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:
Apache or Nginx
PHP 7.4 or later with the following extensions:
- php7.4-cli
- php7.4-curl
- php7.4-gd
- php7.4-json
- php7.4-mbstring
- php7.4-pgsql
- php7.4-xml
- php7.4-zip
PostgreSQL 9.6 or later.
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:
- Login to the PostgreSQL shell by entering the given command:
sudo -u postgres psql
- 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];
- 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:
- Download latest Grocy package by running:
sudo wget https://releases.grocy.info/latest
- Now extract the downloaded archive:
sudo tar -xzf grocy_latest.tar.gz -C /var/www
- Change the directory to the extracted Grocy directory:
cd /var/www/grocy
- Now, rename the sample configuration file:
sudo cp config-dist.php config.php
- 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'
],
- 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.