Magento is a free, open-source, PHP-based eCommerce platform and cloud solution to grow your online business rapidly. It is built on open-source technology, with a flexible shopping cart system and an admin control panel that helps you start your online store easily. Magento also offers many plugins and themes to enhance a customer’s experience.

In this post, we will show you how to install the Magento eCommerce platform on Rocky Linux 8.

Step 1 – Install Apache and MariaDB Server

First, install the Apache and MariaDB server using the following command:

dnf install httpd httpd-tools mariadb-server -y

Once both packages are installed, start both services and enable them to start at system reboot:

systemctl start httpd mariadb
systemctl enable httpd mariadb

Step 2 – Install PHP and Other Extensions

Next, you will need to install PHP 7.4 and other extensions to your server. The default PHP version is set to PHP 7.2. If you want to install the latest version, PHP 7.4, you will need to reset the default PHP steams.

Run the following command to reset the default PHP:

dnf module reset php

Next, enable the PHP 7.4 version using the following command:

dnf module enable php:7.4

Next, 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 change some values:

nano /etc/php.ini

Change the following values:

memory_limit = 1024M
upload_max_filesize = 256M
zlib.output_compression = on
max_execution_time = 18000
date.timezone = Asia/Kolkata

Save and close the file when you are finished.

Next, you will need to install the PHP sodium extension to your system.

First, install the EPEL repository with the following command:

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

Next, install the required dependencies with the following command:

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

Next, install the PHP sodium extension with the following command:

pecl channel-update pecl.php.net
pecl install libsodium

Next, edit the php.ini file and enable the sodium extensions:

nano /etc/php.ini

Add the following line:

extension=sodium.so

Next, verify the sodium extension using the following command:

php -i | grep sodium

Sample output:

sodium
sodium support => enabled
sodium compiled version => 2.0.23
libsodium headers version => 1.0.18
libsodium library version => 1.0.18

Step 3 – Create a Magento Database

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

First, connect to the MariaDB with the following command:

mysql

Once you are connected, create a database and user:

CREATE DATABASE magento;
CREATE USER 'magento'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to the Magento database:

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

Next, flush the privileges and exit from the MariaDB shell:

FLUSH PRIVILEGES;
EXIT;

Step 4 – Install Composer

Next, you will need to install Composer on your system. You can install it using the following command:

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

Next, verify the Composer installation using the following command:

composer -V

Sample output:

Composer version 2.1.5 2021-07-23 10:35:47

Step 5 – Download Magento

At the time of writing this tutorial, the latest version of Magento is 2.4.2. You can download it with the following command:

wget https://github.com/magento/magento2/archive/refs/tags/2.4.2.zip

Once the Magento is downloaded, unzip the downloaded file with the following command:

unzip 2.4.2.zip

Next, move the extracted directory to Apache web root:

mv magento2-* /var/www/html/magento2

Next, change the directory to magento2 and install all required PHP dependencies with the following command:

cd /var/www/html/magento2
composer install

Next, set proper ownership to the magento2 directory:

chown -R apache:apache /var/www/html/magento2

Next, set required permissions with the following commands:

cd /var/www/html/magento2
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R apache:apache . 
chmod u+x bin/magento

Step 6 – Configure Apache for Magento

Next, create an Apache virtual host configuration file for Magento:

nano /etc/httpd/conf.d/magento.conf

Add the following lines:

<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 close the file, then restart the Apache service to apply the changes:

systemctl restart httpd

Step 7 – Install Magento

Magento web installation has been removed from Magento version 2.2, so you will need to install the Magento from the command line.

First, change the directory to magento2 and disable the Elasticsearch module using the following command:

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

Next, install the Magento using the following command:
sudo -u apache bin/magento setup:install --admin-firstname="hitesh" --admin-lastname="jethva" --admin-email="[email protected]" --admin-user="admin" --admin-password="secure@123" --db-name="magento" --db-host="localhost" --db-user="magento" --db-password="password" --language=en_US --currency=USD --timezone=Asia/Kolkata --cleanup-database --base-url=http://"magento.example.com"

Once the Magento has been installed, you should get the following output:

[Progress: 828 / 831]
Disabling Maintenance Mode:
[Progress: 829 / 831]
Post installation file permissions check...
For security, remove write permissions from these directories: '/var/www/html/magento2/app/etc'
[Progress: 830 / 831]
Write installation date...
[Progress: 831 / 831]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_lfsxqf
Nothing to import.

Step 8 – Install Magento Cron Jobs

Next, you will need to set up Magento cron jobs.

First, navigate to the Magento root directory with the following command:

cd /var/www/html/magento2

Next, install the Magento cron jobs with the following command:

sudo -u apache  bin/magento cron:install

Step 9 – Access Magento Web UI

Now, open your web browser and access the Magento web interface using the URL http://magento.example.com/admin_lfsxqf. You should see the Magento login page:
Magento Login Page
Provide your admin username and password and click on the Sign in button. You should see the Magento dashboard on the following page:
Magento Dashboard Page

Conclusion

You have successfully installed Magento 2.4 on Rocky Linux 8. You can now start building your online store using the Magento platform on your dedicated server from Atlantic.Net.