How to Install Grocy on Ubuntu Server Latest

Grocy is an open-source and self-hosted web-based application that offers a great solution for managing your households' groceries, inventories, and other related data. It is the best alternative for individuals who want to track their groceries, bills, or any other household items.

In this tutorial, we will be guiding you through the installation of Grocy on an Ubuntu Server. Before we begin the installation, it's recommended to have a server with a clean installation of Ubuntu 20.04 with root privileges or an account with sudo access.

Prerequisites

Before we get started with the installation, there are some prerequisites that need to be installed on your server:

Step 1: Install Apache or Nginx

To install Nginx, run the following command:

sudo apt-get update

sudo apt-get install nginx

Or to install Apache2:

sudo apt-get update

sudo apt-get install apache2

Step 2: Install PHP

Next, install PHP with the required extensions:

sudo apt-get install php7.4-cli php7.4-curl php7.4-gd php7.4-json php7.4-mbstring php7.4-pgsql php7.4-xml php7.4-zip

Step 3: Install PostgreSQL

Now we will install PostgreSQL on our Ubuntu Server. To install PostgreSQL run:

sudo apt-get update

sudo apt install postgresql postgresql-contrib

Step 4: Create a PostgreSQL Database

Once the PostgreSQL is installed, you must create a new database for Grocy. Use the following steps:

  1. Login to the PostgreSQL shell by entering the given command:

sudo -u postgres psql

  1. On the PostgreSQL shell, execute the following commands to create a new user and database:

CREATE USER [grocy_user] WITH PASSWORD '[grocy_password]';

CREATE DATABASE [grocy_database] OWNER [grocy_user];

  1. Apply changes by running the following command and exit the PostgreSQL shell:

\q

Step 5: Install Grocy

At this point, all necessary prerequisites have been installed. Now let's move on to installing Grocy. Follow the below steps:

  1. Download latest Grocy package by running:

sudo wget https://releases.grocy.info/latest

  1. Now extract the downloaded archive:

sudo tar -xzf grocy_latest.tar.gz -C /var/www

  1. Change the directory to the extracted Grocy directory:

cd /var/www/grocy

  1. Now, rename the sample configuration file:

sudo cp config-dist.php config.php

  1. Edit your Grocy installation configuration by running:

nano /var/www/grocy/config.php

Enter the database details that you have created earlier in step 4.

'database' => [
    'database' => '[grocy_database_name]',
    'username' => '[grocy_user]',
    'password' => '[grocy_password]',
    'hostname' => 'localhost',
    'adapter' => 'pgsql'
],
  1. Set the correct permissions on the Grocy files:

sudo chown -R www-data:www-data /var/www/grocy

Step 6: Set up a Virtual Host (optional)

Now that we have installed Grocy, it's time to set up a virtual host.

Setup Apache Virtual Host configuration

If you're using Apache, run the following as root:

sudo nano /etc/apache2/sites-available/grocy.local.conf

Add the following contents in the file and save:

<VirtualHost *:80>
        ServerName grocy.local
        DocumentRoot /var/www/grocy/public
        <Directory /var/www/grocy/public>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
</VirtualHost>

Activate the virtual host:

sudo a2ensite grocy.local

Restart the apache server:

sudo systemctl reload apache2

Setup NGINX Virtual Host configuration

If you're using NGINX, run the following command as root:

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

Copy and paste the following configurations in the file and save:

server {
    listen 80;
    server_name grocy.local;
    root /var/www/grocy/public;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Activate the virtual host:

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

Step 7: Access Grocy

Once you've completed the above configurations, you can access the Grocy application by visiting your server's IP address or the domain name you specified in the virtual host configuration like this.

http://grocy.local

Conclusion:

In this tutorial, we have successfully installed Grocy on Ubuntu Server latest. Now you can manage your groceries and household items with Grocy to keep them organized and easy to track.

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!