My New Blog - Drupal, MySQL, AxisHOST

After a fair bit of research, I decided to go with Drupal as the web application to power my blog, and to run it on an AxisHOST Linux hosting account.

I've used Drupal in the past for side projects, and it's been great - very solid, good architecture from an administrators point of view. It's overkill for a blog, but - it's easy to use, and free, so why not? Yahoo and IBM have vetted Drupal, which seems like a good vote of confidence to me!

I've also used AxisHOST before - excellent service, excellent prices - a great way to go for most Linux hosting needs.

Installing Drupal took only a few minutes, but definitely required some knowledge of Linux. Actually, It could have taken only a few moments had I used AxisHOST's Fantastico installer - but I wanted to learn a little something, since I've never installed Drupal by hand before. I understand that the next version of Drupal (5.0) will have a built-in installer, so even manual installation might be trivial.

Here's a brief overview of how I installed it, in case it's useful for someone who wants to set up their own site. Drupal has a reputation for being difficult to set up - and I can see that it would be, for people who are not reasonably proficient with Linux. If you do use these instructions, note that I've tried to be accurate, but have not double-checked what I've written - so keep an eye out for small errors. If they do crop up, they should be obvious - if not, feel free to contact me.

1. Log Into The Hosting Account

I use the free putty app for this - it provides a terminal window into my AxisHOST account from my Windows computer, with a secure, encrypted link (using SSH) between my computer and AxisHOST.

2. Get the Drupal codebase, move it into Apache's document root

a. Change to the installed www directory in my AxisHOST account - where the AxisHOST's Apache webserver is expecting to find my web site:
cd ~/www

b. Remove the .htaccess file that AxisHOST puts in my ~www site by default. Drupal has it's own .htaccess site that it wants to see there.
rm .htaccess

c. Copy the tar.gz package of the Drupal codebase (latest production version is 4.7.4) into the ~/www directory. I used wget (which I believe stands for web get) to do this:
wget http://ftp.osuosl.org/pub/drupal/files/projects/drupal-4.7.4.tar.gz

d. "Explode" the Drupal tar.gz backage so that it's usable. tar.gz files pack a bunch of files into a single, compressed file for ease of copying. Now we need to turn the single, compressed file back into a big bunch of files.
tar -zxvf drupal-4.7.4.tar.gz

e. Move the Drupal codebase into the correct directory. The Drupal tar.gz file put everything into a directory ~/www/drupal-4.7.4. However, AxisHOST's Apache web server wants our web site to live one level up, in ~/www. We could either play games with Apache via the .htaccess file and/or Linux symlinks - or we could just copy the codebase. Copying the codebase seems better, particularly for a simple blog site (there might be good reasons to do this differently on a serious business site). So, to copy:

cd ~/drupal-4.7.4
mv * ..
mv .htaccess ..
cd ..
rmdir drupal-4.7.4

3. Prepare the database

Drupal can use either MySQL or PostgreSQL. Since most Drupal sites use MySQL, and since AxisHOST already has MySQL installed, it seemed like MySQL is the way to go (although I'm also quite fond of PostgreSQL!).

The simplest way to deal with MySQL is via a "point-and-click" front end - AxisHOST has such a front end available in its cPanel control panel.

After logging into cPanel, select MySQL databases.

a. Create a database user. MySQL (like most database servers) requires that its own users be set up and given appropriate permissions to access the database.

Using the cPanel front end, let's create a database user to "own" the Drupal database: we'll call ours Drupal_DBUser and assign a password DBUserPassword.

Click Create User to create the user.

Note that cPanel will automatically change the name that you use - it will tack on the user name of your AxisHOST account and a "_" to the beginning of the name. So if my AxisHOST user name was "engineer", the database username I just created would turn into "engineer_Drupal_DBUser" - this is the actual name you'll need to use to access the database in the future.

c. Create an empty database. We need to create an empty database for Drupal, which we'll later fill in using a script that is provided with Drupal. Using the cPanel front end, we'll add a database Drupal_DB, and click Create Database

As happened with the user name, cPanel will automatically change the database name by tacking on the user name of your AxisHOST account and a "_" to the beginning. So if my AxisHOST user name was "engineer", the database username I just created would turn into "engineer_Drupal_DB" - this is the actual name you'll need to use to access the database in the future.

d. Set database privileges. Again using the cPanel front end, under the section that says "Add Users To Your Databases", add the user just installed (e.g., engineer_Drupal_DBUser) to the database just installed (e.g., engineer_Drupal_DB). The permissions needed are SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, and LOCK TABLES - e.g., all of them except REFERENCES, which is actually not currently implented in MySQL - so you may as well simply grant all privileges.

Click Add User to Database to effect the change.

4. Install the Drupal Database

Now we'll run a script provided with Drupal, database.4.1.MySQL, that builds the database schema that Drupal needs to function. This step can be done from a graphical interface, but is just as easily done from our putty terminal session:

MySQL -u engineer_Drupal_DBUser -p engineer_Drupal_DB < ~/www/database/database.4.1.MySQL

5. Point the Drupal installation to the correct database

Drupal finds the correct database, as well as the information for using that database (e.g., user name and password) via the settings.php file in the ~/www/sites/default directory. We have to edit that file to enter the correct information. I find that the Linux's nano editor is a reasonable way to edit text in a terminal. Start up an editing session with:

nano ~/www/sites/default/settings.php

Scroll down (with the arrow keys) to the line that begins db_url = ' (not one of the lines that begins with an '*' - those are just comments.)

and change that line and the next to fit your installation. For example, using the settings that I've given so far, we'd use:

$db_url = 'MySQL://engineer_Drupal_DBUser:DBUserPassword@localhost/engineer_Drupal_DB';

6: Try It!

Give it a whirl - it should work now - open a browser, and surf to your domain - e.g., www.alcohen.com. You should see the Drupal welcome screen.

6:Create the "files" directory

Well... it almost works. After logging in and going to the admin page, I found out that Drupal was looking for a directory that did not yet exist. So let's make it exist, using my putty terminal session:

Create the directory
mkdir ~/www/files

Set appropriate permissions
chmod 777 ~/www/files

7: Add the cron job

Some things in a Drupal website happen periodically, behind the scenes. For example, new content must be periodically indexed for search to function, any RSS feeds that you've set up must be periodically fetched, and so forth. In Drupal, these things are activated by calling the cron.php page, e.g., http://www.alcohen.com/cron.php on my Drupal site. cron.php displays a blank page, but it also starts the internal processes that need to run periodically.

Obviously, we need a way to call this page automatically every once in a while - say, once an hour or once every 15 minutes. Linux's cron daemon (a daemon is a service that runs in the background) is ideal for this - you tell cron what to do and how often to do it, and off it goes.

The simplest way to access cron is from cPanel. In the main cPanel menu, click on "Cron jobs" . Select the "Advanced (Unix Style)" option. For command to run, enter:

wget -q -O /dev/null http://www.alcohen.com/cron.php

To run once an hour, at 8 minutes after the hour, fill in the fields as follows:

Minute: *
Hour: *
Day: *
Month: *
Weekday: *

If you wanted to run more often, say every 15 minutes (usually not needed), you could enter multiple times in Minutes, e.g.,

Minute:0,15,30,45

while leaving the rest the same.

8: Set up robots.txt

After running for only a few hours, I started seeing "robots.txt not found." in my log - this reminded me that I needed a robots.txt file to tell Google and other search engines how to index my site. For now, I'm just using Drupal's own robots.txt from http://drupal.org/robots.txt - I figure that they ought to know what they're doing.

9. Add modules

Adding modules is simple in Drupal - just copy them and ungzip them into the ~/www/modules directory. I've added the tinyMCE module to give me mini-word-processor functionality on input text boxes - I'm sure that I'll add a few more later.