How to Install Magento 2 on CentOS 8. This article will explain what Magento is and it will follow step by step guide how to install it.
What is Magento?
Magento is a popular open source platform and is widely used in the E-commerce business because of its reliability. First released in 2008 and developed with PHP. eBay owns the Magento and two versions of Magento are available in the market: Magento open source and Magento commerce. Magento open-source is a free edition, whereas Magento commerce is a paid edition. Unlike other database platforms, Magento server uses a database model that is an “EAV”, the reason behind using this model is because of flexibility which is very important to access any E-commerce platform. The benefit of using the Magento platform is, it offers powerful marketing, better SEO (search engine optimization) and a catalog management tool for code reusing.
Magento 2
Magento 2 is an upgraded version of Magento that is faster (CMS Speed 50% faster), SEO friendly and more user friendly than Magento 1. Magento 2 supports the latest PHP and uses Secure Payment Gateways (Paypal, Braintree). Magento 2 also comes with the migration tool that easily migrates Magento 1 do Magento 2. I would like to add that Magento 2 has an improved performance (Varnish Caching) and have DevOps Tools for Marketing and advertising.
Follow this article as we now show you how to install Magento 2 server on CentOS 8.
Next, you will need to install PHP and other required extensions to your server. By default, the latest version of PHP is not included in the CentOS 8 default repository. So you will need to add EPEL and Remi PHP repository to your system. You can install both with the following command:
Firstly you will need to secure the MariaDB installation and set a MariaDB root password. You can do it with the following command:
mysql_secure_installation
Answer all the questions as shown below:
Enter current password for root (enter for none):
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
Next you will log in to the MariaDB with the following command:
mysql -u root -p
Once logged in create a database and user for Magento with the following command:
MariaDB [(none)]> CREATE DATABASE magentodb;
MariaDB [(none)]> GRANT ALL ON magentodb.* TO magentouser@localhost IDENTIFIED BY 'password';
What you need to do next is to flush the privileges and exit from the MariaDB with the following command:
Before downloading Magento 2, you will need to install Composer on your system. You can install it by running the following command:
curl -sS https://getcomposer.org/installer | php
You should see the following output:
All settings correct for using Composer
Downloading...
Composer (version 2.2.4) successfully installed to: /root/composer.phar
Use it: php composer.phar
Next, move the Composer binary to the system location with the following command:
mv composer.phar /usr/local/bin/composer
Followint that you need to verify the Composer version:
composer --version
Sample output:
Composer version 2.2.4 2022-01-08 12:30:42
Please change the directory to Apache web root and download the latest version of Magento:
cd /var/www/html/
wget https://github.com/magento/magento2/archive/refs/tags/2.4.2.zip
Once the Magento 2 is downloaded, unzip the downloaded file with the following command:
unzip 2.4.2.zip
Then you must move the extracted directory to the Apache web root directory:
mv magento2-2.4.2 /var/www/html/magento2
Following that step, change the directory to magento2 and update the composer with the following command:
cd magento2
composer update
composer install
Next, set proper permission and ownership to magento2 directory:
chown -R apache:apache /var/www/html/magento2
chmod -R 755 /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 {} +
chmod u+x bin/magento
In this section of how to Install Magento 2 on CentOS 8 you will need to create an Apache virtual host configuration file for Magento 2. You can create it with the following command:
nano /etc/httpd/conf.d/magento.conf
Add the following lines:
ServerAdmin admin@example.com
ServerName magento2.example.com
DocumentRoot /var/www/html/magento2/
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
ErrorLog /var/log/httpd/magento_error.log
CustomLog /var/log/httpd/magento_access.log combined
Save and close the file then restart the Apache service to apply the configuration changes:
systemctl restart httpd
You can check the Apache status with the following command:
systemctl status httpd
You should get the following output:
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since Tue 2022-01-18 11:04:03 EST; 6s ago
Docs: man:httpd.service(8)
Main PID: 6455 (httpd)
Status: "Started, listening on: port 80"
Tasks: 213 (limit: 25014)
Memory: 28.9M
CGroup: /system.slice/httpd.service
├─6455 /usr/sbin/httpd -DFOREGROUND
├─6457 /usr/sbin/httpd -DFOREGROUND
├─6458 /usr/sbin/httpd -DFOREGROUND
├─6459 /usr/sbin/httpd -DFOREGROUND
└─6460 /usr/sbin/httpd -DFOREGROUND
Jan 18 11:04:03 centos8 systemd[1]: Stopped The Apache HTTP Server.
Jan 18 11:04:03 centos8 systemd[1]: Starting The Apache HTTP Server...
Jan 18 11:04:03 centos8 httpd[6455]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::200:6>
Jan 18 11:04:03 centos8 systemd[1]: Started The Apache HTTP Server.
Jan 18 11:04:03 centos8 httpd[6455]: Server configured, listening on: port 80
Next section you will need to perform the Magento 2 installation from the command-line interface because Magento web installation wizard has been removed since version 2.3.7.
First change the directory to Magento2 and disable the Elasticsearch module:
cd /var/www/html/magento2/
sudo -u apache bin/magento module:disable {Magento_Elasticsearch,Magento_Elasticsearch6,Magento_Elasticsearch7}
Next, run the following command to start the installation:
In this guide, we explained what Magento is plus new improved Magento 2. We have moved onto how to install Magento 2 on CentOS 8 server. You can now start your own online business using the Magento E-commerce platform.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.