If Not True Then False

Install Nginx/PHP-FPM on Fedora 26/25, CentOS/RHEL 7.3/6.9 - Comment Page: 6

This is guide howto install Nginx with PHP 7.1.7 and PHP-FPM on Fedora 26/25/24, CentOS 7.3/6.9 and Red Hat (RHEL) 7.3/6.9. PHP-FPM is easier to use and configure than FastCGI and some tests says that PHP-FPM is even much more efficient than FastCGI. Nginx (engine x) is a robust, small and high performance http server, reverse proxy server and also mail proxy server. PHP-FPM (FastCGI Process...


Leave a Comment

Your email address will not be published. Required fields are marked *

Input your comment.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Input your name.


Hi JR,

Thanks for the post. I am new to the web server world, may I raise a question?
Does php-fpm works with apache? What did you choose nginx?

reply Reply

Hi dpdh,

You are welcome.

PHP-FPM works with Apache 2.4.x using mod_proxy_fcgi module. Then you don’t need suphp, suexec or mod_php.

If you want run PHP with nginx, then PHP-FPM is only reasonable option. Nginx is much lighter and powerful web server than Apache so that’s why this guide exists.

reply Reply
Alexander Filatov

Since you explicitly set the document root in the server clause, you can simplify the following line in the testsite.local virtual host file:
fastcgi_param SCRIPT_FILENAME /srv/www/testsite.local/public_html$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

reply Reply

Hi JR,

I need help when i goto install php-fpm it give me

gpg key retrieval failed errno 14 could not open/read file ///etc/pki/rpm-gpg/rpm-gpg-key-remi

How to install it. It Fresh Server.

reply Reply

my mistake, i dropped repo files in new server. That is why it giving that error

reply Reply

I am unable to understand that testsite.local. i am using a vps from ovh. where i need to use my server ipv4 ? and if my domain is xyz.com and ip is xxx.xxx.xxx.xxx then how i can config my virtual host file? where is virtual host located?

reply Reply

Hi bdspice,

This testsite.local is just an example which works on localhost if you don’t have real domain. Same setup works for real domain, but you don’t have to do any changes on /etc/hosts file.

If you have domain xyz.com, then setup is almost same, you have to of course replace directory names and change dns records to point right place and open port 80 on firewall.

Please read guide, but here is quick steps:

1. Point your domain xyz.com dns records to your ip.

2. Create directories like

3. Create Virtualhost /etc/nginx/sites-available/xyz.com:

server {
    server_name xyz.com;
    access_log /srv/www/xyz.com/logs/access.log;
    error_log /srv/www/xyz.com/logs/error.log;
    root /srv/www/xyz.com/public_html;
    location / {
        index index.html index.htm index.php;
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/xyz.com/public_html$fastcgi_script_name;

4. “Enable” your virtualhost

cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/xyz.com

5. Restart (or reload) your nginx service

systemctl restart nginx.service

## OR ##

service nginx restart

6. Open firewall port

reply Reply

Its working but i have face another big problem.i install nginx,mariadb,php-fpm,phpmyadmin.i config my domain (faceur.com) successfully. i try to install a laraval based script (ninja media script).but its show storage/session folder permission problem.then i changed whole www folder group and permission.but then i am not able to get it work and i quit.then i try to work a simple php based script.But its showing all php code as text on browser.Do i need to install apache also to run a php based script???

reply Reply

No, you don’t need Apache. PHP-FPM is enough to run php scripts.

This might be some configuration error. Could you post full code of your simple script which is not working?

reply Reply

here is the link of my script.i think there is some problem in configuration.Now in server,the ninja media script is up.but i cant run it.while its a working script. i try the same script on same server on webmin.but webmin use more ram that i cant effort.if you want config files.just tell me which config files you need.i will provide you soon.

reply Reply

Hai JR
Great tutorial. You just might want to add, that it might be necessary to edit [i]/etc/php-fpm.d/www.conf[/i] in case of a 502 Bad Gateway error.

It should listen to the same values as you give for fastcgi_pass in the available site config :)

– UltraG33k

reply Reply