I recently decided to setup a Debian box on @rackspace (very happy with RackSpace so far) to power my WordPress site. I did some searching for a Debian 6 (squeeze) setup guide using lighttpd and WordPress with php5 and MySQL. I found lots of fragmented posts and posts assuming you were familiar with Linux (and assuming you wanted to use Apache). I was about out of ideas until I remembered I had a resource outside of the interwebs!
He helped me get Debian up, Lighttpd installed, MySQL installed and configured and then finally get WordPress installed. We rounded the build out with a lovely firewall to ensure my box isn’t a crazy relay or something.
Step 1 – Fire up a new Debian build
Now, once you have the connection to the console setup you can proceed (I did not connect through the web console provided by RackSpace, I use iTerm2 to SSH into the server… Use your root credentials and a ssh app of choice, it make things much easier!). Use rackspace’s documentation to find out how to build your first server and get to the console.
On the console we are first going to update and upgrade the component the basic build comes with:
Next, I wanted to know what came in the build from RackSpace, so I ran the following:
This returned a list of everything installed, you will notice (if on RackSpace) you dont have apache or many other services we will need installed by default. This is okay. Lighttpd and PHP are easy to stand up.
Step Two – Install the goods
aptitude install lighttpd
aptitude install php5-cgi php5-gd mysql-server mysql-client php5-mysql
Those commands above download and install Lighttpd, php5 and mysql. We need different components to handle Wordpress, so this is why we specify what we do. You may notice (or maybe not if you are a noob like me) that we dont do a blanket php5 get. The reason why is because the php5 get will install apache, which we dont want.
During the install of MySQL you will see some screen that look like this:
Make sure to use your root password (well, you dont have to, it makes things easier…) And then confirm it:
Now that install is done it’s time to configure!
Step Three – Configure Lighttpd
We will run the following command to enable features:
We will enable the following:
(enter them one at a time and hit enter after each). Now that those are enabled we will need to restart the Lighttpd server:
service lighttpd restart
Now if we navigate to our public IP address we should see the default Lighttpd directory listing, yahoo!!!
Lets now make sure it is up and running and returning all of our PHP stuff. To do this we are going to create a new php file and put it in the default location for our site.
This will create a new file in the var/ww folder and call it index. It will also open the file once it is doen creating it. We are going to modify this file to show the php info from the server. enter the following on the first line of the index.php file that should be open.
<?php phpinfo(); ?>
Next, hit control O and control X to save and close the file. (Reminder: I did not do this through the web console provided by RackSpace, I use iTerm2 to SSH into the server… Use your root credentials and ssh app of choice).
Now if you refresh your site, you should get an error. yea… I taught you to get errors, so that we can figure out what they ar ein the future and fix them Let’s open the defualt log location for lighttpd errors:
It looks like we need to enable mod_rewrite. Let’s do that now. the command below will open the configuration for Lighttpd. From within this file we can enable mod_rewrite.
It should look like this to start:
Remove the # on the mod_rewrite line and then add “mod_fastcgi”, on the line after mod_rewrite. Confirm your syntax matches the other components above. Save and close the file (control O and control X). Now we need to restart Lighttpd again and confirm the new index.php page loads.
service lighttpd restart
Next we have to setup the vhost file. This is how our server knows where to direct traffic it receives on port 80. How to configure a vhost file is personal preference and I chose a way that made most sense to Ben and I. to open the files run:
Update the record so it looks like this (if you want to match our config). Make sure to change the www.example.com entry to your domain name. This only needs to house one domain name, it will parse multiple domains. So, pick your primary domain and enter that as the default-host.
You may also notice we changed the server root and the document root. By changing these, all we have to do is create a new folder in the www folder with our domain name, add in a public_html folder and then all content can go in there. For example this URL is setup like so (this has WordPress in the folder which yours wont have yet):
Now, lets make these directories I showed you above.
Now that we have our directory setup and vhost file pointing to the domain name, let’s clean up the file we used to confirm everything was working
Now that the first file is gone, let’s confirm our domain name is loading properly. To do this, we will need to create a new file in the public_html folder we created in the steps above:
Lets add in the following content to make sure this is in fact loading our new file:
oh hi <?php phpinfo(); ?>
Save and close once your code in the index.php file matches the code above. Dont forget, Control O and Control X is how we do this. And finally, we need to restart Lighttpd again so it refreshes the vhost file configuration.
service lighttpd restart
If you go to your domain name, you should see the new page with the oh hai verbiage and the php info on it! Congrats, you have a working Debian 6 squeeze server running Lighttpd web services configured for php5 and mySQL. You have also configured the vhost file to handle multiple domains or sub domains. Click on over to Part 2 to get to the Word Press install and configuration.