Few days back PHP version 7.0 has been released. Which has number of changes and improvements over PHP version 5.X. This article will help you to install PHP 7, NGINX and MySQL 5.6 on CentOS / RHEL 7.1 & 6.7 operating systems. This tutorial has been tested with CentOS 7.1, so all the services command are used with systemctl, For CentOS 6 users change all systemctl command correspondence service command.

Step 1. Setup Yum Repository

In the first step install all the required yum repositories in your system used in remaining tutorial for various installations. You are adding REMI, EPEL, Webtatic & MySQL community server repositories in your system.

CentOS / RHEL 7

# yum install epel-release
# rpm -Uvh
# rpm -Uvh
# rpm -Uvh

CentOS / RHEL 6

# yum install epel-release
# rpm -Uvh
# rpm -Uvh
# rpm -Uvh

Step 2. Install PHP 7

Now install php 7 packages from webtatic rpm repository using following command.

# yum install php70w

Now install required php modules. Use following command to list available modules in yum repositories.

# yum search php70w

Now check all listed modules in above command and install required modules like below.

# yum install php70w-mysql php70w-xml php70w-soap php70w-xmlrpc
# yum install php70w-mbstring php70w-json php70w-gd php70w-mcrypt

Step 3. Install NGINX

NGINX is the popular web server used on Linux systems. Let’s install Nginx web server using following command on your system.

# yum install nginx

Now start nginx service and enable to start on boot using below commands.

# systemctl enable nginx.service
# systemctl start nginx.service

Step 4. Install MySQL 5.6

In step 1 we already have installed required yum repository in your system. Lets use following command to install MySQL server on your system.

# yum install mysql-server

You need to execute mysql_secure_installation once after installation of MySQL server using following command. First it will prompt to set a password for root account, after that ask few questions, I suggest to say yes ( y ) for all.

# systemctl start mysqld.service
# mysql_secure_installation

Now restart MySQL service and enable to start on system boot.

# systemctl restart mysqld.service
# systemctl enable mysqld.service

See more How To Install MySQL on CentOS 7

Step 5 — Setup PHP-FPM

Now use following command to install php7 fpm package using following command.

# yum install php70w-fpm

Step 6 — Create Nginx VirtualHost

Finally do the configuration of Nginx VirtualHost. For this example we are editing default configuration file.

$ sudo nano /etc/nginx/conf.d/example.conf

and make changes as below.

server {
        listen   80;

        root /var/www;
        index index.php index.html index.htm;

        location / {
                try_files $uri $uri/ /index.html;

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;

        location ~ .php$ {
                try_files $uri =404;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

You have to do the same changes in all Virtual Hosts configured.

Step 7 – Restart Services

After installing all services on your system, start all required services.

# systemctl restart nginx.service
# systemctl restart php-fpm.service

Step 8. Open Port in Firewall

Finally open firewall ports for http (80) and https (443) services using following command.

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

Step 9. Verify Setup

Let’s check the installed versions of packages on system using following commands one by one.

# php -v

PHP 7.0.2 (cli) (built: Jan  9 2016 14:00:11) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
# nginx -v

nginx version: nginx/1.6.3

Finally verify installation of PHP 7 with NGINX. Let’s create a file index.php on website document root using following content.


Now browse this file in web browser. It will so all the details about version’s and installation.


You have successfully configured LEMP Stack setup on your CentOS / RHEL 7.1 & 6.7 system.


Update php

If you have installed php in lower version, you can rm the outdated version:

yum remove php* php-common

If you don’t care the newest php version, you can use default version. See How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7

centos nginx bind() to failed (13: Permission denied)

nginx: no permission to bind port 8090 but it binds to 80 and 8080 - Server Fault


2014/01/10 09:20:02 [emerg] 30181#0: bind() to failed (13: Permission denied)

This will most likely be related to SELinux

semanage port -l | grep http_port_t
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000

As you can see from the output above with SELinux in enforcing mode http is only allowed to bind to the listed ports. The solution is to add the ports you want to bind on to the list

semanage port -a -t http_port_t -p tcp 8090

will add port 8090 to the list.

如果出现 semanage command not found错误就执行

yum -y install policycoreutils-python

See semanage command not found on CentOS 7 and RHEL 7

SElinux error :ValueError: Port tcp/5000 already defined

httpd - SElinux error :ValueError: Port tcp/5000 already defined - Server Fault

On the systems I have to hand (C6, C7 and F24), tcp port 5000 has an SELinux context of commplex_port_t. This will be why, when you try to add it you get the error message

/usr/sbin/semanage: Port tcp/5000 already defined

To change the context of tcp port 5000 from commplex_port_t to http_port_t you will need to use the -m | –modify switch

-m, --modify Modify a OBJECT record NAME


semanage port -m -t http_port_t -p tcp 5000

should do what you want

semanage port -l | grep 5000
http_port_t tcp 5000, 80, 81, 443, 488, 8008, 8009, 8443, 9000

ERROR 1396 (HY000): Operation CREATE USER failed for ‘xxx’@’localhost’

yes this bug is there. However, I found a small workaround.

  • Assume the user is there, so drop the user
  • After deleting the user, there is need to flush the mysql privileges
  • Now create the user.

That should solve it. Assuming we want to create the user admin @ localhost, these would be the commands:

drop user admin@localhost;
flush privileges;
create user admin@localhost identified by '_admins_password_'

See mysql - ERROR 1396 (HY000): Operation CREATE USER failed for ‘jack’@’localhost’ - Stack Overflow