How to Install Magento on CentOS 7

Magento is a powerful and highly flexible open-source e-Commerce platform (or content management system (CMS)) written in PHP. It ships in two main editions: Enterprise and Community edition. The Community Edition is intended for developers and small businesses.

It is fully customizable to meet users requirements enabling them to setup and manage a fully operational e-Commerce store in minutes. Magento runs on such web servers as Apache, Nginx and IIS, a backend databases: MySQL or MariaDB, Percona.

In this guide, we will show how to install Magento Community Edition on a CentOS 7 VPS with LAMP (Linux, Apache MariaDB and PHP) stack. The same instructions also works on RHEL and Fedora based distributions with slight changes in commands.


This article will guide you to install the most recent version of “Community Edition” of Magento on a system running:

  1. Apache version 2.2 or 2.4
  2. PHP version 5.6 or 7.0.x or later with required extensions
  3. MySQL version 5.6 or later

Note: For this setup, I am using website hostname as “” and IP address is ““.

Step 1: Installing Apache Web Server

1. Installing Apache web server is so simple, from the official repositories:

# yum install httpd

2. Then, in order to allow access to Apache services from HTTP and HTTPS, we have to open port 80 and 443 where the HTTPD daemon is listening as follows:

------------ On CentOS/RHEL 7 ------------ 
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

---------- On CentOS/RHEL 6 ----------
# iptables -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT
# service iptables save

Step 2: Install PHP Support for Apache

As I said Magento requires PHP 5.6 or 7.0 and default CentOS repository includes PHP 5.4, which is not compatible with latest Magento 2 version.

3. To install PHP 7, you need to add the EPEL and IUS (Inline with Upstream Stable) repository in order to install PHP 7 using yum:

Install PHP 7 on CentOS 7

# yum install -y
# yum -y update
# yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-mcrypt php70u-gd php70u-devel php70u-mysql php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv

Install PHP 7 on CentOS 6

# yum -y update
# yum -y install epel-release
# wget
# wget
# rpm -Uvh ius-release*.rpm
# yum -y update
# yum -y install php70u php70u-pdo php70u-mysqlnd php70u-opcache php70u-xml php70u-mcrypt php70u-gd php70u-devel php70u-mysql php70u-intl php70u-mbstring php70u-bcmath php70u-json php70u-iconv

4. Next, open and modify the following settings in your /etc/php.ini file:

max_input_time = 30
memory_limit= 512M
error_log = /var/log/php/error.log
date.timezone = Asia/Calcutta

Note: The value for date.timezone will vary as per your systems time zone. Refer to check system timezone and set timezone in Linux.

5. Next, to retrieve a complete info concerning the PHP installation and all its current configurations from a web browser, let’s create a info.php file in the Apache DocumentRoot (/var/www/html) using the following command.

# echo "<?php  phpinfo(); ?>" > /var/www/html/info.php

6. Once all the required configuration completes, its time to start the Apache service and enable it to start automatically from the next system boot as well like so:

------------ On CentOS/RHEL 7 ------------ 
# systemctl start httpd
# systemctl enable httpd

------------ On CentOS/RHEL 6 ------------
# service httpd start
# chkconfig httpd on

7. Next, we can verify that Apache and PHP is working fine; open a remote browser and type your server IP Address using HTTP protocol in the URL and the default Apache2 and PHP info page should appear.

Check PHP 7 Info

Check PHP 7 Info

Step 3: Install and Configure MariaDB Database

8. We must note that Red Hat Enterprise Linux/CentOS 7.0 moved from supporting MySQL to MariaDB as the default database management system.

To install MariaDB database, we need to add the following official MariaDB repository to file /etc/yum.repos.d/MariaDB.repo as shown.

Install MariaDB in CentOS 7

name = MariaDB
baseurl =

Install MariaDB On RHEL 7

name = MariaDB
baseurl =

Install MariaDB in CentOS 6

name = MariaDB
baseurl =

Install MariaDB On RHEL 6

name = MariaDB
baseurl =

9. Once the repo file in created, we are now able to install MariaDB as follows:

# yum install mariadb-server mariadb
# yum install MariaDB-server MariaDB-client

10. After the installation of MariaDB packages completes, start the database daemon for the mean time and enable it to start automatically at the next boot.

------------ On CentOS/RHEL 7 ------------ 
# systemctl start mariadb
# systemctl enable mariadb

------------ On CentOS/RHEL 6 ------------
# service mysqld start
# chkconfig mysqld on

11. Then run the mysql_secure_installation script to secure the database (set root password, disable remote root login, remove test database and remove anonymous users) as follows:

# mysql_secure_installation

12. Next create a magento database and user as shown.

# mysql -u root -p

## Creating New User for Magento Database ##
mysql> CREATE USER magento@localhost IDENTIFIED BY "your_password_here";

## Create New Database ##
mysql> create database magento;

## Grant Privileges to Database ##
mysql> GRANT ALL ON magento.* TO magento@localhost;

## FLUSH privileges ##

## Exit ##
mysql> exit

Step 4: Install Magento Community Edition

12. Now, go the Magento official website, and create a user account in case you a new customer.(or simply login if you already have an account) and download the latest version of Magento Community Edition.


13. After you download Magento tar file, extract the contents into the Apache Document Root (/var/www/html) as follows:

# tar -zxvf Magento-CE-2.1.5-2017-02-20-05-36-16.tar.gz -C /var/www/html/

14. Now you need to set Apache ownership to the files and folders.

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

15. Now open your browser and navigate to the following url, you will be presented with the Magento installation wizard.

Magento Installation Wizard

Magento Installation Wizard

16. Next, the wizard will carry a Readiness Check for the correct PHP version, file permissions and compatibility.

Magento Readiness Check

Magento Readiness Check

Magento Readiness Check Summary

Magento Readiness Check Summary

17. Enter magento database settings.

Magento Database Settings

Magento Database Settings

18. Magento Web site configuration.

Magento Web Configuration

Magento Web Configuration

19. Customize your Magento store by setting timezone, currency and language.

Customize Magento Store

Customize Magento Store

20. Create a new Admin account to manage your Magento store.

Create Magento Admin Account

Create Magento Admin Account

21. Now click ‘Install Now‘ to continue Magento installation.

Install Magento

Install Magento

Magento Installation Completes

Magento Installation Completes

That’s it! you have successfully installed Magento in CentOS 7. If you face any errors during installation, feel free to ask for help in the comments..

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

17 Responses

  1. Ahmer Mansoor says:

    Hi, Good article, but you have missed the SELinux settings therein. Please include.

  2. R Raut says:


    I installed Magento 2 and Zimbra with help of Tecmint articles. Thank you. Now I am looking Cluster installation for Magento 2. Will you please help me?

    Best regards..

  3. Anh Phan says:

    At step 15, I type in the URL with my IP address and a blank page shows up instead of the Installation Wizard. All proper steps have been taken without errors.

  4. kokogyi says:

    Hi Ravi Saive,

    Thanks a lot for your complete instruction. I do that your guide. I can Successful install Magento 2.2.0 in my centos 7.5, php = 7.0.30. RAM = 1GB, storage = 25GB.

    But after install my home page is broken (like css do not effect). Others pages was not found.

    • Ravi Saive says:


      Could you share the link to homepage? so that I can check it. Also have you installed the Magento on correct web server root directory?

  5. R R says:

    Hello, I have followed all steps. There is not problem with installation with magento 1 but with magento 2 I have getting this message “Vendor autoload is not found. Please run ‘composer install’ under application root directory.

    Will you please help me to solve this.

    Best regards..

    • Ravi Saive says:


      On Which Linux distributions are you trying to install Magento 2?

      • R R says:

        CentOS 7, Apache

        • Ravi Saive says:


          Magento Update installation dependencies as follows:

          First log in to your Magento Linux server, change to the Magento installation directory and run composer install as shown.

          # cd /var/www/html/magento2 && composer install

          This command updates package dependencies and can take a few minutes to complete.

  6. Jad Atoui says:

    One PHP extension missing: yum install php70u-soap

  7. Aaron Sullivan says:

    I am following this guide but having issues with php. I cannot get it to properly install. I get errors telling me conflicts the way you have it written and to use --skip-broken. didn’t work either.

    The phpinfo() page will not display anything except for the php tag that got echo’ed to the file. Any Idea?

    • Ravi Saive says:


      Please remove or disable any third party repo, before installing PHP version as in this guide. Because having multiple repositories sometimes conflict with each other..

  8. Nono says:

    I followed these steps for magento2 install on centos to no avail. The Ip/magento2/setup/ is not displaying the default installation as displayed above.

    >[[email protected] html]# ls -a
    . .git .htaccess index.php magento2 .travis.yml
    .. .gitignore .htaccess.sample info.php .php_cs
    >[[email protected] html]# cd magento2
    [[email protected] magento2]# ls -a
    . lib pub
    .. COPYING.txt LICENSE_AFL.txt
    app dev LICENSE.txt releases
    bin Gruntfile.js.sample magento setup index.php nginx.conf.sample var
    composer.json info.php package.json.sample vendor
    composer.lock php.ini.sample
    composer.phar ius-release.rpm phpserver
    [[email protected] magento2]#

    could you shed some light on what am i doing wrong here?

    Thank you in advance for your help.

  9. Ousman says:

    Hello Ravi,

    Is it possible to talk to you in private? I’m new on Magento and I will appreciate if you can help me to build my Magento Platform.


  10. Fayyaz Khattak says:

    Very informative and nicely written article. This will help beginners a lot to setup server and install Magento 2 store. I had also written a brief tutorial to install Magento 2 on Debian server. Please have a look at it:

    If you have any suggestions regarding my article, please note it down in the comments section.

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.