The process is covered in quite a lot of good detail in the Ubuntu Documentation, but I’ve summarised the main steps below for those who just want to get up and running with the basics.
Apache
We can again use apt-get, this time to install Apache HTTP server. It’s version 2 which is available now, hence the command is:
sudo apt-get install apache2
The marvellous apt-get takes care of installing all dependancies too, so anything else we might need to run apache just gets added without us having to worry about it. Once the install process is finished, navigate to http://localhost and make sure that you can see the default Apache page.
To make the pages visible from other machines on the local network, you’ll need to edit /etc/apache2/sites-available/default. Find the line:
Allow from 127.0.0.0/255.0.0.0 ::1/128
and add the IP addresses of other local machines onto the end. Although all our PCs have static IP addresses, I used a wildcard so that things like my iPhone and visiting friend’s PCs can also access the server. I therefore changed the line from the above to:
Allow from 127.0.0.0/255.0.0.0 ::1/128 192.168.1.*
The pages served by default, in my case at least, were stored in /var/www. If you want to run more than one website through Apache, a guide on zaphu.com describes how to add a new site and activate it.
PHP
PHP is pretty easy to install:
sudo apt-get install php5
That’s it! The system will probably re-start Apache for you at the appropriate places, but if you want to check whether it’s successfully integrated PHP5 support into Apache, then running the following will give you an answer as to whether or not the relevant module has been enabled:
>sudo a2enmod php5
MySQL
To install MySQL, just run:
sudo apt-get install mysql-client mysql-server
During the setup procedure, you’ll be asked to choose a password for the ‘root’ account. Once that’s installed, ensure you’ve got support for MySQL in PHP:
sudo apt-get install php5-mysql
And finally, if you want a GUI admin tool, then MySQL Administrator does a fine job (although it seems to have been replaced by MySQL Workbench now, but I couldn’t find that using apt-get), or you can use PHPMyAdmin to do it in your browser:
sudo apt-get install mysql-admin sudo apt-get install phpmyadmin
If you want to check the server’s working OK, log in to it using the root account we set up during installation:
mysql -u root -p
Obviously the next thing you’ll do is set about creating a new user account and locking down the ‘root’ account, right? Good, I thought so.
WordPress
You can WordPress installation files and manually unpack them if you want, but I chose to install by checking out the latest stable version from the WordPress repository using Subversion. This will make it very easy to upgrade in future, by just ‘switching’ to the newest tag release. Note that this assumes you’ve already installed Subversion on your system – if not, please see my post detailing this first. Installing WordPress in this manner is something else that’s incredibly easy – just one command. Make sure you run this command from whatever directory you want WordPress to be installed into – apache2 sets the default web directory to be /var/www, so I’d suggest starting there. The command to checkout (“co”) a specific version of WordPress (3.1.3 in this case) is:
sudo svn co http://core.svn.wordpress.org/tags/3.1.3 .
Note the trailing full-stop, which specifies that the files should be checked out to the current directory. This whole process is discussed in more depth in the relevant page of the official WordPress.org documentation. Once you’ve installed the actual files, you’ll need to set up a database for WordPress to use. I’d include the command here but unfortunately each time I type it in, my WordPress installation thinks I’m trying a SQL injection attack and I get locked out of my own domain! There’s plenty of documentation out and about which covers this though. Set up a user for the blog too, which has the necessary permissions to work with the database you’ve created. Finally, copy wp-config-sample.php to a new file called wp-config.php and set up the values as required. You can view the site by navigating to http://localhost and answering a couple of questions to complete the installation, but don’t forget to change the “WordPress URL” in the settings screen to something like “http://myshinynewserver”, otherwise you may find that the site is served up with references to “localhost” in, instead of your server. After that, you should be good to go. Except, that is, if you’re afflicted by…
The WordPress Blank Screen of Death
I carried out all the steps above, but when I tried to view my shiny new blog, all I got was a blank page. The HTML source for the page was blank too. There are hundreds of different explanations, articles and blog posts which offer advice on how to rectify it. None of them worked for me. I did however, find that in my case there was a very simple solution. I enabled debugging in WordPress by adding the following line to wp-config.php:
define('WP_DEBUG', true);
This gave me the following message when I checked the subsequent output in /var/log/apache2/error.log:
[error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected ':' in /var/www/wp-config.php on line 25
Line 25 is the line which contains the password for the relevant MySQL database. All of my passwords are generated by the GRC Ultra High Security Password Generator, and include symbols. This didn’t pose any problems when I set up the user account with MySQL Administrator, but it did include a colon which was enough to completely confuse PHP. This was preventing the system connecting to the database and causing the blank screen of death. I amended the password so it didn’t contain a colon any more, and suddenly everything instantly worked again. Once you’ve found your error, don’t forget to turn debugging off again.