I had been trying to install Grocy in my Debian VPS1 for a week with no success. After several failed attempts, today I have finally made it.

In the beginning I followed the guide in the documentation and the guide pined in Reddit (link), but it did not work: some HTTP 500 Error or something like that. Then I made my own custom Nginx server configuration, it did not work neither. Then moved the files to different directories, changed their ownership, installed php8.1, etc., but nothing seemed to work.

The best result I achieved was being able to login, just to face a dashboard seeming not to recognize the CSS styling. A similar situation had been reported in Reddit a few days ago (link).

But then, out of nowhere…

Today I got the idea to be certain that the problem was in my VPS. So I installed php8.1 in my PC, downloaded Grocy, and run the app with php -S 127.0.0.1:8000 from grocy/public. It worked like a charm.

So I tried by first removing php in my VPS and then installing php8.1 from scratch, and it worked! The following are the exact steps I did:

Purge php7.4 and install php8.1

Remove the php version currently installed, because mine was 7.4

1
apt remove --purge php*

Update and upgrade the system

1
2
apt update
apt upgrade

Installed some other packages2 to add the php8.1 repository to the list

1
apt install ca-certificates apt-transport-https software-properties-common curl lsb-release wget unzip -y

Then use this script to set up the php8.1 repository

1
curl -sSL https://packages.sury.org/php/README.txt | bash -x

Update and upgrade the system

1
2
apt update
apt upgrade

Install php8.1 and other dependencies for Grocy

1
apt install php8.1 php8.1-fpm php8.1-cli php8.1-gd php8.1-intl sqlite3 php8.1-sqlite3 php8.1-mbstring -y

Start the php8.1 process

1
systemctl start php8.1-fpm

Download Grocy and set the Nginx server

Make the folder where Grocy is gonna live, and move to it

1
2
mkdir /var/www/grocy
cd /var/www/grocy

Download the last version of Grocy, and unpack it

1
2
3
wget https://releases.grocy.info/latest
unzip latest
rm latest

Copy the config.php file to the data folder

1
cp config-dist.php data/config.php

Note: Normally you would edit the config.php file as described in the documentation and in its internal comments. In my case the Grocy instance is going to be on the subdomain grocy.website.org of my VPS. Therefore, I do not need to edit anything in config.php.

Change the ownership of the files to the user and group www-data (which should exist by default in your system).

1
chown -R www-data:www-data /var/www/grocy

Edit/create the file /etc/nginx/conf.d/fastcgi_params and fill it with the following information

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

Finally set the Nginx server. In the file /etc/nginx/sites-available/grocy write the following

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
server {
	listen 80 ;
	listen [::]:80 ;
		
	root /var/www/grocy/public;
	
	index index.html index.php;
	server_name grocy.website.org www.grocy.website.org;

	location / {
		try_files $uri /index.php$is_args$query_string;
	}
     
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
	}
}

Of course you must change the server_name directives to your server.

Then create the link to the sites enabled folder

1
ln -s /etc/nginx/sites-available/grocy /etc/nginx/sites-enabled

and restart Nginx

1
systemctl reload nginx.service

If you go to the server_name address it should be there.

Conclusions

Following those exact steps it worked to me, and I did it twice from scratch to check it wasn’t just luck.

Finally, if you are using Certbot to encrypt the traffic to your Nginx server, do

1
certbot --nginx

Do not hesitate to contact me in case you find something wrong here, or have any question. Have in mind that I am not an expert on the subject, so anything too technical may be difficult to me.

Update to v4.0.2 and associated problems

I tried to update to the new release at the moment (4.0.2) with the script provided update.sh, and something got broken. I had to do several things, revoking all the SSL Certificates and configurations of the Nginx previously generated (and re-do them), restarting the php-fpm service with systemctl restart php8.1-fpm, removing all the content from data and letting the default. I do not really know what specific step worked.

However, whenever I was using it and make one or two clicks in the menus, it stopped the php8.1-fpm service and the whole server went down. This should be related to an over-consumption of resources or something like that. I tied to fix it by making the following changes to the configuration file /etc/php/8.1/fpm/php.ini, but it did not worked neither

  • max_input_time = -1 (it was 60)
  • max_execution_time = 300 (it was 30)
  • memory_limit = 512 (it was 128)
  • post_max_size = 128M (it was 8M)
  • upload_max_filesize = 1024M (it was 2M)

The last attempt was to make a fresh installation, and not to use my old database, because some issues were reported because of problems with new features of cascade units conversion. So far so good, although at the moment of writing this update I have only added my list of products to the database, not recipes, nor daily plans neither shopping lists. In case it breaks, then it means it is definitively related to the resources required by Grocy.

The problem with all this is that I had to manually rebuilding the database. It is something I have been doing gradually, and make sure everything is consistent. Luckily I had not that many data in it yet. However after I added the first recipe it started shutting down the system again. I looked at the result of ~$ top at the moment the server went down, and indeed the memory resource went really up. No matter what the developers may say, there is something in this new releases that consumes much more RAM than in the 3.x.x versions, where I had no issues with this.

The final solution and identification of the problem

After a few days of rest, I was again searching what to do with Grocy, and realized I had no swap on my server, just the RAM (type free -h to check your case). Then, I configured a swap partition of 3GB following step-by-step this excellent guide of Digital Ocean. Also, I modified/enabled the following options in the fpm pool configuration file /etc/php/8.1/fpm/pool.d/www.conf:

1
2
3
4
5
6
pm = dynamic
pm.max_children = 5
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 200

This solved my problem! Now I can see (with free -h) that my RAM is a little bit free, and the swap partition is being used, around 800MB of it. Now I can use Grocy, but it is a little bit slow to response, even though my database is very small (around 30 ingredients and 2 recipes). Anyway, this is a great piece of software completely free as in freedom and as in money, maintained mostly by a single developer.

Footnotes


  1. Virtual Private Server. I am currently using 1984↩︎

  2. In this post it is suggested to install them to add the php8.1 repo. ↩︎

⋇ ⋇ ⋇ ⋇ ⋇

Thanks for reading the post! Do not hesitate to write me an email, and share your point of view 😉: contact@poview.org