Magento 2.2 Install On CentOS 7

2019, Feb 05    


Install Magento 2.2 on CentOS 7. The stack will require PHP 7.1, MariaDB 10.2, and Apache 2.4. To see the full system requirements to run Magento 2.2 click here.

  1. Install Apache 2.4
  2. Configure Apache
  3. Install PHP 7.1
  4. Configure PHP
  5. Install MariaDB 10.2
  6. Configure MariaDB
  7. Create Magento File System User
  8. Download & Extract Magento Files
  9. SELinux
  10. Set File Permissions

Install Apache 2.4

Install Apache on Centos 7

yum -y install httpd

Verify your install

httpd -v

Output Should Look Like This:


Start The Apache Server

sudo systemctl start httpd

Set The Apache Server To Startup On Boot

sudo systemctl enable httpd

Configure Apache

In this section we will configure Apache to host Magento from the directory /var/www/html

Create Your Virtual Host File

You will now create a config file with your preferred text editor.

 vi /etc/httpd/conf.d/vhost.conf

The below example config file tells Apache what we are hosting and how to host it.

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/
    ErrorLog /var/log/httpd/
    CustomLog /var/log/httpd/ combined

Restart Apache

sudo systemctl restart httpd

Test Apache

Go to the public ip of your server and see if you get the test page for Apache. It should look like this:


Setup Rewrite and .htacess For Apache

Now you will have to setup rewrites for apache or Magento will give you all kinds of trouble.

Using vi/vim or your favorite nix text editor go open:

vi /etc/httpd/conf/httpd.conf

Find the section that starts with:



AllowOverride None


AllowOverride All

Restart Apache

systemctl restart httpd

Install PHP 7.1

yum install -y

yum -y update

Install PHP extensions:

yum -y install php71u php71u-pdo php71u-mysqlnd php71u-opcache php71u-xml php71u-mcrypt php71u-gd php71u-devel php71u-mysql php71u-intl php71u-mbstring php71u-bcmath php71u-json php71u-iconv php71u-soap

Restart Apache

sudo systemctl restart httpd

Verify that PHP 7.1 is installed:

php -v

Output should be similar to this:

PHP 7.1.25 (cli) (built: Dec 11 2018 09:32:31) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.25, Copyright (c) 1999-2018, by Zend Technologies

Configure PHP

To find the PHP config file (php.ini) run the following command:

php --ini

Look for the value of the Loaded Configuration File
Mine is: /etc/php.ini

<figcaption>php –ini output on CentOS 7</figcaption></figure>

Open your php.ini file with your text editor:

vi /etc/php.ini

Set PHP Default Timezone

You will need to change the timezone value to your desired timezone. Use this link to find your value. I will be using the timezone America/Chicago.

Now find the line that starts with:

;date.timezone =

If the line uncommented it will start with a semi colon. Remove the semicolon and set your desire value like this:

date.timezone = America/Chicago

Set the Memory Limit

The memory limit might be set to something low like 128MB, Let’s change it to 2Gigs. Go find the line that starts with this:


Change it to 2G


Find OPcache configuration file. Typically on CentOS 7 systems, it can be found in: /etc/php.d/ My opcache configuration file was named: 10-opcache.ini.

vim /etc/php.d/10-opcache.ini

Find opache.save_comments and uncomment it. Make sure it’s set to 1.


Restart Apache

systemctl restart httpd

Install MariaDB 10.2

Create a MariaDB 10.2 repository by creating this file:

vi /etc/yum.repos.d/MariaDB.repo

Add this text to the file:

name = MariaDB
baseurl =

Kick off the install:

yum install MariaDB-server MariaDB-client -y

Start the Mariadb Service:

systemctl start mariadb

Enable the service to start on boot.

systemctl enable mariadb

Make sure the service is running and the correct version is installed:

systemctl status mariadb 

Configure MariaDB

To configure Mariadb run this command.


Just press enter as their is no password for root.

Enter current password for root (enter for none): 

Next, you will setup a mariadb root password

Set root password? [Y/n] Y

Once you set the password you will do some basic house cleaning.

Remove anonymous uers? [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

Now setup the database instance for Magento. Login to Mariadb as root.

mysql -u root -p

Enter the following command to setup a database called magento with a user of magento with a password of [email protected]###

create database magento;
create user magento IDENTIFIED BY '[email protected]###';
GRANT ALL ON magento.* TO [email protected] IDENTIFIED BY '[email protected]###';
flush privileges;

Create Magento File System User

adduser magento

Set a password for the new user.

passwd magento

Set the user primary group to Apache

usermod -a -G apache magento

Test to see if the user belongs to the Apache group

groups magento

The results should look like this:

magento : apache

Restart Apache

systemctl restart httpd

Download & Extract Magento Files

You will need to login and download the Magento files from their web site. Then just SCP the files over to the web server.

scp Magento.tar.bz2 [email protected]_host:/remote/directory/

Move the compressed file into the /var/www/html directory

mv Magento.tar.bz2 /var/www/html

Extract the files

tar xvjf Magento.tar.bz2

Configure SELinux

Set SELinux context on the below directories:

chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/app/etc

chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/var

chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/pub/media

chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/pub/static

chcon -R --type httpd_sys_rw_content_t <your Magento install dir>/generated

Enable inter-server communication

setsebool -P httpd_can_network_connect=1

File System Permissions

cd /var/www/html

Login as the file system user.

cd <your Magento install dir>
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 :apache .

chmod u+x bin/magento


At this point the web installer should be ready:

http://<Magento host or IP>/<path to Magento root>/setup