WordPress with nginx, php-fpm, apc and varnish
Update and upgrade OS

apt-get update
apt-get upgrade

Add the required repo and add key

vi /etc/apt/sources.list
deb http://packages.dotdeb.org stable all
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | sudo apt-key add –
rm dotdeb.gpg
apt-get update

Install and configure nginx and php5-fpm

aptitude install nginx php5-fpm

vi /etc/nginx/conf.d/php5-fpm.conf

upstream php5-fpm-sock {
server unix:/var/run/php5-fpm.sock;
}

Create a wordpress site

vi /etc/nginx/sites-available/wordpress

server {
listen 80; # your server’s public IP address
server_name farhan.net; # your domain name
root /var/www/wordpress/; # absolute path to your WordPress installation

index index.php;

access_log /var/log/nginx/farhan.net-access_log;
error_log /var/log/nginx/farhan.net-error_log;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass php5-fpm-sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

Enable the wordpress site by creating a link and remove the default site:

ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/010-wordpress
rm /etc/nginx/sites-enabled/default

Download and extract the wordpress

mkdir -p /var/www
cd /var/www
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz

Install mysql and create mysql database and user:

aptitude install mysql-server php5-mysql

mysql -u root -p
CREATE DATABASE `wordpress`;
GRANT ALL PRIVILEGES ON `wordpress`.* TO ‘wordpress’@’localhost’ IDENTIFIED BY ‘SOMEREALLYSTRONGPASSWORD’;
FLUSH PRIVILEGES;
EXIT

Restart the services:

service nginx restart
service php5-fpm stop
service php5-fpm start

Install and configure varnish and php-apc

aptitude install php-apc varnish

vi /etc/php5/fpm/conf.d/apc.ini

apc.shm_size=100

vi /etc/default/varnish

START=yes

vi /etc/varnish/wordpress.vcl

backend default {
.host = “127.0.0.1″;
.port = “8080″;
}
acl purge {
“localhost”;
}

sub vcl_recv {
if (req.request == “PURGE”) {
if (!client.ip ~ purge) {
error 405 “Not allowed.”;
}
return(lookup);
}
if (req.url ~ “^/$”) {
unset req.http.cookie;
}
}
sub vcl_hit {
if (req.request == “PURGE”) {
set obj.ttl = 0s;
error 200 “Purged.”;
}
}
sub vcl_miss {
if (req.request == “PURGE”) {
error 404 “Not in cache.”;
}
if (!(req.url ~ “wp-(login|admin)”)) {
unset req.http.cookie;
}
if (req.url ~ “^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.|)$”) {
unset req.http.cookie;
set req.url = regsub(req.url, “\?.$”, “”);
}
if (req.url ~ “^/$”) {
unset req.http.cookie;
}
}
sub vcl_fetch {
if (req.url ~ “^/$”) {
unset beresp.http.set-cookie;
}
if (!(req.url ~ “wp-(login|admin)”)) {
unset beresp.http.set-cookie;
}
}

vi /etc/default/varnish

Set daemon options as below

DAEMON_OPTS=”-a YOUR.IP.ADDRESS.HERE:80 \
-T localhost:6082 \
-f /etc/varnish/wordpress.vcl \
-S /etc/varnish/secret \
-s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G”

service varnish restart

Install memcache

aptitude install memcached php5-memcache

Verify by adding a host entry

10.28.79.164 farhan.net

http://farhan.net

Advertisements