How to Install Grocy on Debian Latest

Grocy is an open-source self-hosted web-based application to manage your groceries, tasks and household inventory. This tutorial will guide you through the process of installing Grocy on Debian Latest.

Prerequisites

Step 1 - Update Debian System

Before installing Grocy, it is essential to have the latest updates installed. To update your system, connect to your server via SSH and enter the following command:

sudo apt update
sudo apt -y upgrade

The above command will fetch the latest package information and install any available updates.

Step 2 - Install Required Dependencies

Grocy is written in PHP, and it needs some packages to run without any errors. We will install all necessary packages for Grocy as shown below:

sudo apt -y install nginx php7.4 php7.4-fpm php7.4-gd php7.4-mysql php-mbstring php7.4-xml

The above command installs Nginx as the web server, PHP7.4 as the backend scripting engine with some necessary modules.

Step 3 - Download Grocy

Next, we will download Grocy from the official website. Connect to your server via SSH and enter the following command:

wget https://github.com/grocy/grocy/releases/download/v3.2.2/grocy_3.2.2.zip

This command will download the latest release of Grocy.

Step 4 - Extract Grocy

Once the package download is complete, we need to extract it to the /var/www/ directory. To do that, enter the following commands:

unzip grocy_3.2.2.zip -d /var/www/
cd /var/www/grocy

The above command will extract the downloaded package to the /var/www/grocy directory.

Step 5 - Configure Nginx

Now we need to configure Nginx to serve Grocy. We will create a new server block for Grocy. In your SSH terminal, type the following command to create a new file:

sudo nano /etc/nginx/sites-available/grocy.conf

Paste the following configuration in the file:

server {
    listen 80;
    listen [::]:80;

    server_name grocy.local; # Replace with your domain name

    root /var/www/grocy/public/;
    index index.php index.html index.htm;

    # Redirect requests to HTTPS
    if ($scheme != "https") {
        rewrite ^ https://$server_name$request_uri permanent;
    }

    #Add PHP processing
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}

Save and close the file by pressing Ctrl+X followed by Y and then Enter.

Next, create a symlink for the above configuration to enable it. Enter the following command:

sudo ln -s /etc/nginx/sites-available/grocy.conf /etc/nginx/sites-enabled/

Reload the Nginx service for the above configuration to take effect:

sudo systemctl reload nginx

Step 6 - Create a Database and User

Now we need to create a new MySQL database, user and grant all necessary privileges to the user. Connect to your server via SSH and enter the following commands:

sudo mysql -u root -p
CREATE DATABASE grocy CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'grocyuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON `grocy`.* TO 'grocyuser'@'localhost';
FLUSH PRIVILEGES;
quit

The above commands will create a new database and user, which we will use in Step 7.

Step 7 - Configure Grocy

Next, we need to configure Grocy to use the MySQL database we created in Step 6. Connect to your server via SSH, and edit the configuration file as shown below:

sudo nano /var/www/grocy/data/config.php

Update the following lines with the MySQL user and database details:

$dbCredentials = new DatabaseCredentials('mysql:host=localhost;dbname=grocy', 'grocyuser', 'yourpassword');

Press Ctrl+X, Y, and Enter to save and close the file.

Step 8 - Start Grocy

Now that everything is set up, start Nginx and PHP7.4-FPM services:

sudo systemctl start nginx
sudo systemctl start php7.4-fpm

Open your web browser and navigate to http://your-server-ip. If you have followed the above tutorial correctly, you should see the Grocy login page.

Conclusion

In this tutorial, we went through the process of installing Grocy, configuring Nginx, and setting up the MySQL database to make it all work. You can now use Grocy on your Debian server to manage your groceries, tasks and household inventory.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!