Drupal

Drupal is a content management system, like there are so many around these days. I have been using drupal now for almost 2 years and after dealing with various content management systems, it is still my tool of choice.

Drupal does take a bit getting used to since it does not provide demo content but it remarkably lightweight and very changeable and adaptable.

Drupal has a core system, that is meticously maintained by Dries Buytaert, which has easy ways to expand the function as wel as look and feel of the website. Many different types of "modules" and "themes" are available to install on your website.

Configuring cron job for drupal

Drupal has a number of tasks that need to run on a regular basis. The index for the search engine of the website needs to be indexed regularly to make sure all new content is added to the index. The xml sitemap can be submitted that way. All these "housekeeping items" can be initiated by cron.

Every drupal installation comes with a file called cron.php which is located at the root folder of the drupal installation. You can call the file through a web browser by domainname.com/cron.php. What you get is a blank screen. It does not produce any output.

Normal persons do not go to their browser every hour to visit that URL so most linux/unix provider offer a cron job through a control panel of some sort like Cpanel. In there you can specify to run this file on a regular basis.

So that's what I did, I specified the cron job from the example provided by my hosting provider site:

GET http://yourdomain.com/path_to_file/cgi-bin/file.cgi > /dev/null

I've recently changed the frequency with which it runs so now I have entries in my traffic report for cron.php. These are my apache log files, Google Analytics obviously is not affected by it.

Php runs as an apache module as well as command line driven. So I tried the command line version but the direct reference ends up in errors.

After a little searching on the drupal website I've managed to configure it correctly. What I have done is create a file called cron.sh and i've uploaded it to the folder above the document root and i've made it executable. Here is the content :

#!/bin/sh
ROOT=/your document root goes here
cd $ROOT
/bin/env - HTTP_HOST=websitenamegoeshere.com SCRIPT_FILENAME=$ROOT/cron.php
/usr/local/bin/php -q $ROOT/cron.php

In the cron setting in the website control panel I've specified to run every 15 minutes:

$HOME/cron.sh > $HOME/cronlog.log

It could be though that your php is located at /usr/bin/php instead of /usr/local/bin/php.

Works like a charm.

Content rewriting, drupal and web page redirection

Rewriting content, reorganizing content or updating the file names of pages of a website can happen over time. It is almost a given that pages or structure or even the Content Management System of a website can change. It is really not a big deal. Not redirecting your indexed pages on the search engines however is a very big deal! With drupal it takes a little investigation to get it right.

I actually have changed the structure of my site and I had to figure out how to properly set up directs. Drupal is the CMS of my choice and has been for a long time but that is another story.

A drupal installation comes with standard url rewrites so that a page named like http://www.jasperkooij.com/?q=node/16 can be turned into a url like http://www.jasperkooij.com/drupal/drupal-installation/installing-drupal.htm. So I'm using the example of telling the search engines that my indexed page mentioned above, now has a new location. This can be done with a little trick called redirecting. There are 2 types of redirecting:

For more in-depth information visit Matt Cutts' article on [weblink:31|SEO advice: discussing 302 redirects].The whole rewrite engine is directed by a file called ".htaccess" and this file is sitting on the root folder of your website.

Look for this section in your .htaccess file:


----------------------------------------------------------------------------------------------------------------

# Modify the RewriteBase if you are using Drupal in a subdirectory and

# the rewrite rules are not working properly.

#RewriteBase /drupal


----------------------------------------------------------------------------------------------------------------


before the next section start ( # Rewrite old-style URLs of the form 'node.php?id=x'.)


insert this new section:

----------------------------------------------------------------------------------------------------------------
#custom redirects

RewriteRule ^node/16$ http://www.jasperkooij.com/drupal/drupal-installation/installing-drupal.htm [R=301,L]

#end custom redirects

----------------------------------------------------------------------------------------------------------------


This, I have found works great and creates a very clean redirect to the new page. So check your website traffic reports for 404 errors and simple update your .htaccess file

Drupal Modules

The default install comes with a number of core and optional modules ready to be used.

Drupal XML sitemap problems

On checking and rechecking my website for the right sitemap, working on more content for the drupal section I discovered that in the latest updates for the xml sitemap, the original node names are used! So my xml sitemap contained entries to http://www.jasperkooij.com/node/32 instead of http://www.jasperkooij.com/drupal/content-rewriting-drupal-and-web-page-...

Half an hour later I have found the answer on the forum and xml sitemap project page. The pathauto module is executed later when submitting a page. Not very good!

There is a new module that will help with that:

Module Weight

"This module adds a weight column to the modules table at
admin/build/modules, allowing weights to be viewed and edited. Once
activated, a weight column appears on the modules table. To change a module
weight, edit its value and press "Save configuration". Any user who can
submit the admin/build/modules form will be able to change module weights."

I've installed this module and gave the xml sitemap module a weight of 1 where everything else was 0 and everything works great now!

To download, visit the [weblink:34|Module Weight] project page.

The updated xml sitemap now submits to these search engines:

 
And it has been updated to fine tune more options.

Installing Drupal

Looking for a good content management system is a hard thing to do; you have to compare features, run demo and in that respect I initially never noticed what drupal could do for me since drupal did not have an installer and the demo's did not show much of the power of drupal.

I have written up a step by step guide on how to set up a working drupal system. I'll explain in it 2 parts: having ssh/ftp access and having only ftp access.

First of here are the requirements for drupal:

REQUIREMENTS
------------
Drupal requires a web server, PHP4 (4.3.3 or greater) or PHP5
(http://www.php.net/) and either MySQL (http://www.mysql.com/)
or PostgreSQL (http://www.postgresql.org/). Your database user
will also need sufficient privileges to run Drupal. Please
check the INSTALL.mysql.txt and INSTALL.pgsql.txt for more
detailed information.
NOTE: the Apache web server and MySQL database are recommended;
other web server and database combinations such as IIS and PostgreSQL
are possible but tested to a lesser extent.
OPTIONAL REQUIREMENTS
---------------------
- To use XML-based services such as the Blogger API, Jabber, and RSS
syndication, you will need PHP's XML extension. This extension is
enabled by default.
- If you want support for clean URLs, you'll need mod_rewrite and
the ability to use local .htaccess files. (More information can
be found in the Drupal handbook on drupal.org.)

 

So if you have ssh access, you can simple download the gzip file by logging into your website via ssh and navigate to your document root and then give the command:

wget http://ftp.osuosl.org/pub/drupal/files/projects/drupal-4.7.3.tar.gz

then to expand:

tar xvfz drupal-4.7.3.tar.gz

and to put everything in the right spot:

mv drupal-4.7.3/.htaccess .
mv drupal-4.7.3/* .

SETTING UP YOUR DATABASE:

That shouldn't be much of a problem, the drupal distribution comes with a directory or folder called database that has a sql file for the database. So you would have to:

cd database

There are 2 mysql sql files located here:

database.4.0.mysql
database.4.1.mysql

first you would have to create a dabase and a user before being able to load it so:

mysql -h (your hostname for your mysql server) -u (username to get into mysql) -p
create database drupal;
grant all on drupal.* to yourname@localhost identified by 'password';
exit;
mysql -h (your hostname for your mysql server) -u (username to get into mysql) -p drupal <./database.4.0.mysql

or

mysql -h (your hostname for your mysql server) -u (username to get into mysql) -p drupal <./database.4.1.mysql

for the appropiate version.

Next up would be the configuration file of drupal which is located under the directory names "sites". So move to :

cd ../sites/default
nano settings.php (or edit with your favorite editor)

and look for this line:

	$db_url = 'mysql://username:password@localhost/databasename';
	
And fill in the appropriate values for the username, password, mysql hostname and database name and save the file. At this point your drupal installation is up and running. Start up a browser and visit your homepage it will have the instructions on how to set up user name etc.

INSTALLING DRUPAL BY USING FTP:

First download the latest version of drupal at :

http://ftp.osuosl.org/pub/drupal/files/projects/drupal-4.7.3.tar.gz

and expand it to your harddrive using winrar or similar programs. I'm assuming that if you only have ftp access to your website that you will be able to set up the database using a control panel of some sort like ensim or cpanel and that you have access to phpmyadmin and be able to set up the database, the username for the database and be able to import the sql file and run it. From that point on all you have to do is edit the file /sites/default/settings.php and and look for this line:

$db_url = 'mysql://username:password@localhost/databasename';
And fill in the appropriate values for the username, password, mysql hostname and database name and save the file. At this point  you can upload using ftp all your drupal files and your drupal installation is up and running. Start up a browser and visit your homepage it will have the instructions on how to set up user name etc.
The next article on Drupal will be about all the options under the admin settings.