Manage your home stocks like a pro with Grocy and Raspberry PI
Managing home stocks is a common need for all people. How many times did you forget to buy something finished at home from your supermarket?
Grocy aims to help people keeping track of their stocks and easily plan shopping of required items. With its built-in barcode scan function, it also allows to manage your products quantity simply scanning their barcode with your smartphone/tablet/pc camera.
It also supports a wider number of items and elements, also letting you to define your customized ones.
Its main features include:
- Google Home Assistant integration
- Purchases tracking
- Shopping list automation and optimization
- Recipes management
- Meal planning
- Tasks management
- … and many other features and addons
In this guide, Grocy will be installed in a cheap Raspberry PI Zero W, but this applies also to newer Raspberry PI boards.
What We Need
As usual, I suggest adding from now to your favourite ecommerce shopping chart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from shopping chart. So, hardware will be only:
- Raspberry PI Zero W (including proper power supply or using a smartphone micro usb charger with at least 3A) or newer Raspberry PI Board
- high speed micro SD card (at least 16 GB, at least class 10)
Check hardware prices with following links:
Step-by-Step Procedure
Install Apache webserver and SQLite:
sudo apt install apache2 # installs Apache web Server sudo apt install sqlite3 # installs sqlite
With recent changes in Grocy, php7.3 seems to be no longer supported. At the date of this article php7.4 is not available from Raspberry PI repositories. So we have 2 options:
- harder way: compiling php7.4 from sources
- easier way: use addictional repositories prepared from developers
This guide will follow second way. Add Sury repository with these commands:
sudo apt install -y apt-transport-https lsb-release ca-certificates wget
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
And install php packages:
sudo apt install php7.4 php7.4-sqlite3 php7.4-gd
Get a copy of Grocy code:
wget https://releases.grocy.info/latest -O grocy.zip
Unzip inside Apache root folder, copy config file from template and give correct permission to folder:
sudo unzip grocy.zip -d /var/www/html/ sudo cp /var/www/html/config-dist.php /var/www/html/data/config.php sudo chown www-data:www-data -R /var/www/html/
Define base path in Apache:
sudo nano /etc/apache2/sites-available/000-default.conf
edit from
DocumentRoot /var/www/html/
to:
DocumentRoot /var/www/html/public/
Enable Override in Apache:
sudo nano /etc/apache2/apache2.conf
Edit under “<Directory /var/www>” row:
AllowOverride None
to
AllowOverride All
Enable Rewrite and restart Apache:
sudo a2enmod rewrite sudo systemctl restart apache2.service
From your favourite browser, use your Raspberry PI url: “http://<<YourRpiIpAddress>>” (my Raspberry PI address is 192.168.1.78, my browser is Brave browser). The login page will appear:

Use default credentials (remember to change password as soon):
- user: admin
- password: admin
You will be logged in to Grocy default home page:

From here, you can use your Grocy installation.
Enabling Barcode Scanner
If you want to use the convenient Barcode Scanner feature, you nee moving your Grocy installatio to htts. To enable SSL and make barcode scan working, please refer following steps.
You will install certificates generated locally, so your browser will surely notify you that this connection is not secure because it cannot verify with a public certification authority.
Enable Apache ssl, create a folder for certificates and generate local certificates. From terminal:
sudo a2enmod ssl sudo mkdir /etc/apache2/ssl sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
Last command will ask some questions for certificates generation. Answers are free…
Setup Apache ssl configuration file with correct root directory:
sudo nano /etc/apache2/sites-available/default-ssl.conf
Identify the row including “DocumentRoot /var/www/html/” and change it to “DocumentRoot /var/www/html/public”. Enable SSL and restart Apache:
sudo a2ensite default-ssl.conf sudo systemctl restart apache2.service
Back to your browser, you will find the SSL page at “https://<<YourRpiIpAddress>>” (my address is still 192.168.1.78). you web browser will notify a not verified certificate with a not secure warning:

You are using your local Raspberry Pi, so you can go on by clicking to “Advanced” and then “Proceed” link. A new login page will appear (identical to previous one), but at left side of your url the “Not Secure” warning will change and clicking it you will see that the notification comes from a not valid certificate:

However, you can login and use your Grocy installation and the Barcode Scanner feature.
If you want to get a correct certificate, you will need to get it from a Certification Authority (like, for example, the free SslForFree or using Let’s encrypt.
Enjoy!
Hello,
thank you for your guide.
I have two questions:
1. Can the section regarding the ssl certificate also applied to a nginx setup?
2. I’m trying to setup my grocy in a sub folder but I have no success. I read through the guides on the webpage but I’m not able to get this running in a sub-folder. So if would be very useful for me but I think also for others when you could show this step by step
Hi.
Nginx has its own security enablement procedure. Once you get nginx working, you can also refer to https://peppe8o.com/install-free-ssl-certificates-with-nginx/. Certificates can be generated with external free authority. They should be ok also from openssl command in this article, but I’ve not still tried it.
Regarding subfolder, you need also to update config.php file as referred in https://github.com/grocy/grocy/issues/694.
Let me know if this is helpful to you of if more help is needed
Hi,
thanks for the link to the nginx article. In the above article you create a ssl certificate without a real domain just in the terminal. In https://peppe8o.com/install-free-ssl-certificates-with-nginx/ according to the guide I would need a real domain or not? Or can I just choose a random domain name which I don’t own and take the certificate and use it for securing my access to my local grocy service?!?
I’m using grocy just in my home network and with VPN, so I just have a internal home network ip for this service.
The subfolder installation I tried several times. Either I can’t reach the page at all and only see a Nginx error or I see a page with Grocy logo and the text this page doesn’t exist and will reload in 5 seconds. I have already tried all configuration files adjusted to my installation paths but it was one of the two results every time.
Hi
Thanks for this tutorial. However when I run grocy it doesn’t work because the version of php installed is not good (requiered PHP 7.4). Do you plan to update the tutorial? I am a novice and despite my little research to install PHP 7.4 I am unable to make grocy work
Thank you very much for your note, David.
Unlucly, after recent Grocy upgrade it seems that php 7.3 is no more supported. On the other side, Raspberry PI apt sources still include only the obsolete php 7.3. For this reason I updated my tutorial adding a workaround. I tested it and appears to be working now. If you already installed php7.3 before, I suggest to purge these packages with “sudo apt purge php7.3*”