Below are the steps I took to configure nginx and php5 on my Ubuntu 8.10 server. I choose nginx because its lightweight and relatively easy to manage once you figure out the configuration. I’ve been using Apache for years and its second nature at this point, however, on my small VPS server I needed to maximize my resources.
Make sure your system is updated:
sudo aptitude update && sudo aptitude safe-upgrade
Install nginx and PHP5, we’ll be installing the cgi version of php.
sudo aptitude install nginx php5-cgi
Download the following php-fastcgi startup script and save it to /etc/init.d/php-fastcgi. Nginx will use php in cgi-mode which is why we are creating a init file for it. (note: I found this init script on a mailing list someplace)
Download: php-fastcgi init script
Next, run the following commands on the php-fastcgi script.
sudo chmod u+x /etc/init.d/php-fastcgi
sudo chown 0.0 /etc/init.d/php-fastcgi
sudo update-rc.d php-fastcgi defaults 21 23
Now, go ahead and create your directory that will store your website. For example you might do the following:
mkdir -p /home/username/domains/yourdomaincom/{public_html,log,cgi-bin}
Modify the /etc/nginx/nginx.conf file and set the following variable. I have mine set to 15MB but if you wish to allow larger files to be uploaded over http set this accordingly.
client_max_body_size 15m;
Finally, lets setup a virtual domain. Navigate to the /etc/nginx/sites-available directory and create a file called yourdomain.com (replace with your domain) and use the following as a template. Make sure to replace your paths etc.
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
access_log /home/username/domains/yourdomain.com/log/access.log;
location / {
root /home/username/domains/yourdomain.com/public_html;
index index.html index.htm index.php;
}
# 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 /home/username/domains/yourdomain.com/public_html$fastcgi_script_name;
include fastcgi_params;
}
}
Like apache, nginx has a sites-available and sites-enabled folder this allows for better control of active/disabled virtual domains. Navigate to the /etc/nginx/sites-enabled folder and create a symlink back to your virtual host’s configuration.
cd /etc/nginx/sites-enabled/ && sudo ln -s ../sites-available/yourdomain.com
Finally, lets start everything up.
/etc/init.d/php-fastcgi start
/etc/init.d/nginx start
At this point you should be able to browse to your site using your domain name. You can easily duplicate multiple domains by creating new virtual host files and creating the sym link as noted above, remember that ngix will need to be restarted.
Not nginux, NGINX!
Dmitry Shirokov
2 Dec 08 at 1:20 am
Fixed thanks!
Ryan
2 Dec 08 at 5:35 am
[...] Install nginx w/ php5 on Ubuntu 8.10 | moxiefoxtrot [...]
Install nginx w/ php5 on Ubuntu 8.10 | moxiefoxtrot | availabl.com
2 Dec 08 at 5:56 am
[...] some great how-tos (not only on nginx) and helpful people in their forums, and my friend, Ryan, has a helpful post as [...]
Matthew Helmke (dot) Net » Blog Archive » A short how-to for switching from Apache to nginx
8 Jan 09 at 11:44 am
Will this work if I use the above info for UBUNTU 8.04 Hardy???
FDA
12 Jan 09 at 11:53 am
I don’t see why not
Ryan
12 Jan 09 at 8:16 pm
The directory you made is missing a dot:
mkdir -p /home/username/domains/yourdomaincom/{public_html,log,cgi-bin}
should be
mkdir -p /home/username/domains/yourdomain.com/{public_html,log,cgi-bin}
Taking note, just for consistency.
Nik
6 May 09 at 8:39 pm
Is there a list of software which will work on nginx???
medicin
25 Jun 09 at 3:21 am
bugs fixed
canada low cost
14 Aug 09 at 6:41 am
I need a list of software too …
cigaretter
22 Sep 09 at 10:28 am
Iam too
cialis canadian pharmacy
1 Mar 10 at 4:51 am