Linux Tutorials Others

Setup and configure NGINX with PHP-FPM ( PHP FastCGI Process Manager ) in CentOS 7 / RHEL 7

main_image_nginx_php_fpm

install PHP and PHP-FPM.
# install from EPEL

yum install epel-release

yum nginx install php php-mbstring php-pear php-fpm

Screen Shot 2016-10-14 at 8.57.51 PM Screen Shot 2016-10-14 at 9.07.55 PM Screen Shot 2016-10-14 at 9.08.04 PM

Configure PHP-FPM and Nginx.

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

Screen Shot 2016-10-14 at 9.08.39 PM
line 39: change user apache to nginx

user = nginx

line 41: change group apache to nginx

group = nginx

guess_linux_nginx_php_fpm6

start and enable php-fpm

systemctl start php-fpm
systemctl enable php-fpm

guess_linux_nginx_php_fpm6

configure nginx

vi /etc/nginx/nginx.conf

guess_linux_nginx_php_fpm7
add following line after root /usr/share/nginx/html; which is on line no 42, so that nginx can read index.php

index index.php index.html index.htm;

# add into “server” section

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
fastcgi_index index.php;
}

guess_linux_nginx_php_fpm5

restart and enable nginx server

systemctl restart nginx
systemctl enable nginx

guess_linux_nginx_php_fpm1
Create a test page to make sure PHP script works normally.

echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php

guess_linux_nginx_php_fpm3

Testing

open your server ip address in browser and you will get the result

guess_linux_nginx_php_fpm4

Thank you.

13 Comments

Leave a Comment