How to Install and Configure Magento 2 on CentOS 7

Table of Contents


Magento is a free and open source content management system for e-commerce. It is written in PHP and uses MySQL to store its data. You can run any types of e-commerce website using Magento. If you are looking for a great e-commerce web application for online store, then Magento is the best option for you. Magento provides a basic theme that can be used to set up an e-commerce website easily. Magento allows its user to install themes and change the display of the website or its functionality.

This tutorial will explain how to install Magento 2 on CentOS 7.


  • A server running CentOS 7.
  • A non-root user with sudo privilege setup on your server.

Getting Started

Before starting, update your system with the latest available packages by running the following command:

sudo yum update -y

Once your system is up-to-date, you can proceed to the next step.

Install and Configure LAMP Stack

You will need to install Apache, MariaDB, and PHP on your system as prerequisites of Magento.

Install Apache with the following command:

sudo yum install httpd -y

Install the latest version of the MariaDB server. MariaDB 10 is not available in the CentOS 7 default repository, so you will need to add the repository first.

sudo nano /etc/yum.repos.d/mariadb.repo

Add the following lines:

name = MariaDB
baseurl =

Save the file and update the MariaDB repo with the following command:

sudo yum update -y

Once the repo is updated, you can install MariaDB with the following command:

sudo yum install mariadb-server

Start the Apache web server and MariaDB and also enable them to start on boot:

sudo systemctl start httpd
sudo systemctl start mariadb
sudo systemctl enable httpd
sudo systemctl enable mariadb

Magento supports PHP versions from PHP 5.6 to PHP 7.1. We will install PHP 7 and other required modules for Magento.

To install PHP 7 and other modules, run the following commands:

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

Once installation is completed, you can verify the version of the PHP by running the following command:

php -v


PHP 7.0.13 (cli) (built: Nov 10 2016 08:44:18) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.13, Copyright (c) 1999-2016, by Zend Technologies

You will need to increase the memory limit of PHP and also set the timezone. You can do this by editing the php.ini file:

sudo nano /etc/php.ini

Change the following lines:

memory_limit = 500M
date.timezone = Asia/Kolkata

Save the file when you are finished.

Next you will need to configure Apache to use mod_rewrite.

You can do this by editing /etc/httpd/conf/httpd.conf file.

sudo nano /etc/httpd/conf/httpd.conf

Find the line Include conf.modules.d/*.conf and add the following line just below these lines:

LoadModule rewrite_module modules/

Change the value of AllowOverride None to AllowOverride All.

AllowOverride All

Save the file and restart Apache:

sudo systemctl restart httpd

Configure a Database for Magento

You will need to create a database for Magento.

Log in to MariaDB with the following command:

mysql -u root -p

Now run the following query to create a new database.

MariaDB [(none)]>create database magento;

Next, create the database user for this database and assign the user full access over the database.

MariaDB [(none)]>grant all on magento.* TO magentouser@localhost identified by 'Admin@1234';
MariaDB [(none)]>flush privileges;

Note: You can set the database name and credentials according to your choice. Make sure you use a strong password.

Next, exit from the MySQL prompt using the following command.

MariaDB [(none)]>exit

Install Composer

Composer is an application level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP and required libraries.

To install composer simply run the following command:

curl -sS | php

The above command will download the latest version of the composer.phar file in your home directory.

To use composer, you will need to move it to /usr/bin/ directory:

sudo mv composer.phar /usr/bin/composer

You can verify the version of the composer with the following command:

composer -V


Composer version 1.2.4 2016-12-06 22:00:51

Install Magento

You can install Magento in different ways. The best method to install Magento is to download the Magento using Git, then install it using composer.

First, download the Magento with the git command:

cd /var/www/html/
sudo git clone

The above command will install the latest version of Magento in Apache's default document root directory.

It is recommended to switch to a stable release of Magento.

You can do this with the following command:

cd magento2
sudo git checkout tags/2.1.0 -b 2.1.0

The above command will checkout to a stable version 2.1.0.

Move all the installation files to document root of Apache:

sudo shopt -s dotglob nullglob
sudo mv /var/www/html/magento2/* /var/www/html/

You will also need to set proper permissions to the files and folders of Magento:

sudo chown -R apache:apache /var/www/html/
sudo chmod -R 775 /var/www/html/

Install Magento using the following command:

cd /var/www/html
sudo composer install

The above command will install Magento in your server by installing required frameworks.

Access the Magento Web Installation Wizard

It is time to finish the Magento installation using a web based interface.

Open your favourite web browser and type the URL http://your-server-ip, You should see the following page:

Install Magento

Click on Agree and Setup Magento button, you should see the following page:

Magento Readiness

Click on the Next button to complete readiness check, you should see the following page:

Magento Complete Readiness

Click on the Next button and provides database information as shown below:

Magento Database Details

Click on the Next button you should see the following page:

Magento Web Configuration

Click on the Next button, you should see the following page. On this page you can customize your store as your need:

Click on the Next button and provide new admin account details as shown below:

Magento Admin Details

Click on Next button and click on Install Now button to install Magento as shown below:

Magento Install Now

Once installation is completed, you should see the following page:

Magento Installation Success

Finally launch the Magento Admin by clicking Launch Magento Admin button and provide admin credentials:

Magento Admin Login

Magento Dashboard

Magento Dashboard

You can also launch Magento Admin directly by typing the URL http://your-server-ip/admin_1srbr7 in your web browser.

You will need to setup some cron jobs for Magento.

You can configure it with the following command:

crontab -u apache -e

Add the following lines:

*/5 * * * * php -c /etc /var/www/html/bin/magento cron:run
*/5 * * * * php -c /etc /var/www/html/update/cron.php
*/5 * * * * php -c /etc /var/www/html/bin/magento setup:cron:run

Save the file when you are finished.

If you want to upgrade Magento to the latest version in the future, then run the following command:

cd /var/www/html
sudo composer update


Congratulations! You have successfully installed Magento 2 using composer on your server. You can now easily deploy your own online store. Feel free to ask me if you have any questions.

  • Hello, mister.

    I follow your tutorial step by step and the result was the same as the yours. But after I reboot the server I was uncapable to access the Magento administrador panel. I suspect it is coming about due to a bad cron config. May you help me?

  • *followed

  • Can't get this to work, run through the whole thing with a fresh install of Centos 7 twice and both times /admin 404s and no style load in the frontend.

  • OK so I got there in the end. There was more than one instance of "AllowOverride none" in my httpd.conf file and I hadn't changed the correct one to AllowOverride All. Thanks for the tutorial.

  • I used http://<your-server-ip>/setup to config website

Log In, Add a Comment