Magento-2 Step-by-Step Installation process in CENTOS-7
Step 1 : Install nginx
yum -y install epel-release
yum -y install nginx
systemctl start nginx
systemctl enable nginx
netstat -plntu
Step 2 : Install and Configure PHP-FPM
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php70w-fpm php70w-mcrypt php70w-curl php70w-cli php70w-mysql php70w-gd php70w-
xsl php70w-json php70w-intl php70w-pear php70w-devel php70w-mbstring php70w-zip php70w-soap
PHP Configuration Changes:
vim /etc/php.ini
Uncomment the cgi.fix_pathinfo and change value to 0 & other values also.
cgi.fix_pathinfo=0
memory_limit = 512M
max_execution_time = 1800
zlib.output_compression = On
session.save_path = "/var/lib/php/session"
vim /etc/php-fpm.d/www.conf
PHP-FPM7 will run under the 'nginx' change the value to 'nginx' for the user and group lines.
user = nginx
group = nginx
listen = /var/run/php/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Finally, uncomment the below attributes in PHP-FPM ( lines 366-370.)
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
Create a new directory for session path.
mkdir -p /var/lib/php/session/
chown -R nginx:nginx /var/lib/php/session/
Create a new directory for php-fpm socket file location.
mkdir -p /run/php/
chown -R nginx:nginx /run/php/
PHP-FPM7 configuration is complete, start the daemon now
systemctl start php-fpm
systemctl enable php-fpm
netstat -pl | grep php-fpm.sock
STEP 3 : Install MySQL 5.7 Server
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Now install MySQL 5.7 from the MySQL repository with the yum command below.
yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
MySQL 5.7 has been installed with a default root password. it is stored in the mysqld.log file.
grep 'temporary' /var/log/mysqld.log
Connect to the mysql shell with user root and default password.
mysql -u root -p
TYPE DEFAULT PASSWORD
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Magento123@';
flush privileges;
create database magentodb;
create user magentouser@localhost identified by 'Magento123@';
grant all privileges on magentodb.* to magentouser@localhost identified by 'Magento123@';
flush privileges;
Step 4 : Install and Configure Magento
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
Check the composer version as shown below.
composer -v
Go to the '/var/www' directory and download the Magento code with the wget command.
cd /var/www/
wget https://github.com/magento/magento2/archive/2.1.zip
Extract Magento code and rename the directory to 'magento2' directory.(yum install unzip)
unzip 2.1.zip
mv magento2-2.1 magento2
Install PHP Dependencies
Go to the magento2 directory and install all Magento dependencies with the composer command.
cd magento2
composer install -v
Wait for PHP Dependency installation to finish.
Configure Magento Virtual Host
Go to the Nginx directory and create a new virtual host configuration file named 'magento.conf' in the
'conf.d' directory.
cd /etc/nginx/
vim conf.d/magento.conf
Paste the virtual host configuration below.
upstream fastcgi_backend {
server unix:/run/php/php-fpm.sock;
}
server {
listen 80;
server_name 13.233.126.167;
set $MAGE_ROOT /var/www/magento2;
set $MAGE_MODE developer;
include /var/www/magento2/nginx.conf.sample;
}
nginx -t
systemctl restart nginx
Install Magento 2.1
Go to the magento2 directory to install Magento on the command line.
cd /var/www/magento2
Run the command below, make sure you have correct configuration. The values that need to be changed by
you are explained below.
bin/magento setup:install --backend-frontname="adminlogin" \
--key="biY8vdWx4w8KV5Q59380Fejy36l6ssUb" \
--db-host="localhost" \
--db-name="magentodb" \
--db-user="magentouser" \
--db-password="Magento123@" \
--language="en_US" \
--currency="USD" \
--timezone="America/New_York" \
--use-rewrites=1 \
--use-secure=0 \
--base-url="http://13.233.126.167" \
--base-url-secure="https://13.233.126.167" \
--admin-user=adminuser \
--admin-password=admin123@ \
[email protected] \
--admin-firstname=admin \
--admin-lastname=user \
--cleanup-database
Change value for:
--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 'magentouser'
--db-password: database password 'Magento123@'
--base-url: Magento URL
--admin-user: Your admin user
--admin-password: Your Magento admin password
--admin-email: Your email address
Magento 2.1 is installed. Run the command below to change the permission for the etc directory and change
the owner of the magento2 directory to the 'nginx' user.
chmod 700 /var/www/magento2/app/etc
chown -R nginx:nginx /var/www/magento2
Configure Magento Cron
This cronjob is needed for the Magento indexer. Create a new cronjob as 'nginx' user (because magento
running under nginx user and group).
crontab -u nginx -e
* * * * * /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