#1 Easy Nginx with PHP
Nginx is a great alternative to other webservers like Apache and Lighttpd. If you're looking for something with a bit less overhead and a bit more speed, give it a try.
We'll get Nginx compiled from source on Ubuntu 9.04 and get PHP playing nice with it.
Uploaded on Sep 23, 2009 | 11:43 | Tags: Nginx PHP
# install openssh-server
$ sudo apt-get install openssh-server
#install updates and tools
$ sudo apt-get update?
$ sudo apt-get upgrade?
$ sudo apt-get install build-essential
# install php
$ sudo apt-get install php5-cli php5-cgi
# get Nginx
$ wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz
# install dependancies for nginx
$ sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
# untar
$ tar -zxvf nginx-0.7.62.tar.gz
# configure
$ ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module
# make and make install
$ make
$ sudo make install
# start Nginx
$ sudo /usr/local/sbin/nginx
# PHP and FCGI
# install subversion
$ sudo apt-get install subversion
# check out spawn-fcgi
$ svn co svn://svn.lighttpd.net/spawn-fcgi/trunk spawn-fcgi
# install automake
$ sudo apt-get install automake
# configure and install
$ ./autogen.sh
$ sudo ./configure
$ make
$ sudo make install
# Nginx virtual hosts
$ sudo nano /usr/local/nginx/conf/nginx.con
# paste in nginx.conf, at the bottom, but before the find curly brace "}"
server {
listen 80;
server_name www.yourdomain.com;
if (!-e $request_filename) {
rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;
rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;
rewrite ^ /index.php last;
}
location / {
root /usr/local/nginx/html;
index index.html index.php index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
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_FILENAME /usr/local/nginx/html/$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;
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;
}
}
# start new PHP FastCGI instance
$ sudo spawn-fcgi -a 127.0.0.1 -p9000 -u www-data -f /usr/bin/php5-cgi
If you enjoyed this episode, be sure to check out the newest Technicast on Apache2. All purchases support FOSSCasts.





