Wordpress on nginx + lighttpd + FastCGI + php
September 1, 2009 | linux, python, toolsauthor: Karol Zielinski | comments: 2 | views: 1419
Tags: blog, fastcgi, lighttpd, nginx, php, python, ubuntu, wordpress
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 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 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
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
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/
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.
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.
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 [...]
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 [...]