RHEL BasedRocky Linux

How To Install Magento on Rocky Linux 9

Install Magento on Rocky Linux 9

In this tutorial, we will show you how to install Magento on Rocky Linux 9. For those of you who didn’t know, Magento is a popular open-source e-commerce platform that offers a wide range of features and functionalities. One of the key features of Magento is its flexibility and scalability. It is designed to be highly customizable, allowing developers to create unique and customized online stores. It also supports multiple languages, currencies, and tax rates, making it suitable for businesses operating in different regions.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Magento open-source e-commerce platforms on Rocky Linux. 9.

Prerequisites

  • A server running one of the following operating systems: Rocky Linux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Magento.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Magento on Rocky Linux 9

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update
sudo dnf install dnf-utils epel-release

Step 2. Installing Apache.

By default, Apache is available on the Rocky Linux 9 base repository. Now we install the latest version of Apache using dnf the command:

sudo dnf install httpd httpd-tools

You can start the httpd service and configure it to run on startup by entering the following commands:

sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd

To make your pages available to the public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands:

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https 
sudo firewall-cmd --reload

For additional resources on installing Apache, read the post below:

Step 3. Installing PHP.

PHP is a popular scripting language that powers the dynamic content of millions of websites and apps. Now we run the commands below to install PHP:

sudo dnf epel-release
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf --disablerepo="*" --enablerepo="remi-safe" list available 
sudo dnf module enable php:remi-8.1

Once Remi PHP 8.1 module is enabled, you can now install PHP 8.1 and commonly used PHP extensions as follows:

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

Check and verify the installed version:

php -v

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/Jakarta

Save and close the file, then you need to install the required dependencies PHP sodium extension using the following command:

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

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

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

Head back to the php.ini file.

nano /etc/php.ini

Add the following line:

extension=sodium.so

To verify if PHP sodium was installed run the command:

php -i | grep sodium

For additional resources on installing PHP, read the post below:

Step 4. Installing MariaDB.

By default, MariaDB is available on the Rocky Linux 9 base repository. Simply install the MariaDB package by using the dnf command:

sudo dnf install mariadb-server mariadb

After the installation is completed, start the service of the Database server and then enable the same, so that it could start itself automatically with the system reboot:

sudo systemctl restart mariadb
sudo systemctl status mariadb
sudo systemctl enable mariadb

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

First, log into the MariaDB shell with the following command:

mysql

Now we create a database and user for Magento with the following command:

MariaDB [(none)]> CREATE DATABASE magento;
MariaDB [(none)]> CREATE USER 'magento'@'localhost' IDENTIFIED BY 'your-strong-password';
MariaDB [(none)]> GRANT ALL ON magento.* TO 'magento'@'localhost' IDENTIFIED BY 'your-strong-password' WITH GRANT OPTION;
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

For additional resources on installing MariaDB Database, read the post below:

Step 5. Installing Composer.

By default, Composer is not available on Rocky Linux 9 base repository. Now run the following command below to download the Composer installer file from their official site using the wget command:

wget https://getcomposer.org/installer -O composer-installer.php

Next, run the downloaded composer installation file with the below command:

php composer-installer.php --filename=composer --install-dir=/usr/local/bin

Verify Composer Installation by running the command:

composer --version

For additional resources on installing Composer, read the post below:

Step 6. Download Magento on Rocky Linux 9.

Now run the following command below to download the latest version of Magento from the GitHub page:

wget https://github.com/magento/magento2/archive/refs/tags/2.4.4-p2.zip

Next, unzip the downloaded file with the following command:

unzip 2.4.4-p2.zip
mv magento2-* /var/www/html/magento2

Change the directory to Magento and install all required PHP dependencies:

cd /var/www/html/magento2
composer install

We will need to change some folders permissions:

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

Next, set the 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 7. Configure Apache.

Now we configure the Magento VirtualHost file using the following command below:

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

Add the following file:

<VirtualHost *:80>
   ServerAdmin admin@your-domain.com
   ServerName magento.your-domain.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:

sudo systemctl restart httpd

Step 8. Installing Magento on Rocky Linux 9.

Starting from Magento version 2.2, the option to install Magento via web interface has been removed. Instead, you will need to perform the installation via the command line. To begin, navigate to the magento2 directory and use the following command to disable the Elasticsearch module:

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

Next, install Magento using the following command below:

sudo -u apache bin/magento setup:install --admin-firstname="meilana" --admin-lastname="maria" --admin-email="admin@your-domain.com" --admin-user="admin" --admin-password="your-strong-passwd" --db-name="magento" --db-host="localhost" --db-user="magento" --db-password="your-strong-password" --language=en_US --currency=USD --timezone=Asia/Jakarta --cleanup-database --base-url=http://"magento.your-domain.com"

After that, now set up Magento cron jobs:

cd /var/www/html/magento2
sudo -u apache bin/magento cron:install

Step 9. Accessing Magento Web Interface.

Once successfully installed, open your web browser and access Magento using the URL http://magento.your-domain.com. You will be redirected to the following page:

Install Magento on Rocky Linux 9

Congratulations! You have successfully installed Magento. Thanks for using this tutorial for installing Magento e-commerce platforms on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Magento website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button