Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal Ubuntu 20.04 system setup with nginx, grocy > 2.6.0, php 7.4 #649

Closed
emk2203 opened this issue Mar 23, 2020 · 35 comments
Closed

Minimal Ubuntu 20.04 system setup with nginx, grocy > 2.6.0, php 7.4 #649

emk2203 opened this issue Mar 23, 2020 · 35 comments
Labels

Comments

@emk2203
Copy link

emk2203 commented Mar 23, 2020

Starting with grocy 2.6.1 and the switchover from the Slim framework v3 to v4, you cannot install in a subdirectory anymore.

Here the updated instructions which work for me on a minimum Ubuntu 20.04 install on a ARM system:

Install nginx, php, sqlite on minimal system

Get root, ideally with sudo -i.

Install nginx and check status, should be up and running. You can make extra sure with systemctl enable nginx that this survives a reboot.

apt install nginx
systemctl status nginx

If you are not starting from a minimal system, make sure that the firewall (ufw or other) don't interfere with the nginx install:

ufw allow 'Nginx Full'

and check with ufw status. This opens the firewall for HTTP and HTTPS on ports 80 and 443.

Now you can install sqlite with apt install sqlite3.

To install only php without the Apache dependency, install php-fpm together with php-gd. Don't forget php-sqlite3.

apt install php-fpm php-sqlite3 php-gd

The standard www root directory is /var/www/html/, the user for nginx is set to 'www-data'.

The files served need to belong to this user.

cd /var/www/html
wget https://releases.grocy.info/latest
unzip latest -d /var/www/html && rm latest
chown -R www-data:www-data /var/www
cp /var/www/html/config-dist.php /var/www/html/data/config.php
vi /var/www/html/data/config.php

Now is the time to do the edits to customize your installation.

Important: BASE_PATH and BASE_URL need to be setup like this:

# When running grocy in a subdirectory, this should be set to the relative path, otherwise empty - this will not work currently with Grocy 2.6.1!
# Example:
#  Webserver root directory = /var/www
#  grocy directory = /var/www/grocy
#  => BASE_PATH = /grocy
Setting('BASE_PATH', '');

# The base url of your installation,
# should be just "/" when running directly under the root of a (sub)domain
# or for example "https://example.com/grocy" when using a subdirectory
Setting('BASE_URL', '/');

Do not try and put grocy in a subdirectory. This seems not to work at the moment with Slim v4 and Grocy 2.6.1.

Test your install with http://localhost or http://<intranet_server_name> from elsewhere. The default nginx landing page should come up to indicate that the web server part is running.

Now to configure the server and php. There are several .ini and .conf files now in your /etc/php folder, you can leave them alone. Same goes for the /etc/nginx/nginx.conf file. What you want to do is to make a file /etc/nginx/conf.d/fastcgi_params to setup your installed system correctly:

include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

Make sure that the last line fits your installed php version. Test with php --version if necessary.

To set the web root, do the following:

cd /etc/nginx/sites-available
cp default grocy
ln -s /etc/nginx/sites-available/grocy /etc/nginx/sites-enabled/grocy
rm /etc/nginx/sites-enabled/default

Now edit the grocy file with the following changes:

 root /var/www/html/public;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri /index.php;
                #try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; #need to edit this!

        #       # With php-cgi (or other tcp sockets):
        #       # fastcgi_pass 127.0.0.1:9000:
        }
}

Again, make sure that the line to be edited fits your installed php version like above.

On reload of nginx with systemctl restart nginx.service, you should be able to access the grocy pages now. Or, if necessary, reboot. I also had issues with my Chrome browser which mandated a cache deletion. Grocy should now work without issues.

If anyone can add to this how to install in a subdirectory of the webserver root, I would be happy to amend the above.

Originally posted by @emk2203 in #201 (comment)

@berrnd
Copy link
Member

berrnd commented Mar 23, 2020

Great thanks, I will replace/update the link on https://grocy.info/links

@robertopreste
Copy link

robertopreste commented Mar 28, 2020

Really good tutorial, I was able to get Grocy running on my RaspberryPi.
There are, however, a couple of points that need to be fixed:

  • when setting the web root, the soft-link line should be
    ln -s /etc/nginx/sites-available/grocy /etc/nginx/sites-enabled/grocy

  • the /etc/nginx/sites-available/grocy configuration file should rather be

    server {
          root /var/www/html/public;
    
          # Add index.php to the list if you are using PHP
          index index.html index.htm index.nginx-debian.html index.php;
    
          server_name _;
    
          location / {
                  # First attempt to serve request as file, then
                  # as directory, then fall back to displaying a 404.
                  try_files $uri /index.php;
                  #try_files $uri $uri/ =404;
          }
    
          # pass PHP scripts to FastCGI server
          #
          location ~ \.php$ {
                  include snippets/fastcgi-php.conf;
    
                  # With php-fpm (or other unix sockets):
                  fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;  # need to edit this!
    
          #       # With php-cgi (or other tcp sockets):
          #       # fastcgi_pass 127.0.0.1:9000:
          }
    }
    

    i.e. make sure that everything is wrapped in a server {} directive (less-experienced users might not know about this); and the php version needs to be edited to fit the installed version.

Thanks again @emk2203!

@emk2203
Copy link
Author

emk2203 commented Mar 28, 2020

@robertopreste Thanks for the suggestions and spotting the errors. I have updated the instructions.

@jayaddison
Copy link
Contributor

@emk2203 @robertopreste These are great instructions, thanks. Do you mind if I pull some of your nginx configuration recommendations into grocy-docker? (or if you feel keen, I'd welcome pull requests and/or testing)

I'm aiming to stabilize and narrow down the nginx configuration there and there are still a few elements which are likely not minimal/ideal.

@darkcloud784
Copy link

If you run php7.4-fpm, you need to install php7.4-gd, which is not including with php-fpm and not added in your tutorial.

@emk2203
Copy link
Author

emk2203 commented May 29, 2020

Yes, I needed to update it, done now.

The requirement for php7.4-gd was introduced just recently, after I wrote this.

@ovz93br43v7
Copy link

ovz93br43v7 commented Dec 1, 2020

@emk2203 @berrnd Thank you for that nice software and installation guide. Is this guide still valid for the latest version 2.7.1?!?

@berrnd
Copy link
Member

berrnd commented Dec 1, 2020

Is this guide still valid for the latest version 2.7.1

Of course, because nothing has changed regarding dependencies and we still use nothing special, it's technically still just a simple PHP application...

@ovz93br43v7
Copy link

Is this guide still valid for the latest version 2.7.1

Of course, because nothing has changed regarding dependencies and we still use nothing special, it's technically still just a simple PHP application...

One additional question: How would I have to install any future update when it comes out?

@berrnd
Copy link
Member

berrnd commented Dec 1, 2020

One additional question: How would I have to install any future update when it comes out?

That's mentioned in README.

@ovz93br43v7
Copy link

ovz93br43v7 commented Dec 6, 2020

I successfully followed your guide, but I found out that I already had port 80 in use, so this could probably useful for somebody who running also Pihole on the machine where grocy will be installed:
https://jdsworld.com/tech-support/pi-hole-dns-change-default-web-port/
I had to modify this before installing nginx.
Probably you can add a hint to your guide to prevent questions regarding the port or how to use a custom port or the https port?

I found today this guide regarding the subfolder issue: #694 (comment) but how have this applied after a successful installation regarding your guide above?!?

@witzker
Copy link

witzker commented Dec 6, 2020

Hi I have really massive problems with this guide
Can you also Pls check the steps I think not all corrections are put in the above description
I installed an Ubuntu 20.04 CL in ProXmoX
following this on YouTube

https://www.youtube.com/watch?v=pOUA5zofM0g&t=225s

then followed the guide above with looking at the correction

Is it possible to do a script or 2 that will set all up correctly?
I attach a Word file with the commands I gave.
Maybe this script and video description can help to spread Grocy to other users like me
Who really don't understand all this server stuff.
What do you think?
Grocy Setup ngnix.docx

@pconwell
Copy link

pconwell commented Dec 7, 2020

If anyone comes across this in the future, the instructions above are confusing and jumbled (why are there like 3 different apt install instances? And why were there a bunch of files mentioned that we don't need to edit?). Here are clean instructions that will work for (proxmox lxc) minimal Debian 10.7 and probably most variants of debian/ubuntu. I started with a completely new, clean install of Debain 10.7.

Note: If your install came with a newer version of php, you will need to change php7.3 to php7.4 (or whatever version) in the instructions below. The easiest way to determine your correct php version is to cd /var/run/php/ and see what php7.X-fpm.sock pointer is located there.

  1. Install clean minimal Debian 10.7 install (will probably work with most debian/ubuntu variants)
  2. apt update
  3. apt full-upgrade -y
  4. apt install -y nginx sqlite3 php-fpm php-sqlite3 php-gd unzip
  5. wget https://releases.grocy.info/latest
  6. unzip latest -d /var/www/html
  7. chown -R www-data:www-data /var/www
  8. cp /var/www/html/config-dist.php /var/www/html/data/config.php
  9. ip addr
  10. In your browser, check if nginx is running at http://ip_addr (from above)

Note: If you are using ubuntu and/or a full fledge install (not a minimal/server install), you may need to configure your firewall. Not covered here.

  1. nano /etc/nginx/conf.d/fastcgi_params and paste the following into the new file:
include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
  1. nano /etc/nginx/sites-available/default and make the file look just like this (you can just delete all the old stuff and copy this):
server {
        listen 80 default_server;

        root /var/www/html/public;

        index index.html index.htm index.nginx-debian.html index.php;

        server_name _;

        location / {
                try_files $uri /index.php;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        }
}
  1. systemctl restart nginx.service
  2. Go back to your http://ip_addr and you should now see the login for grocy. May take a few minutes to load.

Note: Default username/password is admin/admin, OR you can disable authentication by changing Setting('DISABLE_AUTH', false); to true in /var/www/html/data/config.php

@witzker
Copy link

witzker commented Dec 8, 2020

Many THX for making it clear now
I'm new with all this server stuff but try to learn
I finally really want to get this up and running
I hope you can help to do so

Here My steps

Creating a CL in Proxmox
unfortionally there is only this Debian available

image

I took
image

then
start the container
apt update - AND -> Problem with the first command

root@Grocy:~# apt update Err:1 http://ftp.debian.org/debian buster InRelease Temporary failure resolving 'ftp.debian.org' Err:2 http://security.debian.org buster/updates InRelease Temporary failure resolving 'security.debian.org' Err:3 http://ftp.debian.org/debian buster-updates InRelease Temporary failure resolving 'ftp.debian.org' Reading package lists... Done Building dependency tree... Done All packages are up to date. W: Failed to fetch http://ftp.debian.org/debian/dists/buster/InRelease Temporary failure resolving 'ftp.debian.org' W: Failed to fetch http://ftp.debian.org/debian/dists/buster-updates/InRelease Temporary failure resolving 'ftp.debian.org' W: Failed to fetch http://security.debian.org/dists/buster/updates/InRelease Temporary failure resolving 'security.debian.org' W: Some index files failed to download. They have been ignored, or old ones used instead. root@Grocy:~#

HowTo to solve this?
What have I done wrong?

@ovz93br43v7
Copy link

@pconwell I installed successfully according to the first guide. Is there anything completly wrong with the first guide from your point of view? I tried to compare both guides but I'm not an expert. I only see the following differences:

  1. edit of /var/www/html/data/config.php
  2. following commands:
cd /etc/nginx/sites-available
cp default grocy
ln -s /etc/nginx/sites-available/grocy /etc/nginx/sites-enabled/grocy
rm /etc/nginx/sites-enabled/default
  1. edit of grocy

Will installation according to the first guide cause some trouble in the future?!?

@witzker
Copy link

witzker commented Dec 8, 2020

I think to concentrate on pconwell's
GUID and fix that if necessary

I will remove all my stuff on this and SART clear
what do you think?

WHAT could be the problem with Update as shown above?

@pconwell
Copy link

pconwell commented Dec 8, 2020

@ovz93br43v7 First, sorry for coming across snippy - I was very annoyed trying to get this working yesterday and I let my frustrations get to me. To answer your question, there is nothing "wrong" with the first set of instructions, it's just written in a way that can be a little confusing and it's easy to miss a step. The only thing that is actually incorrect (but may still work) is the sites-available config file is missing a couple lines.

@witzker Something is wrong with your network and it cannot reach the debian servers to download updates. The Debian 10.5 CT is the right one (when you successfully update, it will update to 10.7). I'm not sure how to help as I don't know what is wrong with your network. To help narrow down the issue, try this: inside the container, ping 8.8.8.8, then ping www.google.com. If the first one works, but the second one doesn't, something is wrong with your DNS.

@witzker
Copy link

witzker commented Dec 8, 2020

"something is wrong with your DNS"
Yes the gateway was wrong - Sorry
BUT
Now problem with This:

`cp /var/www/html/config-dist.php /var/www/html/data/config.php

cp: cannot stat '/var/www/html/config-dist.php': No such file or directory
root@Grocy:~#`

Pls help

@pconwell
Copy link

pconwell commented Dec 8, 2020

@witzker It's not able to find the file to copy it. Did you download and unzip the latest grocy files? If your DNS was (is) messed up, then the file probably didn't download. What does this do:

wget https://releases.grocy.info/latest
unzip latest -d /var/www/html

@witzker
Copy link

witzker commented Dec 8, 2020

I just repeated Your given commands

AND

image

GREAT many many THX to clear this lets say
informations from the misted glass ball

@witzker
Copy link

witzker commented Dec 8, 2020

I would suggest deleting all other posts and renew the link from the website to your clear instructions
image

What do you Think?

@witzker
Copy link

witzker commented Dec 8, 2020

Now moving Data directory from my Synology installation of Grosy
Shall I log in the first time OR replace the data directory before logging in the first time?

@ovz93br43v7
Copy link

ovz93br43v7 commented Dec 10, 2020

Today my grocy/nginx don't run anymore:

sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2020-12-10 22:25:58 CET; 1min 40s ago
     Docs: man:nginx(8)
  Process: 695 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Dez 10 22:25:57 raspberrypi systemd[1]: Starting A high performance web server and a reverse proxy server...
Dez 10 22:25:57 raspberrypi nginx[695]: nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No su
Dez 10 22:25:58 raspberrypi nginx[695]: 2020/12/10 22:25:57 [emerg] 695#695: open() "/var/log/nginx/access.log" failed (2: No such file 
Dez 10 22:25:58 raspberrypi nginx[695]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dez 10 22:25:58 raspberrypi systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Dez 10 22:25:58 raspberrypi systemd[1]: nginx.service: Failed with result 'exit-code'.
Dez 10 22:25:58 raspberrypi systemd[1]: Failed to start A high performance web server and a reverse proxy server.

Anybody a hint?!?

@pconwell
Copy link

@ovz93br43v7 not much to work with. Did you make any changes to your /etc/nginx/nginx.conf file? Or any other files? Also, make an empty file with write permission for /var/log/nginx/error.og and /var/log/nginx/access.log or if they exist, make sure they are writeable.

What is in your /etc/nginx/nginx.conf' and /etc/nginx/sites-available/FILE_FOR_GROCY`?

@ovz93br43v7
Copy link

ovz93br43v7 commented Dec 11, 2020

@pconwell Thanks for your answer, I made nginx work again.
Problem was: Log file where removed after reboot --> reason /tmp and /var/log are tmpfs to save I/O cycles on my sd card. I thought that this would be a good idea...
But why nginx don't create this folder /var/log/nginx and files error.log and access.log on their own after reboot :-/? Do you know an option to make nginx this automatically? My only idea is to remove the log-files lines in /etc/nginx/nginx.conf or make a cronjob on reboot to create folders, log files and start nginx

EDIT:
I tried that and removed the lines of the log-files lines in /etc/nginx/nginx.conf but this don't make a difference. After a reboot nginx again don't start because of missing log-files/folder

@ovz93br43v7
Copy link

ovz93br43v7 commented Dec 12, 2020

My solution:

  1. sudo crontab -e
  2. add the following lines:
  • @reboot mkdir /var/log/nginx
  • @reboot echo > /var/log/nginx/access.log
  • @reboot echo > /var/log/nginx/error.log

@ovz93br43v7
Copy link

@pconwell Did you install grocy in a sub directory?

@witzker
Copy link

witzker commented Dec 22, 2020

@pconwell
Hi
I finally was able to install Grocy with your perfect guide.
Now the new version is out

May I ask you to tell me HowTo update.

Is it possible to log in with putty and run commands that will update Grocy without losing the data?

@ovz93br43v7
Copy link

@witzker See section "How to update" here: https://github.com/grocy/grocy

@witzker
Copy link

witzker commented Dec 24, 2020

@ovz93br43v7
When running the script what will happen to the data already in Grocy!?
Have you done it that way?
What commands have you used exactly - I'm a Newbie

Pls. Be so kind and list them here (like in the Guide above) that I can follow you

1 Login with putty
2 ?

THX

@ovz93br43v7
Copy link

@witzker
I think you can use the integrated update script also (but I'm also a linux noob...)

If you want to use the update script just run:
./var/www/html/update.sh

According the content of the script which you can find here: https://github.com/grocy/grocy/blob/master/update.sh a backup is created automatically.

@witzker
Copy link

witzker commented Dec 26, 2020

How did YOU Update?

@ovz93br43v7
Copy link

@witzker I updated without backup. I deleted everything and made a complete re-installation according to the above guide.
As I stated check the update.sh script, it contains comments so it is easy to understand.
It makes a backup. To run the script I think you have to enter:
sudo ./var/www/html/update.sh

@witzker
Copy link

witzker commented Jan 24, 2021

Hi
I run the guide again for a new installation of grocy
but now I get
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.4.0".
When calling the IP
Pls help to solve this
THX

@fraunos
Copy link

fraunos commented Mar 9, 2022

Thanks! Docker images didn't work for me (I had 502 errors, only the login page showed up, crashed on "no users table"), and this did on my Odroid C2. Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

9 participants