Update: Setting up WordPress on Ubuntu Server — Step by Step

I switched my hosting environment from dasBlog + IIS on Windows to WordPress + LAMP on Linux a few days ago and everything seemed to have gone pretty smoothly so far. Contrary to most Windows users’ belief, setting up a Linux hosting environment is no more difficult than doing the same on Windows. In fact, in many areas, it is a lot simpler. Since the information on a complete environment setup is somewhat sketchy on the Internet, I will share my own experience with you and hopefully you will find this article helpful. Choice of Distro Given the number of distros out there, it might be a bit overwhelming in choosing a distro for running as a server. Well the choice of distros is mainly a personal preference issue, my favorites have always been OpenSUSE, Ubuntu and FreeBSD. Both OpenSUSE and Ubuntu are well supported and regularly updated. And I also like FreeBSD for it’s simplicity. For my server, I chose Ubuntu Server. One thing nice about Ubuntu Server is that it’s footprint is relatively small and the installation is extremely streamlined. In fact, LAMP installation came as an option so after the installation you will have a LAMP server up and running. But if you are intimidated by Linux shell commands and prefer a GUI environment, you might want to go for the regular Ubuntu/Kbuntu or OpenSUSE or whatever your favorite distro instead. If you are going for a system with X Windows enabled, you might need to beef up the spec a bit since more disk space and RAM will be needed. Server Hardware Another advantage of running a Linux server is that the hardware requirement is relatively low. Just to give you an idea, my previous environment (dasBlog + IIS) runs on a 3GHz Pentium 4 HT machine with 2GB of RAM, but for my Linux server I chose to use one of my older machines (1GHz Pentium 3 with 512MB RAM) instead. Server Installation (Ubuntu Server 7.04) The whole process is very simple, just be sure to select LAMP server towards the end and everything should be set. It seems that Ubuntu Server 7.04 has some display issues when you boot into it. For whatever reason, it did not calculate the screen size correctly and the login prompt would be cut off from the bottom of the screen. It would seem like the system had hung, but you can just press enter key a couple of times to get the login prompt. This is a little bit of annoying but since most of the administration would be done remotely via SSH, this behavior did not bother me that much. Post-installation configurations

1. The first thing you should do after the server install is to get all the security updates:

sudo apt-get update
sudo apt-get dist-upgrade

It will take a few minutes before all the updates are installed, obviously depending on your network and computer speed. This will ensure that your Ubuntu server installation is up-to-date. It is a good idea to reboot after finished installing the security updates. 2. Installing SSH In order to remotely administrate the server, you will need SSH installed.

sudo apt-get install ssh

Afterwards you should be able to ssh into your server from a Windows client using utilities such as PuTTY.

And after SSH is configured, the server can run in a headless mode (without keyboard or monitor) 2. Configure Samba: If once a while you need to browse the server from a Windows machine, installing Samba is a good idea. Note that this is not a necessary step in configuring the server.

sudo apt-get install samba

To use Samba, you will need to set up a share and a user. the configuration file is located at /etc/samba/smb.conf. Add a section towards the end:

[{Server Name}]
path = /
valid users = {user name}
read only = No	create mask = 0755
directory mask = 0755

Now we can add a user for Samba share:

sudo smbpasswd –a kwong

Install WordPress On WordPress’s website, there are some pretty good instructions on how to install WordPress. Never the less, a couple of things were not very clear there so I will give my own steps here.

1. Get the latest version of WordPress

wget http://wordpress.org/latest.tar.gz

wget should have been installed during the Ubuntu server setup. If for whatever reason wget is not available, you can installed by typing

apt-get install wget

Unzip it in your home directory:

tar -xzvf latest.tar.gz

And then you can move it to your www root folder. It is always a good idea to install WordPress in its own folder instead of in the root folder of www (later I will show you how you can configure it so that your blog can be accessed by using http://yourdomain/).

cd /var/wwwmv /home/{user name}/wordpress ./blog

Install phpMyAdmin Even though the WordPress MySQL database can be configured using mysql command line, I found it a lot easier using phpMyAdmin. Plus, you can use this powerful web based SQL tool later for database maintenance.

sudo apt-get install phpMyAdmin

After phpMyAdmin is installed, you should be able to login via a browser via the url: http://{server name}/phpMyAdmin/ The very first time, you should use user root with no password to log in. Because the default installation of MySQL gives you root access without needing any password, the first thing you should do is to add passwords to all root accounts. This can be accomplished easily with phpMyAdmin. Now we will configure a database for WordPress to use (more details here):

1. Enter the database name (e.g. wordpress) in the create new database field and click create. 2. Add a dedicated database user and configure appropriate user privileges for wordpress (e.g. user wordpress)

Now we need to change our wp-config file accordingly:

mv /var/www/blog/wp-config-sample.php /var/www/blog/wp-config.php

Edit the content of wp-config.php:

define('DB_NAME', 'wordpress');    // The name of the database
define('DB_USER', 'username');     // Your MySQL username
define('DB_PASSWORD', 'password'); // ...and password
define('DB_HOST', 'localhost');

Since our WordPress installation is located in the blog directory, the default url will be http://yourdomain/blog/. If you want your blog to be accessible from the root (e.g. http://yourdomain/) you will need to modify /var/www/blog/index.php: First copy it to www root:

cp /var/www/blog/index.php /var/www/

And change the require() line to point to the new path: Now we run the setup script:


After running the installation script, we want to make sure that our blog is pointed at the correct location. go to http://yourdomain/blog/wp-adming/, select options. In General Options section, you will see one line like “WordPress address (URL)” and another line like “Blog address (URL)”. This is the place where you specify how your blog main url looks to the outside world. If you want your blog to appear as http://yourdomain/ then make sure WordPress address is pointed to http://yourdomain/blog and Blog address is pointed to http://yourdomain. If you want your blog to appear as http://yourdomain/blog/ then make sure both entries are the same (http://yourdomain/blog/) Now the installation of WordPress is complete. Tweaking WordPress There are many useful settings you can experiment with after your WordPress installation is working. Also, there are many very useful plug-ins you might want to use with your blog.

1. URL Rewrite

To configure URL rewrite, you will need to install the rewrite module for the Apache server:

sudo a2enmod rewrite/etc/init.d/apache2 force-reload
sudo apache2ctl restart

Then go to wp-admin and choose your desired rewrite scheme under Options->PermaLinks. After you enabled url rewrite, you will have to modify the configuration file /etc/apache2/apache2.conf by adding the following sections at the end: <IfModule mod_rewrite.c> RewriteEngine On </IfModule> <Directory /var/www/> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </Directory>

And if you are migrating from an existing blog engine, it is also a good idea to provide rewrite for the old URL’s to point to the new ones. For example, if I want to redirect feeds from SyndicationService.asmx (used by dasBlog) to /feed (used by WordPress), I would add a line after the RewriteBase and before the first RewriteCond line like follows:

RewriteRule ^SyndicationService.asmx /feed/ [R,L,NC]

2. Install Mono module

If you want to host ASP.Net applications, you will need to add the mono module:

sudo apt-get install libapache2-mod-monosudo
sudo apt-get install mono-apache-server2
sudo a2enmod mod_mono

And add the following sections to your /etc/apache2/apache2.conf configuration file: <IfModule mod_mono.c> Alias /dotnet “{where the directory for aspx pages is}” MonoApplications “/dotnet:{where the directory for aspx pages is}” <Directory {where the directory for aspx pages is}> SetHandler mono <IfModule mod_dir.c> DirectoryIndex Default.aspx </IfModule> </Directory> <Location /dotnet> SetHandler mono </Location> </IfModule>

You will need to reload the apache2 daemon by running /etc/init.d/apache2 force-reload

3. Install Admin Plugins

There are a few plugins that I found quite usful:

wp-syntax: a syntax highlighter for many different languages.

StatTraq: a plugin that tracks vital site statistics.

Be Sociable, Share!