In this guide, we’ll discuss how to configure server blocks in Nginx in centos 7.

Step 1 :Update Server

yum update -y

Step 2: Installing Nginx on CentOS 7

yum install epel-release -y

yum install nginx -y

systemctl start nginx

systemctl enable nginx

Check whether Nginx is running or not by visiting your server’s public IP address. Your page should look like this:

Step 3: Installing MySQL (MariaDB)

yum install mariadb-server mariadb -y

systemctl start mariadb

systemctl enable mariadb


Step 5: Installing PHP 5.6

To install PHP 5.6, you have to install and enable EPEL and Remi repository to your CentOS 7 system using the commands below.

yum install -y

yum install -y

yum install yum-utils -y

yum-config-manager --enable remi-php56 

yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo -y

yum install php-fpm  -y

systemctl enable php-fpm

systemctl start php-fpm

systemctl status php-fpm

Step 5: Configuring Nginx to work with PHP

Create a new Nginx configuration file by running nano text editor:

nano /etc/nginx/conf.d/

Then, insert this code:

server {
    listen   80;

    # note that these lines are originally from the "location /" block
    root   /var/www/;
    index index.php index.html index.htm;

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

    location ~ .php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

add new user and give password

useradd prabin

password prabin

create folders

 mkdir -p /var/www/
 chown -R prabin:prabin /var/www/
 chmod 755 /var/www/
 nano  /var/www/

then save the code


verify nginx configuration

nginx -t

Open PHP-FPM configuration:

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

Find and change these lines:

  • user = apache to user = nginx
  • group = apache to group = nginx
  • listen.owner = nobody to listen.owner = nginx
  • = nobody to = nginx
  1. After it’s done, change  

listen =


listen = /var/run/php-fpm/php-fpm.sock

  1. Save the file by hitting CTRL + X. Lastly, start PHP-FPM and enable it on boot:
systemctl restart php-fpm.service

systemctl enable php-fpm.service 

systemctl restart nginx

Done !!!!