Skip to content

Month: January 2009

Drupal 6 Site Builder Solutions

Those of you who read this blog regularly know that I like Drupal. I use WordPress on this site and think it is fabulous, but for sites that want to do more to connect with readers or customers, I think Drupal is one of the easiest and most powerful solutions out there for creating a quality site with as little difficulty and pain as possible. I personally administer three sites built on Drupal and have built others.

I am in the process of making a new site for someone with a nice looking, but aging site that was built on Drupal 4.7, which is no longer supported. I am looking through the site’s functionality and theme and have upgraded both to use Drupal 5, but only to be sure that it has current security updates while I make plans with the owner for a complete redesign.

While researching ideas and functionality to present for use in the new site, I ran across a brand new book from Packt Press called Drupal 6 Site Builder Solutions that I found enjoyable, and very useful. Now, I already know what I am doing with Drupal. I know how to read the project’s documentation to find and configure modules and themes, and I know how to get help if I need it. Even so, this book gave me some great ideas that I am going to share with the owner of the site I am working on and that I hope to use.

The entire book centers around creating a website for a fictional company, The Good Eatin’ Bistro. You start out with a discussion of the basic needs for the company, then begin with the basics of creating a site suitable to the customer’s needs. As the book progresses, you learn how to use some well-known and some other less-known modules to add interesting and useful functionality to the site that makes information easy to find and interesting to view.

Do you want a site that allows all members of a project you are involved in to have individual blogs, with a calendar to display events, and a map? No problem. Have a restaruant and want to put your menu online in a way that looks good, and is easily changed. Easy. Are you interested in creating a newsletter that people viewing your site can sign up to recieve occasionally? You can. All this and a ton more are in the book.

I think one of the most useful parts of the book for most people will be the last chapter, which talks about how to find out how to add functionality not discussed in the book, where to get help, and has some great tips on things that not everyone thinks about like hosting, hardware, and working with developers and artists.

One thing that crossed my mind is sharing the book with the owner of the site I mentioned. He won’t understand the technical details, but this book is written in a way that I believe will make what I am doing very clear and make it much easier for him to talk with me about his hopes, plans and desires. For that reason alone, the book is valuable to me, and it might be to others as well who are not actually interested in creating a site themselves, but who need to know enough detail to be able to discuss site building intelligently with a developer, designer or team of people working to create a site for them.

The book does not cover theming, but focuses solely on enabling features, enabling and configuring new functionality to a site built on Drupal 6. If you are interested in theming Drupal 6, I recommend a book I reviewed last month on the topic.

An interview with PartyBoi2

It has been a little while since we last had an installment of our interview series. With the new year fully begun and things moving back into a regular schedule, I think it is time we continue the introductions.

Today we get to hear from Karl, known in the forums as PartyBoi2. In the last two years, he has racked up over 3000 posts and helped tons of new users, attempting to focus on posts that have gone entirely unanswered as well as helping beginners with their adaptation issues.

1. Tell as much as you’re willing about your “real life” like name, age, gender, location, family, religion, profession, education, hobbies, etc.

Hi everyone, my  name is Karl and I’m a 34 male who in 2000 decided to leave my family and friends looking for greener pastures so to speak and migrated to Melbourne Australia from New Zealand. I have had a interesting last 8 years in Melbourne where I worked in the hospitality industry and unfortunately made a few wrong choices and ended up with drug and alcohol addictions which nearly cost me my life. In 2006 I quit my job due to my deteriorated health and put my trust and faith back in  Jesus and saw amazing things happen including freedom from the drugs and alcohol.

I don’t have any title or letters before my name and have had an average education and probably see myself as the ‘run of the mill’ type of guy who has learned most things by trial and error and experience. Currently I am doing some study and are hoping to start a new career in the IT industry as a Technician, with the possibility of starting a small computer business with some friends geared towards assisting underprivileged people.

2. When and how did you become interested in computers? in Linux? in Ubuntu?

When I was younger I use to  play the odd game on my friends Amiga computers but was a bit of a late bloomer I would say, as I did not take a real interest in them till a few years ago, even though I  got my first computer running win 98 around 1998.

In 2007 I was looking for an alternative to windows, as windows was out of my price range at the time and I needed a operating system so I could communicate with my family back in New Zealand. I had heard about linux many moons ago and thought that since I had plenty of spare time I would teach myself Linux. I had a look at a couple of different flavors of Linux but was unsuccessful at installing them, probably due to the fact I was a newbie and did not know what I was doing. Most of my searching for a Linux flavor came from searching www.linux.org  and since I had been unsuccessful up to that point of being able to install any I started to check out the forums and support for each Linux distribution that interested me and found that Ubuntu had a large active forum with plenty of Documentation. So I took the plunge and successfully installed my first Linux operating system which was Dapper 6.06 and launched myself into learning about the Ubuntu operating system.

As my interest in Ubuntu grew so did my interest in computers in general and before I knew it I had friends calling on me to fix their computers when ever things went wrong, which was a wonderful learning experience for me and encouraged me to learn more.

3. When did you become involved in the forums? What’s your role there?

I started using  the Ubuntu forums in about June 2007 even though I had signed up with the Ubuntu Forums in January of that year. At first I mostly read different threads in the Absolute Beginners section reading and learning about the different types of problems people were having then finally one day dived in and started replying to some of the posts.

I think my role really is just being part of the Ubuntu forum community like so many others and doing what we enjoy which is assisting others and helping out where we can. Generally I reply to posts that have not been answered and would  say that “Installation and Upgrades” is where I post the most and enjoy helping out the newbies.

4. Are you an Ubuntu member? If so, how do you contribute? If not, do you plan on becoming one?

No, I currently am not a member, its not something that I have really thought to much about to be honest, but maybe down the track once I have contributed more it maybe something that I would consider.

5. What distros do you regularly use? What software? What’s your favorite application? Your least favorite?

Ubuntu is my number one distro at the moment , I have installed a few others like dsl and gentoo using virtualbox but have not really spent much time using them. Might look at other distros more once I get a bigger hard drive.

My favorite application would probably have to be deluge p2p program. I don’t think I have a least favorite applications but if I had to choose one, Evolution would probably be the closest as I have always preferred Thunderbird and never really got accustomed to it.
The main software that I use is the gnome-terminal, Thunderbird, Xchat Vlc, Nano and Firefox.

6. What’s your fondest memory from the forums, or from Ubuntu overall? What’s your worst?

My fondest memories have been when I have helped people get the answer to their question, and knowing the relief they feel when they can finally stop banging their head against the wall. Some of the other fondest memories would be the different types of people I have encountered on the forums and the eagerness they have to help others out. I don’t have any worst memories really the closest I would say would be when I replied to a thread and another poster told the original poster to ignore what I had posted and do it their way. As I have said I have not really had any bad experiences and generally I have a very good impression of the forums and the active members.

7. What luck have you had introducing new computer users to Ubuntu?

For awhile I did some voluntary work refurbishing computers for the underprivileged which also became a good opportunity to promote Ubuntu, when I first started they were sending out computers with windows on only, after awhile I started installing Xubuntu on a lot of the computers and they also started getting sent out and I was able to inform the people I work with more about Ubuntu as well as giving out a few Ubuntu disks.
Not long ago there was  someone who stumbled into ##beginners-help on network irc.freenode.net who was trying to connect to another server who had never heard of Ubuntu, after talking with them they downloaded and tried Ubuntu, so I guess I have had some success at introducing people to Ubuntu and I am sure there will be plenty more opportunity’s  to promote Ubuntu.

8. What would you like to see happen with Linux in the future? with Ubuntu?

I would like to see people’s awareness increased about Linux and Ubuntu and see more computers sold with the option to have Ubuntu come already installed.
Also to see some of the things that hold back Linux improved like games and drivers etc.

9. If there was one thing you could tell all new Ubuntu users, what would it be?

Breathe, don’t stress, it takes time to learn a new operating system. The forums are a great place to get help and remember that no question is stupid and that everyone was a newbie at some stage.

There is also the ubuntu wiki pages that can be helpful as well as irc ##beginners-help on network irc.freenode.net or #ubuntu on network irc.freenode.net

Getting started with Arduino

I love Make magazine. It captures the excitement and joy of tinkering, experimenting, and modifying things for fun. This is an experience I have had over and over through the years, beginning in my early childhood. I was that one kid that always took all of his toys apart, usually putting them back together with “improvements.”

I have learned so much from doing things this way, probably more than I have learned from books. I am a book lover, but more than that, I am a tinkerer. I’m never content with knowing theory, I have to get my hands dirty and experiment, often before I bother to learn the theory.

It is this very personality trait that caused me to enjoy a book I read this week, Getting Started with Arduino. The book is published by O’Reilly as part of their Make: Projects series. There is also an accompanying website dedicated to the project.

The book begins with a description of Arduino. This is an open source electronics prototyping platform designed for experimentation and learning. It was originally begun as a way to teach designers how to build prototypes of the projects they are designing, along with simple embedded software development. It turns out that is is a really fun-sounding hobbyist platform, too. I’ll get to the “fun-sounding” bit shortly.

The book is written in a way that an interested, but completely inexperienced person should be able to pick it up and read it, comprehend it, and begin to use the platform. I think that is possible. The text gives a clear and easy introduction to electronics without bogging down the casual newcomer in the details. In the long term, you would certainly want to study in greater depth from other resources, but for a person just looking to get started actually doing something, this book is ideal. It describes the Arduino hardware, gives an introduction to programming that is easy to follow and should allow any reader to play along with comprehension.

This is where I was unsatisfied: the software IDE and hardware drivers are easy to install and run on Windows and MacOSX, but not on Linux. There is a link in the book to a page that gives details of how to install on Linux, but it is more complicated and may turn some potential users off of the idea. I know that it’s ironic for a tinkerer to not want to tinker, but remember, the target audience is people who love to get their hands dirty without knowing or having to figure out the details in advance. There are links on that page to instructions for installation in various Linux distributions, but all that I checked were at least one release out of date. As I write this, I’m running the 64 bit version of Ubuntu 8.10, but the most recent Ubuntu instructions were for 8.04. Could I figure it out? Of course, but these missing details are disappointing.

My final evaluation is that the project looks like a lot of fun, and the book really is an enjoyable read. I can think of several uses for the hardware without even trying and it would probably be a blast to play around with. I will watch the project and hope to see the usability and interactability with Linux made/kept more up to date. When that happens, I’m in. In the meanwhile, you will probably find me at the electronics surplus/reclamation shop or the swap meet and garage sales for looking for my potential victims, I mean, experimentation platforms.

Mastering phpMyAdmin 2.11

I am the sole person responsible for seven websites that use MySQL databases, and have worked on the back end of several others. Over the years I have worked on these databases in many different ways. I’ve done it from the command line, via ssh. I’ve done it using PHP scripts within the software being run on a site. I have also used phpMyAdmin. Each method has applications and moments where I would prefer using it to the others at my disposal.

I have generally used phpMyAdmin only in those moments when I had something quick and simple to do, or when a hosting company did not provide ssh or command line access. This was mainly because I did not realize how powerful and flexible the software can be.

I just read a book called Mastering phpMyAdmin 2.11.

I didn’t realize how amazingly easy it is to configure this program, and how much you can do with phpMyAdmin. The book starts with the basic foundation of installation and initial configuration, then walks you through the steps of using it in your unique setting. The author makes a note of default settings as well as some that are likely preset to other options by web hosting providers. It clearly outlines how to change those defaults if you are using the software on a server you own or control.

Mastering phpMyAdmin is clearly written, using easy to comprehend examples, with a chapter structure that begins without the need for previous knowledge and takes you to uses and procedures that are far beyond the needs of most of us. That’s cool! It is always my preference to have more information at my disposal than I am likely to need, rather than the other way around. With this book, I can’t imagine needing to look up any other documentation source to figure out how to create, manipulate, check, repair, backup, restore, optimize, or otherwise interact with a MySQL database.

It is my opinion that this book would be very helpful to people who are completely new to database and website administration, who perhaps already have access to phpMyAdmin through their web hosting provider through cPanel or Plesk, or have the permissions on the server to install it themselves. As an intermediate (definitely not guru-level) admin, I found the book a helpful and enjoyable way to discover new uses for the software as well as new ways to configure it to remove limitations I had previously encountered, such as only being able to import sql files smaller than 2 Mb. If that sounds interesting, take a look at the book info on the publisher’s website or persue a copy at your local bookstore.

Ubuntu 8.10 magazine

I wrote several articles, and co-wrote one with a friend, Ryan Troy, for the Ubuntu 8.10 edition of Linux Identity. I even got to write the editorial at the beginning of the issue.

I received my copy today. The issue should be available on newsstands soon. It includes two installation DVDs, one 32 bit and one 64 bit. The issue will give a good introduction to Ubuntu for your friends and coworkers, even those with little technical skill, knowledge or experience.

Nowhere Else to Turn

My second book (written solo, not as a cowriter) appeared on Amazon this morning. The cover still hasn’t appeared on the site, but hopefully it will soon along with “search within this book” capability.

From the back cover: “There are things that happen in the world that are difficult and sometimes impossible to explain. At times, we are confronted with circumstances or situations over which we have no control. How we deal with those situations reveals much about our strongest beliefs, our dreams, and our fears. This collection of short stories explores specific instances of involvement with or belief in the supernatural in one North African country. The tales, all claiming to be true, were collected over several years while the author was living in Morocco.”

Readers will discover stories about fortune tellers, sorcery, jinn (genies) and more.

If you are interested, take a look here: http://www.amazon.com/Nowhere-Else-Turn-Matthew-Helmke/dp/0615264190/

Ubuntu and Open Office get shout outs in the acknowledgements, since I did all the writing and layout using them exclusively.

One url Apache-style 301 redirects in nginx

Note: this post is outdated. Use at your own risk.

In Apache, you can create an .htaccess file to house 301 Redirect statements, or you can do it in the main config file. It is easy, and common. To change the url that appears in a client browser, as well as tell it where to find something that is no longer located in an original place, you would write something like this for :

Redirect 301 /original_location/

where is where the client is looking for the file, but would not find it, and is what you want used when the original is requested as well as in the future.

Easy, right?

I searched and searched for good documentation on how to do this with nginx. I found great documentation for doing it with a regex, such as this sample code you could put in your site-specific vhost file at /etc/nginx/sites-available/mysampledomain.com for forcing browsers to use the domain name without www.

server {
listen 80;
server_name www.mysampledomain.com;
rewrite ^/(.*) permanent;
}

What I couldn’t find was a simple way to do static redirects, like in my sample above. So, tonight I did some experimenting and figured it out. I hope this helps someone else. Put something like this in your /etc/nginx/sites-available/mysampledomain.com file, in the main server section (see second example following this one).

location /original_location/ {
rewrite /original_location/ permanent;
}

That would fit in a file like the one I used in my previous post like this.

server {
listen 80;
server_name www.matthewhelmke.net;
rewrite ^/(.*) http://matthewhelmke.net/$1 permanent;
}

server {
listen 80;
server_name matthewhelmke.net;

access_log /home/myusername/public_html/matthewhelmke.net/log/access.log;
error_log /home/myusername/public_html/matthewhelmke.net/log/error.log;

location /original_location/ {
rewrite /original_location/ permanent;
}

location / {
root /home/myusername/public_html/matthewhelmke.net/public;
index index.html index.htm index.php;

# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d;
break;
}

# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}

}

# 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/myusername/public_html/matthewhelmke.net/public$fastcgi_script_name;
include fastcgi_params;
}
}

Have fun! You now have one less reason to give why a person shouldn’t use ngnix instead of Apache.

A short how-to for switching from Apache to nginx

Note: this post is outdated. Use at your own risk.

I am running my sites on a VPS from Slicehost and have had a very good experience. When I started, I set everything up using Apache 2, since that is what I am most familiar and adept with using. Apache works well, but likes more memory than I have in my server. This caused me to use my swap far too much.

I worked with the Apache configuration, finally coming up with the changes below for my /etc/apache2/apache2.conf file, which minimized the swapping, but wasn’t quite enough for me to be happy. Also, if more than one or two people were browsing the site at a time, it forced everything to go much more slowly, because it now got backed up in a queue instead of being served quickly (this was by design, to save memory and prevent swapping). That was not acceptable. Here you can see the changes I had made to get it to run without swapping all the time in a lean-memory environment. I have removed everything but the necessary changes I had made, just to save space here. Apache is so well documented, you should be able to figure the file out as needed using readily available info, if you need to.

Timeout 30
KeepAlive On
MaxMemFree 262144
MaxKeepAliveRequests 2
KeepAliveTimeout 1
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 1
MaxSpareServers 3
MaxClients 4
MaxRequestsPerChild 5
</IfModule>
<IfModule mpm_worker_module>
StartServers 2
MaxClients 5
MinSpareThreads 2
MaxSpareThreads 5
ThreadsPerChild 2
MaxRequestsPerChild 3
</IfModule>
HostnameLookups Off

I did some reading and decided to try nginx as a replacement for httpd. The Slicehost folks also have some great how-tos (not only on nginx) and helpful people in their forums, and my friend, Ryan, has a helpful post as well.

There are lots of how-tos around for installing from scratch on a server. Most are good. I am focusing on migrating from Apache2 to nginx. For that, I will assume you have your site set up and running on Apache, your DNS is set properly and pointing to the server, etc.

First, make sure your system is up to date, especially with all security updates. Then, install nginx, either from source or from your Linux distribution’s package repositories. I chose the latter. You also want to install the cgi version of php5. On my Ubuntu 8.10 server, I did this:

sudo aptitude update && sudo aptitude safe-upgrade

followed by:

sudo aptitude install nginx php5-cgi

I made a couple of modifications to my /etc/nginx/nginx.conf file. Here is what I have. My server has two dual core processors, hence the 4 worker processes. I lowered the keep-alive timeout, added the gzip config, and made a couple more simple changes.

user www-data;
worker_processes 4;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log;

sendfile on;
tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 3;
tcp_nodelay off;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
application/xml+rss text/javascript;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

After that, I used the php-fastcgi script I found here and put it in /etc/init.d/php-fastcgi.

#! /bin/sh
### BEGIN INIT INFO
# Provides:          php-fastcgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description:       Start and stop php-cgi in external FASTCGI mode
### END INIT INFO

# Author: Kurt Zankl <kz@xon.uni.cc>

# Do NOT "set -e"

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="php-cgi in external FASTCGI mode"
NAME=php-fastcgi
DAEMON=/usr/bin/php-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# If the daemon is not enabled, give the user a warning and then exit,
# unless we are stopping the daemon
if [ "$START" != "yes" -a "$1" != "stop" ]; then
log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes"
exit 0
fi

# Process configuration
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT"

do_start()
{
# Return
#   0 if daemon has been started
#   1 if daemon was already running
#   2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- $DAEMON_ARGS || return 2
}

do_stop()
{
# Return
#   0 if daemon has been stopped
#   1 if daemon was already stopped
#   2 if daemon could not be stopped
#   other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null # --name $DAEMON
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently.  A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac

Then, I set the ownership and permissions appropriately.

sudo chmod u+x /etc/init.d/php-fastcgi

and

sudo chown 0.0 /etc/init.d/php-fastcgi

and set it to run at boot

sudo update-rc.d php-fastcgi defaults 21 23

Most how-to articles tell you here to create the directories to hold your website(s). Since I am doing this on a site that was already running Apache, my sites already existed in /home/myusername/public_html/sitename/public. Note where yours is, because you will need that info.

Ngnix works similarly to Apache for multiple domains. With each you can set up more than one domain on an IP address using virtual domains. If you only have one domain, the setup is easier, but outside the scope of this article. Apache2 puts the sites in directories in /etc/apache2/sites-available for setup, with symbolic links to there for active sites from /etc/apache2/sites-enabled. Nginx can do the same, using /etc/nginx/sites-available and /etc/nginx/sites-enabled.

Make a virtual host (vhost) file for each domain/site you plan to use in /etc/nginx/sites-available. Here’s a sample, based on this domain, but with sensitive info changed:

/etc/nginx/sites-available/matthewhelmke.net

server {
listen  80;
server_name  www.matthewhelmke.net;
rewrite ^/(.*) http://matthewhelmke.net/$1 permanent;
}

server {
listen  80;
server_name  matthewhelmke.net;

access_log  /home/myusername/public_html/matthewhelmke.net/log/access.log;
error_log   /home/myusername/public_html/matthewhelmke.net/log/error.log;

location / {
root   /home/myusername/public_html/matthewhelmke.net/public;
index  index.html index.htm index.php;

# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d;
break;
}

# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}

}

# 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/myusername/public_html/matthewhelmke.net/public$fastcgi_script_name;
include fastcgi_params;
}
}

The first server section rewrites all requests for the domain that use www in front to the same url without the www. The second server section is where all the fun happens. Both are listening on port 80, the standard for http. The second tells nginx where to put the log files (in a special log directory I created for each domain, in each domain’s directory in my /home directory).

The location section is especially important. It tells where to find the root directory for my site, in my case, in a special directory called public. Then, I have two special rewrites. These allow you to use permalinks aka clean urls aka pretty urls aka SEO urls with your site. Once these lines are in the vhost file, you will discover that both WordPress and Drupal allow you to adjust the settings in their admin panels to use them as you would like. I haven’t tried it with other types of content management systems, but I think it would probably work. Without these lines, you have to use the standard url formats.

The other incredibly important bit is that last section. It tells nginx to send all php files to the fastcgi script to be interpreted. Without this, you won’t get php to work.

Once you get your vhost file set up, create a link to it from the sites-enabled directory so that nginx will know to use it.

cd /etc/nginx/sites-enabled/ && sudo ln -s ../sites-available/yourdomain.com

Then, to test it out, start the fast-cgi script, turn off Apache, and start nginx.

/etc/init.d/php-fastcgi start

/etc/init.d/apache2 stop

/etc/init.d/nginx start

If everything is set correctly, you should now be able to view your site using nginx. If it isn’t, you can always stop nginx and start apache2 again to keep your site up while you try to figure out the problem. Once it is up, tested thoroughly, and you are happy, you can remove Apache if you like.

Note: I had some trouble with the fast-cgi script at first, having copied one that had special characters put in it. That happens sometimes when you post code with WordPress. I’m trying to prevent it here by using code tags, but they reset any time there is a blank line, so you may need to cut/paste in sections. If you have problems, and all you did was cut & paste, look at this first as the likely cause.