How to Install Grocy on Alpine Linux Latest

Grocy is a web-based application that helps manage your groceries, tasks, and household. It provides features like tracking grocery inventory, meal planning, expiration tracking, and even task management. In this tutorial, we will show you how to install Grocy on Alpine Linux Latest.

Prerequisites

Before you begin with the installation process, make sure you have the following:

Step 1: Update Packages and Dependencies

Start off by updating your system packages and dependencies using the following command:

sudo apk update && sudo apk upgrade

This command will update the packages and dependencies of your machine, ensuring everything is up-to-date.

Step 2: Install Required Packages and Dependencies

Next, install the required packages and dependencies for Grocy using the following command:

sudo apk add --no-cache php7 php7-fpm php7-session php7-mbstring php7-json php7-curl php7-zip php7-openssl php7-gd php7-pdo php7-pdo_mysql nginx mariadb mariadb-client

This command installs the necessary PHP7 extensions, the Nginx web server, and the MariaDB database server.

Step 3: Install Composer

Composer is a PHP package manager that is required to install Grocy. To install Composer, run the following command:

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

This command downloads and installs Composer in /usr/local/bin.

Step 4: Download and Configure Grocy

To download and configure Grocy, we will create a new system user and set up the web server.

Create a new system user using the following command:

sudo adduser -D -H grocy

This command creates a new user named grocy.

Next, configure Nginx by creating a new server block in /etc/nginx/conf.d/default.conf. Open the file and replace its contents with the following configuration:

server {
    listen 80;
    server_name your_domain.com;
    root /var/www/grocy/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm7.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

In this configuration, replace your_domain.com with your domain name or IP address.

After you have saved this configuration file, create the /var/www/grocy directory and set the appropriate permissions using the following command:

sudo mkdir -p /var/www/grocy
sudo chown -R grocy:grocy /var/www/grocy
sudo chmod -R 755 /var/www/grocy

Now, navigate to the /var/www/grocy directory and download Grocy using the following command:

cd /var/www/grocy
sudo -u grocy composer create-project grocy/grocy --no-dev --ignore-platform-reqs

This command downloads Grocy to /var/www/grocy.

Step 5: Configure MariaDB

Finally, configure MariaDB by running the following command:

sudo mysql_secure_installation

Then, enter a root password for MariaDB and answer the following prompts:

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM, 2 = STRONG: 2
Please set the password for root here.

New password: 
Re-enter new password: 

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Dropping test database...
Success.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

Step 6: Configure Grocy

To configure Grocy, navigate to /var/www/grocy/data and copy config-dist.php to config.php using the following command:

cd /var/www/grocy/data
cp config-dist.php config.php

Then, open the config.php file and modify the following lines:

'db_name' => 'grocy',
'db_username' => 'root',
'db_password' => 'your_mariadb_root_password',

Replace your_mariadb_root_password with the root password you set in Step 5.

Step 7: Start and Enable Services

Finally, start and enable the Nginx, PHP-FPM, and MariaDB services using the following command:

sudo rc-service nginx start
sudo rc-service php-fpm7 start
sudo rc-service mariadb start
sudo rc-update add nginx default
sudo rc-update add php-fpm7 default
sudo rc-update add mariadb default

And you’re done! You have now successfully installed and configured Grocy on Alpine Linux Latest.

Conclusion

Grocy is an amazing application that helps you manage your groceries, tasks, and household. In this tutorial, we have shown you how to install Grocy on Alpine Linux Latest. You can now use Grocy to effectively manage your household and keep track of your groceries.

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!