I want to serve php via Php-fpm on my ubuntu
October 23, 2009 | linux, other, pythonauthor: Karol Zielinski | comments: 4 | views: 3399
Tags: fastcgi, nginx, php, php-fpm
My plan is to have one server for my python and php applications. I already wrote about configuring nginx + apache for django applications. As well as configuring WordPress on nginx + lighttpd + FastCGI + php (via spawn-fcgi). Today I will to present how to serve my php applications via php-fpm.
Let’s go to work…
I will use latest version of PHP – 5.2.11.
I assume that you have nginx installed and configured.
cd /usr/local/src wget http://pl2.php.net/get/php-5.2.11.tar.gz/from/pl.php.net/mirror tar zxvf php-5.2.11.tar.gz wget http://php-fpm.org/downloads/php-5.2.11-fpm-0.5.13.diff.gz gzip -cd php-5.2.11-fpm-0.5.13.diff.gz | patch -d php-5.2.11 -p1 cd php-5.2.11 ./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysql-sock --with-gd --without-sqlite --disable-pdo --disable-reflection make all install strip /usr/local/bin/php-cgi
now change user and group of your php-fpm processess
/usr/local/etc/php-fpm.conf
and change lines 63 and 66 to www-data (
cd /etc/nginx/sites-available/ vim my-php-site.com
and add there:
server {
listen OUR_IP:80;
server_name www.my-php-site.com;
rewrite ^(.*) http://my-php-site.com permanent;
}
server {
listen OUR_IP:80;
server_name my-php-site.com;
error_log /var/log/nginx/my-php-site-nginx.error.log;
access_log /var/log/nginx/my-php-site-nginx.access.log;
allow all;
location / {
root /opt/php-projects/my-php-site.com;
index index.php index.html index.htm;
# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d;
break;
}
# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/php-projects/my-php-site.com$fastcgi_script_name;
}
}
how should /etc/nginx/fastcgi_params looks like I described earlier.
now add this site to nginx’s site-enabled:
ln -s /etc/nginx/sites-available/my-php-site.com /etc/nginx/sites-enabled/
and at least:
php-fpm start /etc/init.d/nginx restart
Everything should be fine.
Check it in your web browser, as well as by…
ps -aux
Good luck!
More informations:
Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.
November 26, 2009, 4:25 am
[...] I moved from php on apache + nginx to php-fpm + nginx and I forgot about short form of PHP’s open tag. I did some reasearch and… what I had [...]
December 3, 2009, 7:00 am
[...] tech.karolzielinski.com Follow us on Twitter 1,510 śledzących RSS Feed 162 czytelników I want to serve php via Php-fpm on my ubuntu 1 głosuj! My plan is to have one server for my python and php applications. I already [...]
January 6, 2010, 3:04 am
[...] http://tech.karolzielinski.com/i-want-to-serve-php-via-php-fpm-on-my-ubuntu Filed under: Jumble Leave a comment Comments (0) Trackbacks (0) ( subscribe to comments on this post ) [...]
January 8, 2010, 7:15 pm
[...] http://tech.karolzielinski.com/i-want-to-serve-php-via-php-fpm-on-my-ubuntu [...]