Installing Bleeding Edge Grocy on Raspberry Pi OS (Debian 11)
Othman Alikhan / July 2022
Table of Content
- Table of Content
- Overview
- Installing Backend Components
- Installing Frontend Components
- Configuring Apache
Overview
We will be installing the latest release of Grocy (as of this article v3.3.1) on a Raspberry Pi 3 (running Rasperry Pi OS [Debian 11]).
The setup involves installing the backend PHP dependencies, the frontend javascript dependencies, and configuring an Apache server.
This article was inspired by https://peppe8o.com/manage-your-home-stocks-like-a-pro-with-grocy-and-raspberry-pi/
Installing Backend Components
- Update the OS list of downloadable packages.
sudo apt update
- Install Apache, SQLite, and PHP8
sudo apt install apache2 sqlite3 php8.0
- Clone the bleeding edge release of grocy.
cd /var/www/ sudo git clone https://github.com/grocy/grocy.git
-
Install PHP composer locally in the project (required to install PHP libraries automatically). PHP composer is a bit funny in how it works, from official docs, do not download/install composer as root user for security reasons!
Therefore switch to the regular user that you created when you installed the Raspberry Pi OS. You can use
cat etc/passwd | grep -i 1000
to find the username if you are really lost. We will later adjust permissions so only Apache service account can accessgrocy/
directory.cd /var/www/grocy/ # Temporary modifying permissions su <REGULAR_USER> sudo chown <REGULAR_USER>:<REGULAR_USER> -R /var/www/grocy/ # Installing composer (Reference: https://getcomposer.org/download/) php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
QA: You should see a ‘composer.phar’ binary in your local directory.
- Use composer to fix any library version mismatches.
php composer.phar update
- Use composer to highlight any missing PHP extensions.
php composer.phar install
- 6.1. You should see a bunch of errors similar to the one below.
Problem 1 - slim/http is locked to version 1.2.0 and an update of this package was not requested. - slim/http 1.2.0 requires ext-simplexml * -> it is missing from your system. Install or enable PHP's simplexml extension.
-
6.2. For each error, install the relevant library manually. So for the error above,
sudo apt install php8.0-simplexml
. - 6.3. Otherwise, you can use the following command which should install pretty much everything needed
(though this might have missing libraries in future grocy releases! So if you see errors, go back to bullet 6.2.)
sudo apt install php8.0-gd php8.0-simplexml php8.0-intl php8.0-mbstring php8.0-pdo_sqlite
QA: Re-run
php composer.phar install
and you should see no errors. - 6.1. You should see a bunch of errors similar to the one below.
Installing Frontend Components
- Install
yarn
to download frontend dependencies (install yarn via npm since the apt package is a different tool altogether).sudo apt install npm # Require npm to install yarn sudo npm install -g yarn
- Download frontend dependencies using
yarn
.cd /var/www/grocy sudo yarn install
Configuring Apache
- Prepare a grocy config file as mentioned in Grocy docs.
cp /var/www/grocy/config-dist.php /var/www/grocy/data/config.php
- Change ownership to Apache service account to restrict access.
sudo chown www-data:www-data -R /var/www/grocy/
- Configure apache to not ignore the .htaccess file in the grocy directory.
sudo vi /etc/apache2/apache2.conf
7.1. Under the ‘<Directory /var/www/>’ section set AllowOverride from ‘None’ to ‘All’
... <Directory /var/www/> ... AllowOverride All # Change this value is changed from 'None' to 'All' ... # https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
- Create an Apache config file for the grocy webapp.
- 4.1. Copy an existing Apache config file.
cd /etc/apache2/sites-available/ sudo cp 000-default.conf grocy.conf
- 4.2. In your new copy, add a
ServerName
entry, and modify theDocumentRoot
entry.sudo vi grocy.conf ... ServerName <YOUR_STATIC_IP> # You will need to add this entry! DocumentRoot /var/www/grocy/public # Ensure no trailing slash! ...
- 4.1. Copy an existing Apache config file.
- Check for syntax errors
sudo apache2ctl configtest ... Syntax OK
- Enable the Apache sites and restart.
sudo a2ensite grocy.conf sudo a2enmod rewrite # Enables the re-write module. sudo a2dissite 000-default.conf # Disables the unused default Apache page sudo systemctl restart apache2
- Finally, navigate to
http://<YOUR_IP>
to use your deployed grocy webapp.