Drupal
From HerzbubeWiki
Contents |
Version
The Drupal version I use is a moving target because releases are made so frequently. I have started using Drupal "in ernest" at 4.7.0-rc2 and, at the time of writing/creating this document, am upgrading to 5.1.
System installation
Why not the Debian package
For a short period of time I have used the Drupal package provided by Debian. Unfortunately, Debian packaging is always two or three versions behind. For instance, at the time of writing Drupal 5.1 has just been released, but the Debian package in testing is still at 4.5.3. So, if I had gone with Debian I would have completely missed versions 4.6 and 4.7.
It is a known fact that Debian is always "a little bit backward". Ordinarily, with packages for software that is rather stable and does not release as often as Drupal, this is no problem. I even have sympathy for the Debian package maintainer who attempts to keep up with, but gets overrun by, the active Drupal community.
Whatever the reasons, the current situation with the Debian package is not satisfying, therefore I have opted for a manual installation of Drupal.
Historic notes
For history, these are the notes I haven taken when I first tried to install the Debian package
drupal
Note: If you have apache2 installed, it is possible that aptitude tries to re-install the old apache package. You need to manually correct the situation. This is no problem, Drupal has no web server preference.
The cron scripts of Drupal require the package
php4-mcrypt
Apache configuration:
- enable PHP (php_admin_flag engine on) for the directory /usr/share/drupal if you have it disabled by default
- /usr/share/drupal/.htaccess contains an entry Options -Indexes that should be removed; the entry prevents the automatic loading of index.php when the Drupal base directory is entered in the URL; instead the browser tries to download a file that has type x-httpd-php
Drupal configuration
- in /etc/drupal/conf.php the variable $base_url needs to be changed (e.g. to $base_url = "/drupal";); the original setting $base_url = "http://localhost/drupal"; is unusable
- if you want/need this you can modify /etc/drupal/htaccess and provide additional RewriteRule statements for mod_rewrite; for instance
RewriteCond %{QUERY_STRING} ^q=redirect_url=(.*)
RewriteRule .* %1? [R,L]
(for an explanation of this rule see further down)
References
The installation "manual" is found inside the Drupal tar ball, in the file
INSTALL.txt
Rough instructions for upgrading can be found in
UPGRADE.txt
Manual/shell installation
Tar ball
Unpack the tar ball downloaded from http://drupal.org/ into /var/www and create a symbolic link /var/www/drupal to the versioned directory:
osgiliath:/var/www# ls -ld drupal* lrwxrwxrwx 1 root root 12 Jun 20 2006 drupal -> drupal-4.7.2 drwxr-xr-x 10 root root 4096 May 23 2006 drupal-4.7.0 drwxr-xr-x 10 root root 4096 Jun 20 2006 drupal-4.7.2
Apache configuration
Alias /drupal/ /var/www/drupal/
<Directory /var/www/drupal/>
Options +FollowSymLinks
AllowOverride All
order allow,deny
allow from all
<IfModule mod_php4.c>
php_admin_flag engine on
php_value memory_limit 24M
</IfModule>
</Directory>
Since I am hosting multiple sites on more than one domain, the above block contains global options. The allow from all and php_admin_flag engine on options are present because I have defaults that disallow all access and turn PHP off.
php_value memory_limit 24M is very important - in earlier versions of Drupal various Drupal modules exhibit bizarre behaviour and don't work properly without this option. Since Drupal 6, the Views module requires more than 16 MB.
MySQL configuration
Create a database for every site:
- drupal_herzbube
- drupal_ludenti
- drupal_mosernaef
Create one user drupal (optionally: create one user per site/database) and grant the user all privileges on the Drupal databases.
It used to be necessary to load the database schema manually. Nowadays (I tried this first with with Drupal 5.1), you can simply point your browser to the install.php script:
http://<drupal base url>/install.php
Before you do that, though, you may need to create a site directory first and put a settings.php file into it that points to the database for that site, using the correct password for user drupal. The procedure for this is described in the next chapter.
Drupal configuration
Site configuration
Create one sub-directory for every site in /var/www/drupal/sites. The rules how Drupal matches an URL against site sub-directories are listed in INSTALL.txt. On my system, the current setup looks like this:
osgiliath:/var/www# ls -l drupal/sites/ total 12 lrwxrwxrwx 1 root root 11 Jun 20 2006 default -> herzbube.ch drwxr-xr-x 3 root root 4096 Dec 3 20:05 herzbube.ch drwxr-xr-x 3 root root 4096 Dec 3 20:05 ludenti.ch drwxr-xr-x 3 root root 4096 Dec 3 20:06 moser-naef.ch
Every site sub-directory needs its own file settings.php. Copy the file from an existing site and change it as follows:
$db_url = 'mysqli://<user>:<password>@localhost/<dbname>';
Note: mysqli is a PHP module that provides an improved MySQL interface (usable only with MySQL 4.1 or newer). On updating the system to PHP 5.2, Drupal 4.7 started to issue "access denied" errors on login. The easiest solution to fix the bug (see http://drupal.org/node/93945) without having to patch is to use the mysqli interface.
To protect the password in settings.php, remove some privileges:
chown www-data:www-data settings.php chmod 400 settings.php
Every site can have its own modules, themes and file area:
mkdir /var/www/drupal/sites/<xxx>/modules mkdir /var/www/drupal/sites/<xxx>/themes mkdir /var/www/drupal/sites/<xxx>/files chown www-data:www-data /var/www/drupal/sites/<xxx>/files
Note: The directory files needs to be specified when configuring the Drupal site in the web browser (see next chapter). The entry can be found in the "Site settings" and needs to be changed to sites/<xxx>/files.
Note: Alternatively, it is possible to share modules and themes between sites by placing them into the folders /var/www/drupal/sites/all/modules and /var/www/drupal/sites/all/themes.
Global configuration
files sub-directory
Note: I think the information in this chapter is no longer true for Drupal 5.1.
The directory /var/www/drupal/files needs to be created to prevent errors later on when sites are configured in the web browser.
mkdir files chown www-data:www-data files
Relative links outside of Drupal
The file /var/www/drupal/.htaccess can be modified to provide additional RewriteRule statements for mod_rewrite; for instance
RewriteCond %{QUERY_STRING} ^q=redirect_url=(.*)
RewriteRule .* %1? [R,L]
The effect of this is that you can now have menu entries that provide relative links within the same domain as the site. For instance the menu entry
redirect_url=/gallery2/
now points to the site-relative URL
/gallery2
Note: Starting with Drupal 4.7, the "=" character in menu item paths is replaced by "%3D". When the "clean URLs" option is disabled, the RewriteCond needs to use "%3D": (^q=redirect=%3D(.*)).
Note: Drupal 6 breaks this approach for menu items because of its strict validation of menu item paths.
cron configuration
A "healthy" Drupal site should run periodic maintenance tasks. A user can do this manually by pointing his or her browser to this PHP script:
cron.php
To automate this task I add the script
/etc/cron.daily/osgiliath-drupal
which has the following content:
#!/bin/sh
#
# Run Drupal's maintenance tasks. This should be run regularly (daily) by cron.
#
# Note: Normally cron.php does not output anything, therefore output is not
# redirected (e.g. to /dev/null). If something goes wrong, though, it can be
# expected that some output will be generated. If this script is run by cron,
# the output will be forwarded to the mail account of the user under which
# cron executes this script (usually root).
SITES="www.herzbube.ch www.ludenti.ch www.moser-naef.ch www.grunzwanzling.ch"
for SITE in $SITES; do
URL="http://${SITE}/cron.php"
curl --silent --compressed "$URL"
done
Web browser based configuration
See the separate page DrupalConfiguration.
Modules
See the separate page DrupalModules.
Themes
See the separate page DrupalThemes.
Sites
See the separate page DrupalSites.
Upgrades & Troubleshooting
See the separate page DrupalMaintenance.
