In this guide, we will explain how to install Magento on CentOS 7.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area and deploy your Cloudwafer cloud server.

Step 1: Install Nginx
If you don't have the Nginx web server installed, issue the commands below to install it on your CentOS 7 Server. First, enable access to the EPEL repository which provides additional packages for CentOS on your server by typing:

sudo yum install epel-release -y

Next, issue the command below to install Nginx

sudo yum install nginx



Upon completion, start and enable Nginx by issuing the command below:

sudo systemctl start nginx
sudo systemctl enable nginx


You can check the status of Nginx by issuing the command below:

sudo systemctl status nginx


Step 2 - Install and Configure PHP-FPM

Download and add a new webtatic repository to the system.

rpm -Uvh


Next, issue the command below to install PHP-FPM7 with all packages and extension needed for the Magento installation.

sudo yum -y install php72w-fpm php72w-mcrypt php72w-curl php72w-cli php72w-mysql php72w-gd php72w-xsl php72w-json php72w-intl php72w-pear php72w-devel php72w-mbstring php72w-zip php72w-soap


After installing,


Next, we need to configure our PHP-FPM7 installation by making some changes to the php.ini file and the php-fpm configuration www.conf file.

sudo nano /etc/php.ini

Uncomment the cgi.fix_pathinfo line and change value to 0. On the nano Editor, use Ctrl+W to search


Uncomment and change to cgi.fix_pathinfo=0


Make changes to memory_limit, max_execution_time, enable the zlib.output compression, and uncomment session path directory, setting the values as shown below.

memory_limit = 512M
max_execution_time = 1800
zlib.output_compression = On
session.save_path = "/var/lib/php/session"

Magento-CentOs-10a Magento-CentOs-10b Magento-CentOs-10c Magento-CentOs-10d

Ensure to save before you exit.

Next, edit the php-fpm configuration file www.conf with the command below:

sudo nano /etc/php-fpm.d/www.conf

By default, the www.conf file instructs PHP-FPM7 to run under the apache user and group:

However, for our configurations, change the value to nginx for the user and group lines as shown below:


Next, we are going to run php-fpm under a socket file, not a server port.

Change the value of the listen line to the path of the socket file as shown below:

Next, uncomment listen.owner, and listen.mode and make the changes as shown below:
Magento-CentOs-11e Next, change the environment variables and make the changes as shown below:

Next, create a new directory for session path and change the owner to the nginx user and group.

Next, Create a new directory for php-fpm socket file location and change the owner to the nginx user and group.

Lastly, using the systemctl command, start the PHP-FPM daemon now and enable it to start at boot by issuing the command below:
Magento-CentOs-12c Ensure to save before you exit.

Step 3: Install MySQL Server
In this guide, we are going to install MySQL 5.7 which can be installed from the official MySQL repository. We begin by adding the MySQL repository first with the command below:

sudo yum localinstall


Next, install MySQL 5.7 from the MySQL repository with the command below:

sudo yum install mysql-community-server


Next, start mysql using the systemctl command and add it to start at boot by issuing the commands below:

sudo systemctl start mysqld
sudo systemctl enable mysqld


To view the temporary MySQL root password, issue the command below:

grep 'temporary' /var/log/mysqld.log


To change the password and secure our MySQL installation, issue the command below entering our temporary password:



Remove anonymous users, disallow root login remotely, remove test database, and reload privilege tables:


Next, from the MySQL environment, we will create a new user and a new database for our Magento installation:

 create database magentodb;
 create user magentocwadmin@localhost identified by 'Cloudwafer123*';
 grant all privileges on magentodb.* to magentocwadmin@localhost identified by 'Cloudwafer123*';
 flush privileges;

Note: Change magentodb, magentocwadmin and Cloudwafer123* to what suits you but ensure to note it.


Step 4: Install and Configure Magento
We are now ready to install and configure Magento, but first, we need to PHP composer for the Magento package installation.

We will use Composer for PHP package dependency installation. Install composer with the curl command below.

curl -sS | sudo php -- --install-dir=/usr/bin --filename=composer

After a successful installation, check the composer version as shown below:

 composer -v


We can now download and Extract Magento by navigating to the var/www directory and download the Magento code with the wget command as shown below:

cd /var/www/


You might be required to install unzip to extract the files. To do this, issue the command below:

sudo yum -y install unzip

Proceed to extract Magento code and rename the directory to **magento2** directory.

sudo unzip
sudo mv magento2-2.1 magento2

Install PHP Dependencies

In order to successfully install Magento, some PHP dependencies are required. This will be installed with the composer command as shown below from the newly created magento2 directory.

cd magento2
sudo composer install -v

Step 5: Configure Magento Virtual Host Navigate to the Nginx directory and create a new virtual host configuration file named magento.conf in the conf.d directory.

cd /etc/nginx/
sudo nano conf.d/magento.conf

Enter the virtual host configuration below.

upstream fastcgi_backend {
    server  unix:/run/php/php-fpm.sock;
server {
    listen 80;
    set $MAGE_ROOT /var/www/magento2;
    set $MAGE_MODE developer;
    include /var/www/magento2/nginx.conf.sample;


Ensure to save before you exit.

You can test the configuration using Nginx's test tool as shown below:

nginx -t


If there are no errors, restart Nginx service:

sudo systemctl restart nginx

Finally, to complete our installation, verify and change the values shown below:

cd /var/www/magento2

bin/magento setup:install --backend-frontname="adminlogin" \
--key="kkssid8sdnsd52jds7ds6d02odd79u9" \
--db-host="localhost" \
--db-name="magentodb" \
--db-user="magentocwadmin" \
--db-password="Cloudwafer123*" \
--language="en_US" \
--currency="NGN" \
--timezone="Nigeria/Lagos" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="" \
--base-url-secure="" \
--admin-user=admin \
--admin-password=cloudwaferadmin12* \ \
--admin-firstname=admin \
--admin-lastname=user \

You will be required to change the values for the following:

--backend-frontname: Magento admin login page "adminlogin"
--key: generate your own key
--db-host: Database host localhost
--db-name: database name 'magentodb'
--db-user: database user 'magentocwadmin'
--db-password: database password 'Cloudwafer123*'
--base-url: Magento URL
--admin-user: Your admin user
--admin-password: Your Magento admin password
--admin-email: Your email address

Lastly, issue the command below to change the permission for the etc directory and change the owner of the magento2 directory to the nginx user.

sudo chmod 700 /var/www/magento2/app/etc
sudo chown -R nginx:nginx /var/www/magento2


Configure Magento Cron
The Magento indexer requires this cron job as nginx user since magento runs under nginx user and group.

crontab -u nginx -e

Type the following:

* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log

Ensure to save before you exit. Then, visit your Magento URL on the browser.

Visit the official Magento webpage to learn more.