PHP-FPM and NGINX
+
Par Remi le lundi 27 septembre 2010, 19:14 - HowTo - Lien permanent
Since PHP 5.3.3, the PHP-FPM engine is bundled. The php-fpm package is available in remi repository and will be soon in rawhide.
This entry show how to use it with the nginx web server.
My goal is to install a working web server, for local and packaged (RPM) applications, I will use phpMyAdmin as an example.
1. Installation :
yum --enablerepo=remi install php-fpm nginx phpMyAdmin
This command will also install the apache web server, listening on port 80. I will not use it, but I will configure nginx to listen on port 82.
2. Creating my web site
With nginx, pages are, by default, installed in the /usr/share/nginx/html directory.
My application will be very minimal:
echo '<?php phpinfo(); ?>' >/usr/share/nginx/html/nginfo.php
3. Nginx configuration
I'm really not an expert on this web server, but, reading the documentation (quite minimal), I found a working solution:
Change in the /etc/nginx/nginx.conf file.
Port :
listen 82;
Alias for phpMyAdmin (after the commented section about PHP)
location /phpMyAdmin { alias /usr/share/phpMyAdmin; index index.php index.html index.htm; }
PHP Configuration for phpMyAdmin
location ~ /phpMyAdmin/.*\.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/$uri; fastcgi_intercept_errors on; include fastcgi_params; }
PHP configuration for my local application
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; include fastcgi_params; }
This is probably not the simplest / best solution (I'd like to not have to configure php twice), your comments are welcome, I will try to improve it.
4. Launch the services
service php-fpm start
service nginx start
5. Test URL
- http://localhost:82/ the default provided by nginx home page
- http://localhost:82/nginfo.php my great application
- http://localhost:82/phpMyAdmin/ a packaged application
6. Conclusion
It works !
Commentaires
Hello Remi,
Thanks for the helpful tutorial,
I checked fpm package on Fedora 13 repos, and didn't find it there, despite the fact fedora have upgraded to php 5.3.3. fedora is not including php-fpm package.
Any idea why? and/or would it be at all possible to just install remi's fpm rpm package instead all of remi's php packages?
Thanks!
php-fpm is not "yet" in fedora repository. (But it will first lands in rawhide, and I don't know if I will push it as an update to F-14 or F-13)
For now, you must install "all" php* rpm from my repo, but, globally there are the same than in official repository (except some additional extensions, like sqlite and oci8).
+
Dear Remi!
Thank you very much for the great work you're doing!
I got one question about php-fpm and php from your repo. You claim that it "Since PHP 5.3.3, the PHP-FPM engine is bundled". But here is the situation:
php-5.3.3-1.fc14.remi.i686
php-fpm-5.3.3-1.fc14.remi.i686
nginx-0.8.53-2.fc14.i686 (from official fedora repo)
and php -i | grep -i fpm says nothing.
So nothing works if try to follow your instructions (or just manuals). Is there anything wrong with php-fpm in this build?
Thank you very much in advance!
php command is the CLI Sapi.
the FPM Sapi is in the php-fpm command.
So, try
+
P.S. and, please, use the forums which are a better place for question / help.
Another entry : Installing Nginx With PHP5 (And PHP-FPM) And MySQL Support On Fedora 15