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

NGINX Setup #201

Closed
schildgenb opened this issue Mar 31, 2019 · 5 comments
Labels

Comments

@schildgenb
Copy link

@schildgenb schildgenb commented Mar 31, 2019

Do you have a step by step guide on setting this up with NGINX? I have been trying to get this setup but I am struggling with it. I would love to be able to use this program. I am getting an internal server error so I know I am missing something somewhere.

@berrnd berrnd added the question label Mar 31, 2019
@berrnd

This comment has been minimized.

Copy link
Member

@berrnd berrnd commented Mar 31, 2019

It's really nothing special - just ensure that your root directory points to /public, that the data directory is writable and that you include try_files $uri /index.php; in your location block or otherwise disable URL rewriting in the config file - everything is also mentioned in README. Or maybe try grocy-docker.

Feel free to reopen this when you have a specific error message (check the webserver/PHP logs).

@berrnd berrnd closed this Mar 31, 2019
@emk2203

This comment has been minimized.

Copy link

@emk2203 emk2203 commented Apr 26, 2019

I had the same issues as OP, including the server error.

For someone who has never set up a web server or just a practice one years ago, the first step is quite steep, since there are so many differing generic instructions out, partly even contradicting each other.

I have listed some boilerplate instructions which worked for me on a minimum Ubuntu 18.04 install on a ARM system:

Install nginx, php, sqlite on minimal system

Get root, ideally with sudo -i for this install marathon.

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.

Now you can install sqlite with apt install sqlite3.

When you want install just the default php, apache gets installed as dependency. To avoid this, install php-fpm. Don't forget php-sqlite3.

apt install php-fpm php-sqlite3

The Ubuntu and Debian installation is a bastard child to accomodate both nginx and apache and forcing some defaults on nginx which come from apache. One of the signs for this is that the standard www root directory is /var/www/html/, and the user for nginx is set to 'www-data'.

The files served should belong to this user. My first-level suffix for the home intranet is .lan, change this according to your environment.

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

Now is the time to do the edits to customize your installation. I got a sqlite error and no webpage with URL rewriting enabled, but this may have been just during my setup. Afterwards, enabled URL rewriting works well.

When you access this now with http://localhost or http://<intranet_server_name> from elsewhere, you will still see the default nginx landing page - a good sign since it shows that the web server functionality is there.

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.2-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.lan
ln -s grocy.lan ../sites-enabled/grocy.lan
rm ../sites-enabled/default

Now edit the grocy.lan file with the following changes:

 root /var/www/html/grocy.lan/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.2-fpm.sock;

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

On reload of nginx with systemctl restart nginx.service, you should be able to access the grocy pages now. Or, if necessary, reboot. Grocy should now work without issues from the install process.

Maybe these or some other bare-bones setup instructions should be linked in the docs. Looking closer, there seem to be a lot of people struggling with this in these issues.

@berrnd

This comment has been minimized.

Copy link
Member

@berrnd berrnd commented Apr 26, 2019

Why do you need to disable URL rewriting?
try_files $uri /index.php; is exactly for this...

Does not really matter, just produces ugly URLs...

Also just for reference: I posted the complete config of the demo-en instance (which includes another nginx as a reverse proxy in front) yesterday here: grocy/grocy-docker#15 (comment)

@emk2203

This comment has been minimized.

Copy link

@emk2203 emk2203 commented Apr 26, 2019

It simply didn't work during my setup with URL rewriting enabled. Only after changing this I got the web page to display, before, I had only an error page from sqlite. Now I enabled it again, and it still works.

I fixed this in my process above.

berrnd added a commit to grocy/grocy-website that referenced this issue Sep 16, 2019
@berrnd

This comment has been minimized.

Copy link
Member

@berrnd berrnd commented Sep 16, 2019

Thanks again @emk2203 for sharing your install guide, because this could maybe help others too, I added this now as a link on https://grocy.info/links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.