How to install and configure php7 , nginx on centos 7

How to install nginx in centos 7

Update your server

yum update

Add epel repo as nginx is not available in Default repo

yum install epel-release

Install nginx

yum install nginx

Start the nginx services

systemctl start nginx

Enable the nginx so that when ever server restart , it should automatically start

systemctl enable nginx

Test your domain

lynx localhost

install php7 with Nginx, Installing php71



Download and install additional centos repo

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm

or

yum localinstall http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Install

rpm -Uvh remi-release-7.rpm

Enable the remi repository

yum install yum-utils -y

yum-config-manager --enable remi-php71

Installing php71 , php-common and php-fpm (php-fpm is compulsory to install with nginx)

yum --enablerepo=remi,remi-php71 install php-fpm php-common

Installing the needed and most common modules

yum --enablerepo=remi,remi-php71 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

In order to run php with nginx, one needs to configure and establish the nginx and php connection so that they can communicate with each other.

Configuring php7 with nginx



Install vim editor 

yum install vim

How to run php-fpm on socket

Edit default.conf file

vim /etc/nginx/conf.d/default.conf

##Copy this syntax in your configuration file

server {
listen 80;
server_name techouse.co.in;
root /usr/share/nginx/html;
index index.html index.htm index.php;
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;
}
}

Restart Nginx web server

systemctl restart nginx

Edit php-fpm file

vim /etc/php-fpm/www.conf

Comment

;user = apache
;group = nginx
;listen = 127.0.0.1:9000

And add

user = nginx
group = nginx
listen = /var/run/php-fpm/php-fpm.sock

Now start the php-fpm services

systemctl start php-fpm.service

Enable the php-fpm so that it can automatically start on reboot

systemctl enable php-fpm.service

Thank You , for any query comment below.
How to install and configure php7 , nginx on centos 7 1

 

techouse

I love helping beautiful people like you. I love hanging out with my dogs.

You may also like...

1 Response

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

× How can I help you?