Learn how to install Magento 2 on CentOS 8 with our step-by-step guide. Follow these instructions to set up and configure Magento eCommerce Platform, ensuring a smooth and efficient installation process on your Linux server. #centlinux #linux #magento
Magento is a leading open-source eCommerce platform that provides businesses with a highly customizable online store. It is designed to be scalable and offers a wide range of features to help merchants manage their products, orders, and customers. Some key features include:
Magento is available in two main editions: Magento Open Source (formerly Community Edition) and Magento Commerce (formerly Enterprise Edition). Magento Open Source is free to download and use, while Magento Commerce offers additional features and support for large enterprises. Magento’s flexibility and extensive feature set make it a preferred choice for many businesses looking to build a robust and scalable eCommerce presence.
Recommended Online Training: Magento 2 Development (Adobe Commerce) Updated Version (V2)
Magento and WooCommerce are two popular eCommerce platforms, each with its own strengths and ideal use cases. Here’s a comparison to help you decide which might be better for your business:
You can also view the feature comparison of Magento Commerce with other Open Source here.
Read Also: Top 10 Magento Development Services
We are using a minimal CentOS 8 virtual machine with following specifications.
Connect with magento-2.centlinux.com as Linux root user by using a SSH client.
It is a best practice to update your Linux operating system before installing any new software. Therefore, execute the dnf command and update installed software packages on CentOS / RHEL 8.
You may need to enable free Redhat subscription for your RHEL operating system.
# dnf update -y Last metadata expiration check: 0:00:40 ago on Thu 03 Dec 2020 08:47:52 PM PKT. Dependencies resolved. Nothing to do. Complete!
Our Linux operating system is already up-to-date, therefore, no package is updated this time. The output may vary on your CentOS 8 server.
Verify the Linux operating system and updated Kernel versions.
# uname -r 4.18.0-193.28.1.el8_2.x86_64 # cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core)
Magento requires following prerequisite software. Therefore, you must install them to install Magento on CentOS 8.
Apache, PHP and MySQL are available in standard yum repositories, therefore, you can install all of them with a single dnf command.
# dnf install -y httpd mariadb-server @php:7.3 mod_ssl wget unzip
Configure PHP settings as required by the eCommerce software .
# vi /etc/php.ini
Locate and adjust following parameter in this file.
memory_limit = 1024M
Enable and start Apache, MySQL and PHP services.
# systemctl enable --now mariadb.service httpd.service php-fpm.service
Configure MySQL database server security as follows.
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
To allow incoming traffic to HTTP service port, you can add http service or port 80/tcp in your Linux firewall.
# firewall-cmd --permanent --add-service=http success # firewall-cmd --reload success
Create a Linux user to own Magento directory and files.
# adduser magento # usermod -a -G apache magento
Create a directory for deploying Magento eCommerce software.
# mkdir /var/www/magento # chown magento:apache /var/www/magento
Magento uses MySQL as its backend database. You have already installed MariaDB on your Linux server. Now, login to MySQL shell as root user.
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 8 Server version: 10.3.17-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]>
Create a MySQL database for Magento eCommerce software.
MariaDB [(none)]> CREATE DATABASE magentodb; Query OK, 1 row affected (0.001 sec)
Grant all privileges on magentodb database to magento user. This command also creates the magento user, if not already created.
MariaDB [(none)]> GRANT ALL ON magentodb.* TO magento@localhost IDENTIFIED BY 'Str0ngP@ssw0rd'; Query OK, 0 rows affected (0.001 sec)
Exit from MySQL shell.
MariaDB [(none)]> exit Bye
Starting from Magento 2.4.0, ElasticSearch is now being used for search. Therefore, you are also required to install ElasticSearch on Linux server.
ElasticSearch needs Java Runtime, therefore, before installing ElasticSearch you have to install OpenJDK on CentOS 8 machine.
# dnf install -y java-11-openjdk
Verify the Java version of installed software.
# java -version openjdk version "11.0.9" 2020-10-20 LTS OpenJDK Runtime Environment 18.9 (build 11.0.9+11-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.9+11-LTS, mixed mode, sharing)
Import the ElasticSearch GPG key by using rpm command.
# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Create a yum repository file by using vi text editor.
# vi /etc/yum.repos.d/elasticsearch.repo
Add following directives in this repo file.
[elasticsearch] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=0 autorefresh=1 type=rpm-md
You can now easily install ElasticSearch on your Linux server by using dnf command.
# dnf install -y --enablerepo=elasticsearch elasticsearch
Since, we are installing on a virtual machine with limited memory. Therefore, we are reducing the Java virtual machine (JVM) memory options as follows.
Open jvm.option file in vi text editor.
# vi /etc/elasticsearch/jvm.options
Find and adjust following parameters therein.
-Xms256m -Xmx512m
Enable and start ElasticSearch service.
# systemctl enable --now elasticsearch.service
Composer is a dependency manager for PHP.
Currently, the Composer v2.0 is available on the Internet. But Magento 2.4.1 does not supports it.
Therefore, you have to use Composer v1.0 for your eCommerce server.
Download the Composer by using wget command.
# wget https://getcomposer.org/composer-1.phar --2020-12-05 18:53:38-- https://getcomposer.org/composer-1.phar Resolving getcomposer.org (getcomposer.org)... 142.44.245.229, 2607:5300:201:2100::4:d105 Connecting to getcomposer.org (getcomposer.org)|142.44.245.229|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1999995 (1.9M) [application/octet-stream] Saving to: âcomposer-1.pharâ composer-1.phar 100%[===================>] 1.91M 63.0KB/s in 29s 2020-12-05 18:54:11 (67.6 KB/s) - âcomposer-1.pharâ saved [1999995/1999995]
Add execute permissions to composer file and copy it in /usr/local/bin directory, so users can run it from any location.
# chmod +x composer-1.phar # mv composer-1.phar /usr/local/bin/composer
All prerequisites has been installed and configured. Now you are ready to install Magento on CentOS 8.
You can now use composer to install the Magento Open Source edition as follows.
Note: You may be asked to provide a Username/Password to install Magento on CentOS 8. The username is the Public Key and Password is the Private Key. These Public/Private keys can be generated at Magento Marketplace website. You are required to sign-up/sign-in to generate these keys.
# composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /var/www/magento
Adjust file permissions of Magento files as follows.
# cd /var/www/magento # 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 magento:apache /var/www/magento/ # chmod u+x bin/magento
Adjust SELinux file contexts and booleans.
# restorecon -R /var/www/magento # setsebool -P httpd_unified 1
Create Apache virtual host configurations for Magento.
# vi /etc/httpd/conf.d/magento.conf
And add following directives in this file.
<VirtualHost *:80> ServerName magento-2.centlinux.com DocumentRoot /var/www/magento ErrorLog /var/log/httpd/magento_error.log CustomLog /var/log/httpd/magento_access.log combined <Directory /var/www/magento > Options FollowSymLinks AllowOverride All </Directory> </VirtualHost>
Restart Apache service to load newly added configurations.
# systemctl restart httpd.service
Magento web setup is no longer available in Magento 2.4.0 (or later). You must use Magento Command Line to install it.
# php /var/www/magento/bin/magento setup:install > --base-url="http://magento-2.centlinux.com/magento/" > --db-host="localhost" > --db-name="magentodb" > --db-user="magento" > --db-password="Str0ngP@ssw0rd" > --search-engine="elasticsearch7" > --admin-firstname="admin" > --admin-lastname="admin" > --admin-email="admin@centlinux.com" > --admin-user="admin" > --admin-password="Ahmer@1234" > --language="en_US" > --currency="USD" > --timezone="America/Chicago" > --use-rewrites="1" > --backend-frontname="admin"
Adjust SELinux file contexts for following Magento directories.
# semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/var(/.*)?' # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/generated(/.*)?' # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/vendor(/.*)?' # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/pub/static(/.*)?' # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/pub/media(/.*)?' # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/magento/app/etc(/.*)?' # restorecon -R /var/www/magento
Magento eCommerce Platform has been installed.
Now its time to read Magento 2 Developer’s Guide (PAID LINK) by Packt Publishing, if you want to start developing your eCommerce website.
Installing Magento 2 on CentOS 8 can be a complex process, but with the right guidance, it becomes manageable and rewarding. By following a step-by-step approach, you can ensure that your Magento store is set up efficiently and ready to handle your eCommerce needs.
If you need professional assistance with the installation or any other aspect of your Magento store, I offer expert services to help you achieve a seamless and optimized setup. Check out my Fiverr gig for Linux Server Administration. I provide comprehensive support, including installation, configuration, and troubleshooting, to ensure your eCommerce platform runs smoothly.
With my service, you can focus on growing your business while I handle the technical details. Let’s make your Magento store a success!
Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…
Discover how to change Apache port in Linux easily. Follow our simple guide to modify…
Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…
Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…
Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…
Explore the ultimate guide to VPS servers and learn everything about Virtual Private Servers, including…
This website uses cookies.
View Comments
this is a really great article, easy to follow.
I just got an error when try to install magento in command cli
-bash: --base-url=http://magento-2.centlinux.com/: No such file or directory
Please ensure that the server hostname is resolvable.
My Elasticsearch is not getting assign.
Please discuss it on our Facebook Page.