IMPORTANT NOTE: I just submitted a GitHub bug notification as the default procedure to install Grocy results into a “SQLSTATE[HY000]: General error: 1 no such table: users” error. Stay tuned with this page for news when the bug will be solved.
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 keep track of their stocks and easily plan shopping for required items. With its built-in barcode scan function, it also allows managing the number of your products by simply scanning their barcode with your smartphone/tablet/pc camera.
It also supports a wider number of items and elements, also letting you 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 3 Model A+, but this applies also to newer Raspberry PI computer boards.
What We Need
As usual, I suggest adding from now to your favourite e-commerce shopping cart all the needed hardware, so that at the end you will be able to evaluate overall costs and decide if continue with the project or remove them from the shopping cart. So, hardware will be only:
- Raspberry PI 3 Model A+ (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 the following links:
Prepare Operating System and Required Packages
Make your OS up to date. From terminal:
sudo apt update -y && sudo apt upgrade -y
Install Apache webserver and SQLite:
sudo apt install apache2 -y sudo apt install sqlite3 -y
Finally, install the required PHP packages:
sudo apt install php7.4 php7.4-sqlite3 php7.4-gd php7.4-intl php7.4-mbstring -y
Install Grocy in your Raspberry PI
Get a copy of Grocy code:
wget https://releases.grocy.info/latest -O grocy.zip
Unzip to the Apache root folder, copy the config file from the template and give correct permission to the 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 the base path in Apache:
sudo nano /etc/apache2/sites-available/000-default.conf
Save and close this file.
Enable Override in Apache:
sudo nano /etc/apache2/apache2.conf
Edit within the “<Directory /var/www>” section:
Save and close this file.
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). It is important to use the root URL (without adding, for example, the trailing “/login”), as it initializes the database and avoids the “SQLSTATE[HY000]: General error: 1 no such table: users” error.
The login page will appear:
Use default credentials (remember to change the password soon when you will start using Grocy with your info):
- 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 need to move your Grocy installation to “https”. To enable SSL and make the barcode scan work, 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
The 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”. Save and close the file.
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). Your 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 on the “Advanced” button and then “Accept the risk and continue” link.
If you want to get a certificate without warnings, you will need to get it from a Certification Authority (like, for example, using Let’s encrypt with Raspberry PI).
A new login page will appear (identical to the previous one), but on the left side of your URL the “Not Secure” warning will change and after clicking it you will reach the certificate details:
However, you can log in and use your Grocy installation and the Barcode Scanner feature.
Please find the Grocy tutorials at https://github.com/grocy/docs/blob/master/tutorial.md.
If you want to discover many other projects for your Raspberry PI, you can take a look at peppe8o Raspberry PI tutorials.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?