Setting up WordPress on Ubuntu Server — Step by Step

I wrote a tutorial on how to setup WordPress on Ubuntu Server back in 2007. While the setup steps have largely remained the same from version 6.10 to 8.04 (both are long term support LTS versions), I decided to create an other guide focusing on the setup processes with Ubuntu Server 8.04. The setup steps are actually a bit easier in 8.04 as Samba has been fully integrated into the initial setup process. I have also included some screen shots from the text-mode Ubuntu Server setup so that newbies would find the task of setting up the server less daunting.

1. Ubuntu Server Setup

The following screen shots are taken while installing Ubuntu Server 8.04 (note the latest Ubuntu Server Edition is 8.04.2)

While the default choice is Yes (Detect keyboard layout), I have found that that for the keyboards used here in the US, skipping the auto-detection step is actually easier.

This is the host name you want to use. For whatever reason, the default Ubuntu Server setting does not set the host-name correctly using DHCP (for instance, you can not use vm-wordpress to locate the server from a Windows machine). This can be addressed easily by ensuring that the following lines are present in /etc/dhcp3/dhclient.conf:

send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, host-name, ntp-servers;

For a dedicated server, the default partitioning scheme (use entire disk) should be suffice.

If you are setting it up on your home computer, this is usually blank.

For the WordPress server setup LAMP and OpenSSH are the only required components. However, I usually add the Print Server (CUPS) so that the whole home network can share the printer on the WordPress server (since it is always on) and Samba File Server so that I can copy files from a Windows machine.

Don’t confuse MySQL root user password with the Ubuntu login password. They can be the same but it is recommended that you use a different strong password for each.

We are almost done!

If everything goes well, you should be greeted with this login screen after your machine is re-booted.

As a best practice, you should always ensure that your distribution is up-to-date by getting the latest patches/software:

This can be achieved by issuing the following commands upon log in:

sudo apt-get update
sudo apt-get dst-upgrade

A reboot maybe necessary if kernel image is updated.

2. Create Samba Share

We have already installed Samba during the Ubuntu Server install. To use it we need to first configure it properly.

sudo vi /etc/samba/smb.conf

at the end add the following section:

[{Samba Share Name}]
path=/
valid users= {User Name}
read only = no
create mask = 0666
directory mask = 0777

Now we can add a user for Samba share:

sudo smbpasswd -a {user name}
sudo /etc/init.d/samba restart

After Samba is configured, you should be able to see it via smb://vm-wordpress/sambaroot/ (using the user name and password you just added) in Linux or \\vm-wordpress\sambaroot\ in Windows.

3. Install WordPress

In your user directory (e.g. /home/{user name}):

wget http://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
sudo mv ./wordpress/ /var/www/blog

4. Configure Database

mysql -u root -p

mysql> create database wordpress;
mysql> grant all privileges on wordpress.* to "wpuser"@"localhost" identified by "password";
mysql> flush privileges;
mysql> exit

In my previous tutorial, I used phpMyAdmin as the SQL tool. While it is much easier to use then the mysql command line, it nevertheless adds some risk if you allow database logins remotely. So I would not recommand installing it on the production server.

5. Configure WordPress

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: require(‘blog/wp-blog-header.php’).

a. for new setup

Run the setup script at http://yourdomain/blog/wp-admin/install.php

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.

If you need URL rewrite capability, you will need to load the URL rewrite module:

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

b. for existing setup (restoring a previously backed-up database)

mysql -u [username] -p [password] [database_to_restore] < [backupfile]
http://yourdomain/blog/wp-admin/upgrade.php

For a detailed discussing on how to perform backup/restore on MySQL database, please refer to this article.

If you need to access the MySQL database from another machine that is on the LAN, you will want to change /etc/mysql/my.cnf and modify the bind-address to the server address, you can read more here.

I omitted some content which are less commonly used in this article. You can refer to my previous tutorial for more information.

Be Sociable, Share!

12 Comments

  1. pandiana says:

    Thanks a lot for your work and it helps me
    to configure word press as simple as anything.

  2. […] Kerry D Wong Blog Archive Setting up WordPress on Ubuntu Posted by root 1 hour 33 minutes ago (http://www.kerrywong.com) I have also included some screen shots from the text mode ubuntu server setup so that newbies would find the task to configure word press as simple as anything reply to this comment powered by wordpress original theme by srinig Discuss  |  Bury |  News | Kerry D Wong Blog Archive Setting up WordPress on Ubuntu […]

  3. adi says:

    nice info bro.that will be nice if you want to see my blog. maybe we can share about computer. just check my linkthank you:)

  4. Thanks a lot for your work and it helps me
    to configure word press as simple as anything.

  5. Jonathan Shapiro says:

    In this post, you document installing WordPress to the default Apache www folder under /var. I guess this becomes the default Apace web site.

    What if you want to host multiple web sites on this server, and you want a WordPress blog to be just another site on the server?

    Where do you suggest placing the WordPress content and how should I set up Apache to point there?

    • kwong says:

      As a best practice, any sites (including WordPress) should be installed under their own directory (for instance /var/www/wordpress/). If you want your blog to be accessible via your root domain name (i.e. http://www.yourdomain.com) you can go to general settings in wordpress and set the WordPress URL to http://www.yourdomain.com/wordpress and set the blog address as http://www.yourdomain.com. I hope this helps.

      • Jonathan Shapiro says:

        I understand what you are saying and agree, but my question has more to do with hosting multiple web sites with folders in alternate locations other than /var/www on the server.

        In other words, If I want to place the content in another folder altogether, can I define an Apache host header or alternate IP pointing to another path?

        For instance, suppose I want http://www.xyz.com to fetch content from /somefolder/path1/www
        and I want http://www.abc.com to fetch content from /somefolder/path2/www
        and I want my wordpress blog to fetch content from somefolder/path3/www

        etc.

        Can this be done?

        • Jonathan Shapiro says:

          I got this figured out myself. I think I’m on my way. Now I’m trying to set up samba access, and I’m running into a roadblock.

          I created a samba user updated my smb.conf with a share, and when I try to hit that share from windows, I can’t get in. I’ve tried logging in with hostname\username and just username. Nothing gets me into the share.

          Where do I start?

          • Jonathan Shapiro says:

            After about 8 hours of frustration yesterday, I discovered the problem today. It was actually my Windows PC. I was using Windows Explorer to try to connect. The problem was that I had already browsed in to the share when I had it public, and I had an RPC$ connection using my Windows credentials.

            I discovered this when trying to come on via the command line instead of Windows Explorer. I got an error message indicating that I cannot connect under altertenate credentials to the same resource. Then I looked at the output of a net use command and found the connections. Once I deleted them, I was able to log in.

            Ugh!

  6. Thanks for the installation guide! It was easy to follow and worked out great. There is one issue that I have run into so far.

    In order to use the image resize, thumbnails features of the newer releases of WordPress you need to install the GD graphics library for PHP.

    sudo apt-get install php5-gd

    and then restart Apache2

    /etc/init.d/apache2 restart

  7. […] WordPress setup was installed on Debian 5.0 by following the instruction at Kerry D. Wong site.  Although Kerry instruction illustrated how to install WordPress on Ubuntu, I had no issue […]

Leave a Reply