moxiefoxtrot

…a random blog about life and technology

Archive for the ‘nginx’ tag

Install nginx w/ php5 on Ubuntu 8.10

11 comments

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.

Written by Ryan

December 1st, 2008 at 3:47 pm

Posted in Articles & Reviews, Ubuntu

Tagged with , , ,

Hosting with slicehost

2 comments

I decided to move my blog and a couple other websites I maintain to an Ubuntu 8.10 based VPS/slice at slicehost.net. For various reasons the shared hosting provider I was using wasn’t fitting my needs, specifically there was downtime and performance issues.

I choose to start with slicehost’s “256 slice” which gave me 256BM ram, 10GB storage and 100GB of monthly transfer. I opted to install Ubuntu 8.10, although there are other Linux flavors available. The install took about 5 minutes and Slicehost’s control panel allows me to rebuild my slice anytime, view stats, login to a console and much more.

Since I choose to start with the smaller 256 slice I needed to make sure I wasn’t going to max out my resources since I need to have specific applications installed to maintain my blog. I decided to go with nginx as a replacement for apache2, mysql5, php5 and postfix to handle sending mail.

It’s only been a couple days since I made the switch and so far slicehost is really working out for me.

Edit: I stumbled on Slicehost when researching Linux HA for work. Slicehost has a nice write up on using HA with multiple slices. :)

Written by Ryan

November 30th, 2008 at 8:19 pm

Posted in General

Tagged with , , ,