Host a personal diary on your PC using WordPress

August 04, 2006
A couple of months back, I did something really interesting. I downloaded the WordPress content management suite from the wordpress.org site and installed it on my machine. The installation as such was a simple affair of unpacking the WordPress files in the desired location - I unpacked it in the '/var/www/' location - and in no time I had a robust blog hosted on my PC.

The prerequisites for getting WordPress up and running are - you need to have PHP, MySQL and Apache web server running on your machine. In an earlier post, I had explained how I configured MySQL and hosted webpages using Apache webserver. The steps are the same for wordpress too.

So why did I do such a thing? Well, I am in the habit of maintaining a diary containing my day to day experiences as well as jotting down my thoughts on topics close to my heart. After installing and trying out wordpress, I decided to write on the blog rather than the diary. And now a days, I write my day's thoughts on the WordPress blog I have hosted on my machine. Already I see a lot of advantages to this form of documenting. For one, my family can pull up my blog and read about my day as well as get to know about things which I may have failed to reveal to them. Not only that they can post comments on the blog sharing their view point.

And in the event that I do not want even my family to read a post, WordPress has a feature of password protecting individual posts which comes handy. This project of hosting WordPress blog on my machine has become such a hit with my family that I have created accounts for my whole family and each one of us put to words our thoughts and tribulations as well as document interesting stuff like recipes, jokes that one came across and so on.

Fig: My (Wordpress) Diary hosted on my own machine

I find the search feature of WordPress really useful. For example, the blog (my diary) now has over 20 posts. And if I want to find a particular post all I have to do is search for it and since wordpress uses MySQL database as the back-end, the search is very fast and accurate.

Editing and managing WordPress blog is a dream come true for any person who is into writing. For one, you have a WYSIWYG kind of editor which though not having all the features of a word processor, has sufficient formatting functions like bold, italic, text alignment and image insertion ... which makes it a joy to write and publish content. And the interesting thing is that it produces correct XHTML code.

Another feature which I really like in WordPress is how one can edit the comments that were made by others. For example, this blog (All about Linux) has seen a fair share of spam in the comment section and one feature lacking in a blog hosted on blogspot domain is that you cannot edit the comments that others insert in your post. Now a days when a good blog could easily be bogged down by spam and flame comments, this feature is god send. And what is more, one can track the IP address of the comments made, and the blog author also have the choice of approving or unapproving a comment which goes a long way in maintaining the sanity of the blog.

Categories in WordPress
WordPress allows one to create categories. For example, this post, if it was published in a wordpress blog could have been tagged wordpress or content management and that makes it easy to navigate. I believe any content management software worth its name should support categories. In wordpress, if one clicks on the particular category, all the posts related to the category are displayed. What is more, it is possible to associate each post with multiple categories. So if I write an article on programming in Linux, I can tag that article in both the Linux as well as Programming categories.

Themes in WordPress
One of the most alluring aspects of wordpress is the ease with which one can create themes. This simple way of creating themes have helped spawn a humongous collection of themes which are free for use by anybody using wordpress. There is a theme to suite any purpose - from the simple two column theme to the complex three or more column theme with heavy graphics. And some very popular themes like K2 have an inbuilt user interface which allows one to make minor changes to the theme layout without touching the underlying code what so ever. I dare say that Wordpress has the most number of themes when compared to other content management suites.

Plugins bring more functionality to Wordpress
The last time I checked, there were hundreds of plugins available for Wordpress. Plugins are pieces of PHP code which can be easily used to add one or more features to the default Wordpress setup. And it is easy to install plugins. Just download the plugin archive and unpack it in the plugins directory in your Wordpress blog. After that all that is needed is to enable the plugin which is done by navigating to the Plugins section in the administrator panel of your blog and activating the plugin.

Steps for Installing Wordpress on ones machine
Before installing Wordpress, it is important to have a running MySQL database server, a web server (preferably Apache) and also the necessary PHP modules installed. In previous posts, I had explained how to configure Apache webserver to host websites on ones machine as well as configuring MySQL database. Once these prerequisites are met, navigate to the official WordPress website and download the latest version of the software. As of this writing, the latest stable version of Wordpress is 2.x. Once downloaded and unpacked, copy the directory into the Apache webserver document root - in a default setup, it is /var/www. On my machine, I unpacked it in the '/var/www/myblog/' folder. And then opened it in the web browser by typing the following address: 'http://localhost/myblog/' . The exact steps of unpacking the Wordpress blog are as follows:
$ tar -xvzf wordpress-2.0.3.tar.gz
$ sudo cp -R wordpress/ /var/www/.
$ cd /var/www/
$ sudo mv wordpress myblog
Since it is the first time that I am opening the blog, it will be opened in setup mode and will initiate the installation process. In particular, it looks for the file 'wp-config.php'. This file should contain all the details about the database such as the username and password needed to connect to the MySQL database, the database name and so on. I found a sample file by name 'wp-config-sample.php' in the blog folder. I just renamed it to wp-config.php and edited the file to mirror my database, username and password. On the other hand wordpress itself will offer to do it for you but if the blog folder does not have sufficient permissions, then it would cause some problems. So it is always fail safe to edit the file by hand.

Of course, it is understood that you need to have a database created with the same name entered in the wp-config.php file prior to the above steps and it should be accessible using the username and password entered in the wp-config.php file. I created the mysql user and the database as follows:
$ sudo mysql
Create the user ravmad
mysql> Create user 'ravi' identified by 'mypassword';
Create the database by name db_myblog
mysql> create database db_myblog;
Grant the rights to the user ravi for the database db_myblog
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX,ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON db_myblog.* TO 'ravi'@'localhost' IDENTIFIED BY 'mypassword';

mysql> quit
My wp-config.php file contents after editing is as follows:
<?php

// ** MySQL settings ** //
define('DB_NAME', 'db_myblog'); // The name of the database
define('DB_USER', 'ravi'); // Your MySQL username
define('DB_PASSWORD', 'mypassword'); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value

... //lines removed for brevity
?>
Now I refreshed the page http://localhost/myblog in the web browser. And Wordpress populated the database db_myblog with the necessary tables as well as generated a unique password for the username 'admin' which by the way has administrator privileges. It is recommended to login as administrator and change the password to one that is easier to remember lest you forget the Wordpress generated password.

Fig: First step of the two step Wordpress installation

Fig: Second and final step.

A simpler way of accomplishing the above tasks
If you feel editing the wp-config.php file by hand to be too much of a chore, you can let Wordpress walk you through the process via the web interface. But the catch is that your blog directory should have the correct permissions. I found that if the blog directory had the user ownership as your username and group ownership as that of the Apache webserver then wordpress is able to edit the files in the blog directory without any problems.

To check the user account used by Apache web server, I ran the command as follows:
$ ps aux|grep apache2|cut -d" " -f1 |head -n 2
root
www-data
The above output tells me that the first apache process (the parent) is owned by root and the Apache child processes spawned by the parent run with the user id www-data. So for successful editing of the files, I need to change the group ownership of the blog directory to www-data and give write permissions to it. This I achieved as follows:
$ sudo chown -R ravi.www-data myblog
$ sudo chmod -R g+w myblog
After executing the above steps, if I do a long listing of the blog directory, I will get the following output.
$ ls -ld /var/www/myblog
drwxrwxr-x 5 ravi www-data 4096 2006-08-04 07:47 myblog
Now I can go back to the web interface (http://localhost/myblog/ ) and finish the installation.

Important: I have seen some content management systems suggesting to give the blog directory write permissions to everyone (777) for ease of installation. But I believe that is a security issue especially when you are hosting your blog on a shared hosting plan where each website is just a directory. Now it is clear to see that if you give your blog directory write permission for everyone, then others who are hosting websites on the same server as yours can have free access to your files and can easily compromise them.

Once I finished setting up WordPress, it became the blogging platform of choice for my whole family. In fact, we use it to document just about anything from contact information to recipes to ... in fact any data that needs to be remembered. And it is much more fun than writing in a book.

13 comments:

  • Ravi,

    Why can't I use a wiki for that? OddMuse wiki is just one example.

    Don't you think wordpress is too heavy for personal-offline blogging?

  • Thanks for this very complete article on setting up wordpress. Got a couple of my questions answered reading this.

  • I did not know that adding write permissions for everyone while installing was a security issue. I have been prompted by certain cms in the past to give write permissions for everyone for some of the directories in the process of installing.

    Thanks for pointing out how to do it right. Enjoyed the article.

    @ranjhith and darkknight,
    Aren't wikis used for collaborative editing rather than individual publishing which is a pre-requisite of a diary? I would always favour a blog over wiki for this kind of thing provided it is simple to setup.

  • Lewis,

    Even blogs can be collaborative. Wiki does cross-referencing better. Now the trend is moving from a blog world to wiki world. As wiki is more advantageous.

  • just saw the beginning of your post. about unpacking wordpress into /var/www/ my suggestion is you unpack it into you home folder rather and create a symlink in /var/www/ just for security reasons. I guess i'm just paranoid :)

  • Um, I'm afraid I can't take any CMS that doesn't support Postgresql seriously. Plus, we all know Mysql is just a toy.

  • @ambarish
    As they say, One man's toy is another man's tool.

    Btw, there is a port of wordpress which uses postgresql as the database. You can find it at wordpress-pg

  • @anonymous,

    Hey, thanks! I didn't know about wordpress-pg. That said, reading the blurb at the end of the page gives me no confidence about either wordpress-pg or wordpress itself. I think I'll stick with typo.

  • Hey Ravi,
    Thanks for this wonderful post on setting up wordpress. I was looking for just such a resource.

    Could you also explain how to use permanent links in wordpress instead of those with '?'. I have heard that the latter are not search engine friendly.

    --
    Andre

  • In an easy way.
    Just << apt-get install wordpress >>.
    Always up to date.

    I'ts a nice reading for begginers and to get new wordpressers.

  • @kike,
    You are right. apt-get install wordpress will help in installing wordpress. But you definitely have to do the configuration part like creating database, changing the apache configuration to reflect your website and so on which is where this article gains prominence.

  • I've been using Wordpress for quite some time to do the same personal diary thing as you. I don't share my diary with anyone else other than me, but Wordpress offers a more robust means to do so. I used to use simple text based packages to maintain a diary, but after awhile this can get messy to maintain. For all those skeptic of a database being overkill to maintain a personal blog, just think about if you post daily in a diary for a long time...say a few years. After awhile, you'll get overwhelmed when something crashes, as all computers will do evetually. Having things in a database that you can backup easily daily, gives you the ability to move that database to any machine very quickly and very easily. I also use Wordpress as my public blogging package. I must say it's one of the best applications I've ever used. It's also very well maintained, and when anything needs security updates, they are very on top of things. Very simple to use package, but yet offers so much to build a personal website, or do as this post suggest and give you a means to jot your thoughts down.

  • A very informative post. Thanks. I was wondering which blogging platform to choose for hosting my blog. I had a couple of them in my mind. And this article has leaned me towards WordPress.

    Franc