Install Nginx/PHP-FPM on Fedora 29/28, CentOS/RHEL 7.5/6.10 - Comment Page: 6
This is guide howto install Nginx with PHP 7.2.12 and PHP-FPM on Fedora 29/28/27, CentOS 7.5/6.10 and Red Hat (RHEL) 7.5/6.10. 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 Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.
1. Install Nginx, PHP 7.2.12 and PHP-FPM on Fedora 29/28/27, CentOS 7.5/6.10, Red Hat (RHEL) 7.5/6.10
[inttf_post_ad1]
1.1 Change to root...
getting error on fedora 17 repo
http://nginx.org/packages/centos/17/x86_64/repodata/repomd.xml: [Errno 14] curl#22 – “The requested URL returned error: 404 Not Found”
Trying other mirror.
Error: failure: repodata/repomd.xml from nginx: [Errno 256] No more mirrors to try.
Hi bob,
There is not nginx own repo for Fedora (as this guide says, it’s only for CentOS and Red Hat), please remove that repo file and use just yum.
Dear fried,
I have follow your instructions in CENTOS 6.5 and i have install nginx ok but the php it was 5.3.3 ?!?
Is there something wrong with the remi repo ??
Hi Dimitrios,
Did you enabled remi and remi-php55 repos? Like:
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?
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.
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;
with
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
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.
my mistake, i dropped repo files in new server. That is why it giving that error
thanks a lot
Thanks a lot.
Thanks for the Share . Good Work
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?
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
/srv/www/xyz.com/public_html
/srv/www/xyz.com/logs
3. Create Virtualhost /etc/nginx/sites-available/xyz.com:
4. “Enable” your virtualhost
5. Restart (or reload) your nginx service
6. Open firewall port
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???
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?
https://www.mirrorcreator.com/files/8VRQRYVC/vs.zip_links
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.
Thanks for the post!!!
How to make it work with PHP 7
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
epel is now on the following URL: http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm, you have http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-7.noarch.rpm in content which brings up 404 error now.
What if I have 2 sites that I am hosting. One is at /siteName, and that’s the php site. The other is /. / is on 4040 and /siteName is on 8080?
Hi Eric,
You can use VirtualHosts and set both listen different ports or different host names, example
Virtual host 1:
server {
...
listen 8080;
...
}
Virtual host 2:
server {
...
listen 4040;
...
}
Maybe better setup is use server_name directive, like:
Virtual host 1:
server {
...
server_name site1.localhost;
...
}
Virtual host 2:
server {
...
server_name site2.localhost;
...
}