1, Install nginx, spawn-fcgi, php and mysql
#apt-get install nginx spawn-fcgi php5-cgi php5-mysql mysql-server-5.1
2, Configure nginx
#cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
#vi /etc/nginx/nginx.conf
user www www;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 1024;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
# mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/NginxImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities “TOP” “USER”;
# # imap_capabilities “IMAP4rev1″ “UIDPLUS”;
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
# }
#cp /etc/nginx/sites-available/default /etc/nginx/sites-available/thuhd.com
#rm -fr /etc/nginx/sites-enabled/default
#vi /etc/nginx/sites-available/thuhd.com
# You may add here your
# server {
# …
# }
# statements for each of your virtual hosts
server {
listen 80;
server_name www.thuhd.com thuhd.com 173.212.227.87;
access_log /var/log/nginx/thuhd.com.access.log;
location / {
root /var/www/thuhd.com;
try_files $uri $uri/ /index.php?q=$uri; #Rewrite rule for WordPress.
index index.php index.html index.htm;
}
#location /doc {
# root /usr/share;
# autoindex on;
# allow 127.0.0.1;
# deny all;
#}
#location /images {
# root /usr/share;
# autoindex on;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /var/www/nginx-default;
#}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/thuhd.com$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
#deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#listen 8000;
#listen somename:8080;
#server_name somename alias another.alias;
#location / {
#root html;
#index index.html index.htm;
#}
#}
# HTTPS server
#
#server {
#listen 443;
#server_name localhost;
#ssl on;
#ssl_certificate cert.pem;
#ssl_certificate_key cert.key;
#ssl_session_timeout 5m;
#ssl_protocols SSLv2 SSLv3 TLSv1;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#ssl_prefer_server_ciphers on;
#location / {
#root html;
#index index.html index.htm;
#}
#}
#ln -s /etc/nginx/sites-available/thuhd.com /etc/nginx/sites-enabled/thuhd.com
#/etc/init.d/nginx stop
#userdel www-data && useradd www
#vi /etc/passwd
……
www:x:1001:1001:,,,:/var/www:/bin/sh
……
#mkdir /var/www
#mkdir /var/www/thuhd.com
#vi /var/www/thuhd.com/index.php
<?php phpinfo(); ?>
#chown -R www:www /var/www
3, make spawn-fcgi automatically start
#cp /etc/rc.local /etc/rc.local/bak
#vi /etc/rc.local
……
if [ -x /usr/bin/spawn-fcgi ] ; then
/usr/bin/spawn-fcgi -f /usr/bin/php5-cgi -a 127.0.0.1 -p 9000 -C 3 -u www -g www
fi
exit 0
4, Compile eAccelerator and install it. Note that php5-dev can be removed when we’ve got eaccelerator.so
#apt-get install php5-dev build-essential
$wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
$bunzip2 eaccelerator-0.9.5.3.tar.bz2
$tar xvf eaccelerator-0.9.5.3.tar
$cd eaccelerator
$./configure
$make
#cp modules/eaccelerator.so /usr/lib/php5/20060613/
#mkdir /var/cache/eaccelerator
#chown -R www:www /var/cache/eaccelerator
#cp /etc/php5/cgi/php.ini /etc/php5/cgi/php.ini.bak
#vi /etc/php5/cgi/php.ini #add the following lines to the end.
…
sendmail_path = /usr/sbin/sendmail #enable PHP mail() function
…
[eAccelerator]
extension=”eaccelerator.so” #Without pathname
eaccelerator.shm_size=”16″
eaccelerator.cache_dir=”/var/cache/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
$php5-cgi -v #reboot and test if eaccelertor is loaded by php5-cgi
PHP 5.2.11-2 with Suhosin-Patch 0.9.7 (cgi-fcgi) (built: Nov 21 2009 22:59:34)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
5, Configure mysql
$mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.1.37-1ubuntu5 (Ubuntu)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> create database thuhd;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on thuhd to thuhd@localhost identified by ‘***’;
Query OK, 0 rows affected (0.02 sec)
mysql> exit
Bye