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

WordPress on nginx + lighttpd + FastCGI + php

September 1, 2009 | linux, python, tools
author: Karol Zielinski | comments: 3 | views: 2784
Tags: , , , , , , ,

Sure, you can always install Apache. However… sometimes you can’t… for example: there could be some other web server installed on your port 80. There could be nginx for your python projects already installed (like in my case).

Yes, you can always install some python-based blog. Of course, you can. However… WordPress is the best, so why you should look for some other engine? My answer is: you shouldn’t.

I will describe how to install blog.karolzielinski.com on the server with nginx + lighttpd + FastCGI.

Update and install everything, what we need

update apt:

sudo apt-get update

install php-cgi:

sudo apt-get install php5-cgi php5-mysql

install lighttpd:

sudo apt-get install lighttpd

now remove lighttpd from startup since we will be using nginx:

sudo update-rc.d -f lighttpd remove

Create some useful scripts

create a bash script that will spawn the php fcgi handlers:

sudo vim /usr/bin/php-fastcgi

and add the following:

#!/bin/sh
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -f /usr/bin/php5-cgi

make the script executable:

sudo chmod +x /usr/bin/php-fastcgi

now lets create some script to start/stop/restart out php-fastcgi

sudo vim /etc/init.d/init-fastcgi

and add the following:

#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php
RETVAL=$?
;;
restart)
killall -9 php
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

make the script executable:

sudo chmod +x /etc/init.d/init-fastcgi

Configure nginx

edit fastcgi_params:

vim /etc/nginx/fastcgi_params

this file should looks like:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

and now lets configure our blog…

sudo vim /etc/nginx/sites-available/blog.karolzielinski.com

and add the following:


server {
    listen 80;
    server_name blog.karolzielinski.com www.blog.karolzielinski.com;

    allow all;

    location / {
        root   /var/www/blogs/blog.karolzielinski.com;  # absolute path to your WordPress installation
        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  /var/www/blogs/blog.karolzielinski.com$fastcgi_script_name;
    }
}

create symlink to our blog:

ln -s /etc/nginx/sites-available/blog.karolzielinski.com /etc/nginx/sites-enabled/blog.karolzielinski.com

WordPress stuff

download and unpack wordpress:

cd /var/www/
mkdir blogs
cd blogs/
wget http://wordpress.org/latest.zip
unzip latest.zip
mv wordpress/ blog.karolzielinski.com/

(…) and the end

run everything:

sudo /etc/init.d/nginx restart
sudo /etc/init.d/init-fastcgi start

now – everything should be fine.

You can check it by putting http://blog.karolzielinski.com in your browser’s address bar.

Bookmark and Share
Post WordPress on nginx + lighttpd + FastCGI + php to develway Post WordPress on nginx + lighttpd + FastCGI + php to Delicious Post WordPress on nginx + lighttpd + FastCGI + php to Digg Post WordPress on nginx + lighttpd + FastCGI + php to Facebook Post WordPress on nginx + lighttpd + FastCGI + php to Reddit Post WordPress on nginx + lighttpd + FastCGI + php to StumbleUpon

Related news and resources

Comments (3)

4Avatars v0.3.1 v0.3.1
I want to serve php via Php-fpm on my ubuntu
October 23, 2009, 4:53 am

[...] 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 [...]

4Avatars v0.3.1 v0.3.1
PHP via apache on the server with nginx and django
October 27, 2009, 4:21 am

[...] already described how to configure WordPress on nginx + lighttpd + FastCGI + php (via spawn-fcgi), as well as how to configure php-fpm on server with nginx. Now… I will try to describe [...]

4Avatars v0.3.1 v0.3.1
Krishna Kumar B.
May 11, 2010, 11:50 am

Nice article. I have a post on how to build a similar setup on Windows – http://krishnakumar.net/blog/2010/04/install-wordpress-welp/

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