Share on Social Media

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

What is 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:

  1. Flexible Shopping Cart System: Allows businesses to offer various products and services with multiple shipping and payment options.
  2. Extensive Customization Options: Enables merchants to customize the look and feel of their store to align with their brand identity.
  3. Robust SEO Capabilities: Built-in tools help improve search engine rankings and drive organic traffic to the store.
  4. Advanced Marketing Tools: Includes promotional and discount capabilities, email marketing, and customer segmentation.
  5. Comprehensive Inventory Management: Facilitates efficient product management, including tracking stock levels, managing product attributes, and setting up categories.
  6. Multi-Store Management: Allows the management of multiple stores from a single admin interface, making it ideal for businesses with various brands or international markets.
  7. Third-Party Integrations: Supports integration with numerous third-party services and extensions, enhancing functionality and improving customer experience.

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)

4316414 da0c 3show?id=oLRJ54lcVEg&offerid=1074530.4316414&bids=1074530

Magento vs WooCommerce

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:

Magento

Scalability:

  • Pros: Highly scalable, suitable for large businesses and enterprises with high traffic and extensive product catalogs.
  • Cons: Can be resource-intensive and may require robust hosting solutions.

Features:

  • Pros: Rich in built-in features, offering advanced capabilities for marketing, SEO, and inventory management. Supports multi-store management from a single dashboard.
  • Cons: Some features are complex and might require professional development to fully utilize.

Customization:

  • Pros: Highly customizable, allowing for significant modifications to meet specific business needs.
  • Cons: Customization can be complex and often requires skilled developers.

Cost:

  • Pros: The open-source version (Magento Open Source) is free to use.
  • Cons: Enterprise version (Magento Commerce) can be expensive. High costs for hosting, development, and maintenance.

Community and Support:

  • Pros: Strong community support with a wealth of extensions and themes.
  • Cons: Official support is more readily available for the paid version.

WooCommerce

Ease of Use:

  • Pros: User-friendly, especially for those familiar with WordPress. Easy to set up and manage.
  • Cons: May not offer the same depth of features as Magento out of the box.

Features:

  • Pros: Offers essential eCommerce features with the ability to extend functionality through plugins. Great for small to medium-sized stores.
  • Cons: Extensive customization may require additional plugins, which can lead to higher costs and potential compatibility issues.

Customization:

  • Pros: Highly flexible, with numerous plugins and themes available to tailor the store to specific needs.
  • Cons: Too many plugins can slow down the website and make it harder to manage.

Cost:

  • Pros: Free core plugin with many free and premium extensions. Lower initial costs compared to Magento.
  • Cons: Costs can add up with premium plugins and themes, as well as potentially needing paid support or developers.

Community and Support:

  • Pros: Large community with extensive resources, tutorials, and forums. Direct integration with WordPress means access to a wide range of additional plugins and themes.
  • Cons: Support primarily through community forums unless paid support is purchased.

Conclusion

  • Choose Magento if: You have a large, complex store with a substantial budget for development and maintenance. It’s ideal for enterprises requiring extensive features, scalability, and customization.
  • Choose WooCommerce if: You have a small to medium-sized store and prefer a user-friendly platform with lower initial costs. It’s perfect for those already familiar with WordPress and looking for a flexible and extendable solution.

You can also view the feature comparison of Magento Commerce with other Open Source here.

Read Also: Top 10 Magento Development Services

Environment Specification

We are using a minimal CentOS 8 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 8.2
  • Hostname – magento-2.centlinux.com
  • IP Address – 192.168.116.230 /24

Update Linux Server Packages

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)

Install Magento 2 Prerequisites

Magento requires following prerequisite software. Therefore, you must install them to install Magento on CentOS 8.

  • Nginx or Apache Web Server
  • PHP (7.3 or later)
  • MySQL Database Server
  • ElasticSearch

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!

Configure Linux Firewall

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 Linux User and Directory

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

Create MySQL Database for Magento eCommerce

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

Install ElasticSearch on CentOS 8

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
Elasticsearch Installation on CentOS 8
Elasticsearch Installation on CentOS 8

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

Install Composer on CentOS 8

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.

Magento Installation 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"
Magento Installation 1
Magento Installation 1
Magento Installation 2
Magento Installation 2

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.

Final Thoughts

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!

4 thoughts on “How to install Magento 2 on CentOS 8”
  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *