... because from time to time I'm a web developer, too
About me
Projects
Contact
Links

I want to serve php via Php-fpm on my ubuntu

October 23, 2009 | linux, other, python
author: Karol Zielinski | comments: 4 | views: 3399
Tags: , , ,

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.

Install and configure php-fpm

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 ( and ).

all php-fpm patches are here

configure site in nginx

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:

Bookmark and Share
Post I want to serve php via Php-fpm on my ubuntu to develway Post I want to serve php via Php-fpm on my ubuntu to Delicious Post I want to serve php via Php-fpm on my ubuntu to Digg Post I want to serve php via Php-fpm on my ubuntu to Facebook Post I want to serve php via Php-fpm on my ubuntu to Reddit Post I want to serve php via Php-fpm on my ubuntu to StumbleUpon

Related news and resources

Comments (4)

4Avatars v0.3.1 v0.3.1
Allow short form of PHP’s open tag
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 [...]

4Avatars v0.3.1 v0.3.1
I want to serve php via Php-fpm on my ubuntu - develway.pl - wiadomości dla programistów, wiadomości IT, świeże linki ze świata IT
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 [...]

4Avatars v0.3.1 v0.3.1
Even Better « CAPITOLEF/FECT
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 ) [...]

Write a comment

Karol Zielinski :: Just a tech stuff 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.

Most popular posts

Much more links

Karol Zielinski    |   contact me
Gdynia, Poland
RSS - Just a tech stuff - python, java blog - web development blog Karol Zielinski on twitter Karol Zielinski on LinkedIn Karol Zielinski on facebook Karol Zielinski on delicious Karol Zielinski on digg Karol Zielinski on flickr Karol Zielinski on stumbleupon Karol Zielinski on technorati