Install Magento2 with PHP7 on Centos7/RHEL

Install Magento2 with PHP7 on Centos7/RHEL

Magento2 installation on RHEL/Centos 7 with Php7.

Subscribing to the IUS Community Project Repository
Since PHP 7.x is not yet packaged in official repositories for the major distributions, we’ll have to rely on a third-party source. Several repositories offer PHP 7 RPM files. We’ll use the IUS repository.

IUS offers an installation script for subscribing to their repository and importing associated GPG keys. Make sure you’re in your home directory, and retrieve the script using curl:

curl '' -o
sudo bash

Add rpm Package for mysql 5.7 server.

$ sudo rpm -iUvh

Step 1-:

Install Required Packages-:

sudo yum install -y mod_php70u php70u-cli php70u-mysqlnd php70u-json php70u-mbstring php70u-gd php70u-dom php70u-simplexml php70u-mcrypt php70u-intl httpd mysql-server git

To start and enable for startup MySql-Server

sudo systemctl enable mysqld
sudo systemctl start mysqld

Use the below command to get temporary MySql root password.

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

Run the below command to reset the root password.


Use the password in grep command.

Enter the new root password

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

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? (Press y|Y for Yes, any other key for No) : y

By default, MySQL 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

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...

 - Removing privileges on test database...

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done!

Add a database for magento2 instance.

 $ mysql -u root -p -e "create database <DatabaseName>";

Step 2-:

Enable the apache to start up and restart the apache.

sudo systemctl enable httpd
sudo systemctl restart httpd

Setup the Firewall for the port 80 and 443.

$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --zone=public --add-port=443/tcp --permanent
$ firewall-cmd --reload

Check the phpinfo version and enable modules.

 $ sudo echo "<?php phpinfo() ?>" > /var/www/html/phpinfo.php

Step 3-:

Now setup the Magento2 (M2) instance.

cd /var/www/html/
git clone
mv /var/www/html/magento2/* /var/www/html/
mv /var/www/html/magento2/.htaccess /var/www/html/

Install Magento2 dependencies via composer.

$ composer install

if composer is not installed.
(use the below command to install composer)

curl -sS | php 
mv composer.phar /usr/local/bin/composer
sudo chmod 0755 /usr/local/bin/composer

if prompt while composer install

Installing magento/composer (1.0.2)
    Authentication required (

Register on
Login with your email and password.
Click on “My Account” > “Connect” tab > Secure Key
You will find the Public Key and Private key.
Add key using or regenerate and use in below

 nano ~/.composer/auth.json


 vi ~/.composer/auth.json
   "github-oauth": {
     "": ""
   "http-basic": {
      "": {
         "username": "",
         "password": ""

To change the permission of current directory.

sudo chmod -R 755 .

Edit .htaccess file of main folder and set RewriteBase with your application directory name.

 RewriteBase /magento2/

Follow the Magento Installer Steps.
Your Magento2 Setup is ready.

http://< ip > /magento2/
http://< localhost >/magento2/

If you found error 500, please use /setup. For example.
http://< ip > /magento2/setup/
http://< localhost >/magento2/setup/

Step 4-:

Schedule Magento2 Cronjobs

Finally schedule the backgound cronjobs for your magento2 installation. These cronjobs does some activities like, re-indexing, Newsletters, Update of currency rates, sending automatic emails and generating sitemaps etc. To schedule these jobs edit crontab file

$ crontab -e

and add below cronjobs at the end of file and save it.

*/1 * * * * www-data php /var/www/html/magento2/bin/magento cron:run
*/1 * * * * www-data php /var/www/html/magento2/update/cron.php
*/1 * * * * www-data php /var/www/html/magento2/bin/magento setup:cron:run

Post a comment