Some links in this post may be affiliate links. We may get paid if you buy something or take an action after clicking one of these, but without addictional costs for you compared to direct buying.

Manage your home stocks like a pro with Grocy and Raspberry PI

Raspberry PI Grocy featured

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

Raspberry PI Zero W unpopulated

As usual, I suggest adding from now to your favourite e-commerce shopping cart 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 the shopping cart. So, hardware will be only:

Check hardware prices with following links:

Amazon raspberry pi boards box
Amazon raspberry pi Zero W box
Amazon Micro SD box
Amazon Raspberry PI Power Supply box

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
echo "deb $(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 -O

Unzip inside Apache root folder, copy config file from template and give correct permission to folder:

sudo unzip -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/


DocumentRoot /var/www/html/public/

Enable Override in Apache:

sudo nano /etc/apache2/apache2.conf

Edit under “<Directory /var/www>” row:

AllowOverride None


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, my browser is Brave browser). The login page will appear:

Grocy Login page

Use default credentials (remember to change password as soon):

  • user: admin
  • password: admin

You will be logged in to Grocy default home page:

Grocy Stock Overview

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 you web browser will notify a not verified certificate with a not secure warning:

SSL not secure page 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:

Grocy Login page on https without 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.


How useful was this post?

Click on a star to rate it anonymously!

Average rating 4.8 / 5. Vote count: 8

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?


  1. 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

    1. Hi.
      Nginx has its own security enablement procedure. Once you get nginx working, you can also refer to 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
      Let me know if this is helpful to you of if more help is needed

  2. 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 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.

  3. 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

    1. 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*”

  4. Hi,
    Thank you for the tutorial 🙂
    I’ve followed it “by the letter” but when I try to connect to grocy the first time I get a 403 error.
    I did the chown www-data thing I can’t find a way to connect to grocy 🙁

    any idea ?


  5. Hi peppe80

    thanks for your quick answer 🙂

    first of all, all my websites on the servers are installed directly on /var/www/… (not /var/www/html/…), maybe so grocy is installed at /var/www/
    might it be the source of the error ?

    so concerning your request, ls -la output on the root of grocy folder is following :

    total 244
    drwxrwxr-x 13 www-data www-data 4096 avril 18 16:07 .
    drwxr-xr-x 6 www-data www-data 4096 avril 18 11:06 ..
    -rwxrwxr-x 1 www-data www-data 2649 janv. 5 10:51 app.php
    drwxrwxr-x 2 www-data www-data 4096 janv. 5 10:52 changelog
    -rwxrwxr-x 1 www-data www-data 10077 janv. 5 09:52 config-dist.php
    drwxrwxr-x 3 www-data www-data 4096 janv. 5 09:52 controllers
    drwxrwxr-x 4 www-data www-data 4096 avril 18 11:03 data
    -rwxrwxr-x 1 www-data www-data 128962 janv. 5 09:52 grocy.openapi.json
    drwxrwxr-x 2 www-data www-data 4096 janv. 5 09:52 helpers
    -rw-r–r– 1 www-data www-data 155 avril 18 16:07 .htaccess
    -rwxrwxr-x 1 www-data www-data 1090 mars 6 2019 LICENSE
    drwxrwxr-x 28 www-data www-data 4096 janv. 5 10:44 localization
    drwxrwxr-x 2 www-data www-data 4096 janv. 5 09:52 middleware
    drwxrwxr-x 2 www-data www-data 4096 janv. 5 09:52 migrations
    drwxrwxr-x 9 www-data www-data 4096 janv. 5 09:56 public
    -rwxrwxr-x 1 www-data www-data 10646 janv. 5 09:52
    -rwxrwxr-x 1 www-data www-data 16446 janv. 5 09:52 routes.php
    drwxrwxr-x 2 www-data www-data 4096 janv. 5 09:52 services
    -rwxrwxr-x 1 www-data www-data 968 avril 7 2020
    drwxrwxr-x 23 www-data www-data 4096 janv. 5 09:55 vendor
    -rwxrwxr-x 1 www-data www-data 58 janv. 5 10:49 version.json
    drwxrwxr-x 5 www-data www-data 4096 janv. 5 09:52 views

  6. Re ^^

    I checked further, changing apache root folder from /var/www/html to /var/www

    I then clicked down to the grocy/public folder and this page appeared :

    Error source:

    Error message:
    SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: migrations.migration

    Stack trace:
    #0 /var/www/ PDO->exec()
    #1 /var/www/ Grocy\Services\DatabaseService->ExecuteDbStatement()
    #2 /var/www/ Grocy\Services\DatabaseMigrationService->ExecutePhpMigrationWhenNeeded()
    #3 /var/www/ Grocy\Services\DatabaseMigrationService->MigrateDatabase()
    #4 /var/www/ Grocy\Controllers\SystemController->Root()
    #5 /var/www/ Slim\Handlers\Strategies\RequestResponse->__invoke()
    #6 /var/www/ Slim\Routing\Route->handle()
    #7 /var/www/ Slim\MiddlewareDispatcher->handle()
    #8 /var/www/ Slim\MiddlewareDispatcher->handle()
    #9 /var/www/ Slim\Routing\Route->run()
    #10 /var/www/ Slim\Routing\RouteRunner->handle()
    #11 /var/www/ Grocy\Middleware\LocaleMiddleware->__invoke()
    #12 /var/www/ class@anonymous->handle()
    #13 /var/www/ Grocy\Middleware\AuthMiddleware->__invoke()
    #14 /var/www/ class@anonymous->handle()
    #15 /var/www/ Slim\Middleware\RoutingMiddleware->process()
    #16 /var/www/ class@anonymous->handle()
    #17 /var/www/ Slim\Middleware\ErrorMiddleware->process()
    #18 /var/www/ class@anonymous->handle()
    #19 /var/www/ Grocy\Middleware\CorsMiddleware->__invoke()
    #20 /var/www/ class@anonymous->handle()
    #21 /var/www/ Slim\MiddlewareDispatcher->handle()
    #22 /var/www/ Slim\App->handle()
    #23 /var/www/ Slim\App->run()
    #24 /var/www/ require_once(‘/var/www/grocy….’)
    #25 {main}

    any idea ? 🙂

    1. You should use /var/www/public as document root in your apache site config. Unless you need to be so, I would recommend to start a new installation with same paths as in my tutorial…

      1. hello peppe8o
        thanks, yes i did exactly as in your tutorial and it works fine now 🙂

        … except the ssl : i get a error 500 message

        in fact i did as you requested except the port number I’ve setup to 44301 (as the 443 is already used for another website).

        I updated default-ssl.conf file accordingly …

        would you have an idea ?


  7. Hi,
    After installing php packages and checking version of php installed I get Segmentation fault message:
    sudo apt install php7.4 php7.4-sqlite3 php7.4-gd
    Reading package lists… Done
    Building depedency tree
    Reading state information… Done
    php7.4 is already the newest version (7.4.21-1+0~20210702.48+debian10~1.gbp9b7c1f).
    php7.4-gd is already the newest version (7.4.21-1+0~20210702.48+debian10~1.gbp9b7c1f).
    php7.4-sqlite3 is already the newest version (7.4.21-1+0~20210702.48+debian10~1.gbp9b7c1f).
    0 upgraded, 0 newly installed, 0 to remove and 92 not upgraded.
    php -v
    Segmentation fault
    How can I troubleshoot this?

    1. Hi Dariusz. A segmentation fault means a memory access problem and is complex to debug. Trying to go simple, I can see that you had already installed php7.4 (0 upgraded, 0 newly installed, 0 to remove and 92 not upgraded), so maybe something conflicting. Please note that you have 92 packages not upgraded, so a “sudo apt upgrade” can be needed. I’ve re-tryed to install these packages and it has been accomplished successfully on my Raspberry PI.
      You can move in 2 different directions.
      If you don’t have any other programs/data already installed in your Raspberry PI, I suggest to start with a new setup (from OS installation).
      If you need to preserve your current OS installation, I suggest to purge/autoclean packages:
      sudo apt purge php7.4 php7.4-sqlite3 php7.4-gd
      sudo apt autoclean
      and then install again.
      Please let me know if one of these ways worked.

  8. Starting from scratch I get these messages at the end after running command to install php packages: sudo apt install php7.4 php7.4-sqlite3 php7.4-gd

    Creating config file /etc/php/7.4/apache2/php.ini with new version
    Module mpm_event disabled.
    Enabling module mpm_prefork.
    apache2_switch_mpm Switch to prefork
    apache2_invoke: Enable module php7.4
    apache2_reload: Your configuration is broken. Not restarting Apache 2
    apache2_reload: Illegal instruction
    Setting up php7.4 (7.4.21-1+0~20210702.48+debian10~1.gbp9b7c1f) …
    Processing triggers for man-db (2.8.5-2) …
    Processing triggers for php7.4-cli (7.4.21-1+0~20210702.48+debian10~1.gbp9b7c1f) …
    Processing triggers for libapache2-mod-php7.4 (7.4.21-1+0~20210702.48+debian10~1.gbp9b7c1f) …

    And after running php -v I get:
    Segmentation fault

    I will try to complete configuration regardless of these messages and see what I will get. I’ll post it there

      1. Sorry for late answer. Please can you let me know what is your RPI model and how are you flashing your OS? (Rpi imagery or Etcher or other?)

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy