How to Install Magento on Rocky Linux

Magento is a free and one of the most widely used PHP-based open-source eCommerce platforms that allows you to quickly and easily set up eCommerce websites and online shops. It is written in PHP, based on the Zend Framework and has a flexible shopping cart system, an admin control panel, and many themes and plugins to help you easily launch your online shop.

In this tutorial, you will learn how to install the Magento eCommerce platform on Rocky Linux 8.

Prerequisites

  • A fresh Rocky Linux 8 server with at least 2GB RAM.
  • A valid domain name is associated with your server IP.
  • A root password is configured on the server.

Step 1: Update OS

Before you start the installation, update your OS by executing the following command into the terminal:

dnf update -y

Step 2: Install Apache Webserver

After OS update, install Apache webserver:

dnf install httpd httpd-tools

Next, start the Nginx service and add service to start at system reboot:

systemctl start httpd

systemctl start httpd

Subsequently,, check the Nginx service status using the following command:

systemctl status httpd

You will see the Apache webserver is up and running.

Install and test Apache web server

Step 3: Install and Configure MariaDB Server

Next, Install the MariaDB server by executing the following command:

dnf install mariadb-server -y

Once the database package is installed, start the service, check the service status and enable it to start at system reboot:

systemctl start mariadb

systemctl status mariadb

systemctl enable mariadb

Next, secure MariaDB installation with the following command:

sudo mysql_secure_installation
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Now, your MariaDB root password has been configured.

Next, you will need to create a database and user for Magento.

First, you need to connect to the MariaDB with the following command:

mysql -u root -p

Next, enter the password for the root user then create a database and user:

create database magento_db;
create user magento_user@'localhost' identified by 'password';

Next, grant all the privileges to the database:

GRANT ALL ON magento_db.* TO 'magento_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Next, flush the privileges and exit MariaDB console:

FLUSH PRIVILEGES;
EXIT;

Create MySQL database

Step 4: Install PHP and Other Extensions

On Rocky Linux, the PHP default version is PHP 7.2. You can install PHP 7.4 by resetting the default PHP steams.

dnf module reset php

Next, enable the PHP 7.4 version by executing:

dnf module enable php:7.4

Install PHP

Now, install PHP 7.4 with other extensions using the following command:

dnf install php php-cli php-mysqlnd php-opcache php-xml php-gd php-soap php-pdo php-bcmath php-intl php-mbstring php-json php-iconv php-zip unzip git -y

Next, edit the php.ini file and make some changes:

vim /etc/php.ini

Change the following value and set date. Timezone value according to your location:

memory_limit = 1024M
upload_max_filesize = 256M
zlib.output_compression = on
max_execution_time = 18000
date.timezone = America/Toronto

Save and close the file after making changes.

Next, you need to install the PHP sodium extension.

For PHP sodium extension, you are required to install the EPEL repository on Rocky Linux.

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Next, execute the following command to install the required dependencies:

dnf install php-cli libsodium php-pear php-devel libsodium-devel make

Now, install the PHP sodium extension by running the following command:

pecl channel-update pecl.php.net

pecl install libsodium

Next, enable sodium extensions in php.ini file.

vim /etc/php.ini

Add the following line in php.ini:

extension=sodium.so

Save and exit the file and verify the sodium extension with the following command:

php -i | grep sodium

Install Sodium

Step 5: Install Composer

You need to install composer, you can install it by running the following command:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Once the installation is completed, verify the Composer installation using the following command:

composer --version
Composer version 2.1.14 2021-11-30 10:51:43

Install Composer

Step 6: Download and Install Magento

Next, run the change directory and  download the latest Magento version by executing the following commands:

cd /var/www/html
wget https://github.com/magento/magento2/archive/refs/tags/2.4.3.zip

Once the download is completed, extract the downloaded zip using the following command:

Step 7: Configure Apache for Magento

Next, you need to create Apache virtual configuration file for Magento:

vim /etc/httpd/conf.d/magento.conf

Add the following lines into magento.conf

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName magento.example.com
DocumentRoot /var/www/html/magento2/
DirectoryIndex index.php
<Directory /var/www/html/magento2/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/magento_error.log
CustomLog /var/log/httpd/magento_access.log combined
</VirtualHost>

Save and exit the configuration file.

Next, restart the Apache service to implement the changes:

systemctl restart httpd

Step 8: Install Magento

From Magento version 2.2, web installation is no longer available, and you need to install it from the command line.

First, go to your magento2 directory and disable the Elasticsearch module by executing the following command in the terminal:

cd /var/www/html/magento2/
sudo -u apache bin/magento module:disable {Magento_Elasticsearch,Magento_Elasticsearch6,Magento_Elasticsearch7}

Start installation

Next, run the below command to install Magento:

sudo -u apache bin/magento setup:install --admin-firstname="admin" --admin-lastname="admin" --admin-email="[email protected]" --admin-user="admin" --admin-password="secure@123" --db-name="magento_db" --db-host="localhost" --db-user="magento_user" --db-password="password" --language=en_US --currency=USD --timezone=America/Toronto --cleanup-database --base-url=http://"143.198.120.231"

You should see the output like below:

Start Magento setup

Magento installation

Note: In the above screenshot you can see /admin_14es7e, It may be different for you. Please note down it, you will need this to login into the Magento admin panel later.

Step 9: Install Magento Cron Jobs

Next, set cronjob for Magento.

First, go to the Magento root directory using the following command:

cd /var/www/html/magento2

Run the below command to install Magento cron jobs:

sudo -u apache bin/magento cron:install

Step 10: Magento Web UI

Next, Open your web browser and enter the URL as per your domain name or IP:

http://143.198.120.231/admin_14es7r 

It will show you a Magento login page like:

Magento login

Here, Enter your admin username and password and click on ‘Sign in‘ button. It will redirect you to the Magento dashboard as shown in the below screenshot:

Magento dashboard

Conclusion

In this tutorial, you have successfully installed Magento 2.4 on Rocky Linux 9. You can now explore Magento to build an outstanding eCommerce website using the Magento platform on your cloud VPN. Please don’t hesitate to ask me if you have any queries.