This document describes the steps I took to get Drupal [1] installed and working on FreeBSD [2]. I used freebsd 4.11-release and drupal 4.6.0.
Although drupal is available in th ports collection, the port doesn't take care of any dependencies so it's easier to install by hand. When I tested the drupal port in the ports tree it just downloaded and copyed the drupal files to the web root directory. It didn't install any of the other dependencies required to install drupal. This may have changed in more recent versions of FreeBSD. I prefer installing the dependencies separately as it gives more control over each component.
1 Download Drupal from http://www.drupal.org. I used version 4.6.0
wget http://drupal.org/files/project/drupal-4.6.0.tgz
tar -zxvf drupal-4.6.0.tgz
This creates a directory called drupal4.6.0 containing all the drupal files
Move this directory to somewhere inside your web directory
mv drupal-4.6.0 /usr/local/www/data
Read through the INSTALL.txt in the drupal directory. You will have to follow all the steps here to install drupal. There are just some extra caveats for installing drupal on freebsd.
2 Install MySQL
I have tested it with mysql 3.23 and 4.0 and both worked fine. However 4.1 had a problem with password encoding that prevented database access.
2.1 install mysql-client
cd /usr/ports/databases/mysql323-client/
make
make install
make clean
2.2 Install mysql-scripts
cd /usr/ports/databases/mysql323-scripts/
make
make install
make clean
2.3 Install mysql-server
cd /usr/ports/databases/mysql323-server/
make
make install
make clean
2.4 Move the database files to /usr/local (optional)
This step depends on your disk setup. By default, mysql will store its files in /var/db. You may prefer to store them somewhere else. For example you may have a different partition with lots of space. If you dont care where the mysql database files are stored skip this step.
cd /var/db
mv mysql /usr/local/
ln -s /usr/local/mysql mysql
cd /usr/local
chown -R mysql mysql
At this point mysql is installed but not running.
You can start the mysql server by running the command
/usr/local/etc/rc.d/mysql-server.sh start Note: you must enable the mysql rc script first (see below)
2.5 change the mysql root password etc
A default mysql install has no root password set and allows anonymous connections. This is not a good idea.
mysqladmin -u root password newpassword
mysql -u root -p
use mysql
SET PASSWORD FOR root = PASSWORD('blah');
SET PASSWORD FOR root@hostname.ucd.ie = PASSWORD('blah');
delete from user where User='';
2.6 Create the Drupal Database
Now that you have a working mysql installation you need to create the database and tables that drupal will use
mysqladmin -u dba_user -p create drupal
mysql -u dba_user -p
Enter your mysql password. Now you need to create a database user for drupal. Enter the following in mysql
GRANT ALL PRIVILEGES ON drupal.* TO nobody@localhost IDENTIFIED BY 'password';
flush privileges;
Then exit mysql
Now load the drupal database
mysql -u nobody -p drupal < database/database.mysql
3. Install Apache and mod_php
Thanks to the freebsd ports system, installing apache with mod_php is easy. However the ports configuration leaves out several apache modules that are needed to run drupal.
You need to install apache with php support. The www/mod_php4 port doesn't compile all the options needed to run drupal.
3.1 Change the port Makefile
The port /usr/ports/www/mod_php4/ is a link to the port /usr/ports/lang/php4/
Add the following code to the file /usr/ports/lang/php4/Makefile. Put this somewhere after CONFIGURE-ARGS is defined.
#AF - need the following modules to use drupal
#mysql
CONFIGURE_ARGS+=--with-mysql=${LOCALBASE} \
--with-zlib-dir=/usr
USE_MYSQL= yes
#session support
CONFIGURE_ARGS+=--enable-session
#xml support
LIB_DEPENDS+= expat.5:${PORTSDIR}/textproc/expat2
CONFIGURE_ARGS+=--enable-xml \
--with-expat-dir=${LOCALBASE}
#pcre
CONFIGURE_ARGS+=--with-pcre-regex=yes
PHP_HEADER_DIRS=pcrelib
#gd image library
LIB_DEPENDS= freetype.9:${PORTSDIR}/print/freetype2 \
png.5:${PORTSDIR}/graphics/png \
jpeg.9:${PORTSDIR}/graphics/jpeg
CONFIGURE_ARGS+=--with-gd \
--with-freetype-dir=${LOCALBASE} \
--with-jpeg-dir=${LOCALBASE} \
--with-png-dir=${LOCALBASE} \
--with-zlib-dir=/usr
OPTIONS= T1LIB "Include T1lib support" on \
TRUETYPE "Enable TrueType string function" on \
JIS "Enable JIS-mapped Japanese font support" off
PHP_HEADER_DIRS=libgd
#/AF
3.2 Install the port
cd /usr/ports/www/mod_php4
make
make install clean
3.3 Apache settings
Change Apache's Allowoverride setting for the drupal install directory so that the .htaccess works
e.g. put something like the following in /usr/local/etc/apache/httpd.conf
<Directory "/usr/local/www/data/drupal-4.6.0">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
4 Setup a crontab for drupal
create ~/crontab containing the following
15 * * * * wget -O - -q http://www.mydomain.org/cron.php
45 * * * * wget -O - -q http://www.mydomain.org/cron.php
This calls your site's cron.php on the 15th and 45th minute of every hour
Now issue the command
crontab ~/crontab
5 Edit Drupal settings
Change $db_url and $base_url in the file sites/default/settings.php of your drupal installation
$db_url = "mysql://username:password@localhost/database";
$base_url = "http://www.mydomain.com";
create a files directory that is readable and writable by the drupal/webserver process in the drupal directory
mkdir files
chown www files
chmod 755 files
6 Start mysql and apache
Before you can use the apache and mysql rc scripts, you need to enable them. To enable them, add the following lines to /etc/rc.conf
mysql_enable="YES"
apache_enable="YES"
Then you can start apache and mysql with the following commands:
/usr/local/etc/rc.d/mysql-server.sh start
/usr/local/etc/rc.d/apache.sh start
Now you should be able to access drupal through your web browser. Enjoy!
Note:There have recently been some security issues with the php xmlrpc library. This has resulted in a couple of serious exploits for drupal. You may want to limit access to the file xmlrpc.php. If you don't need it you can delete it. Otherwise you you can limit access by ip by placing something like the following in your drupal installation .htaccess file:
RewriteCond %{REMOTE_ADDR} !^(127.0.0.1)$
RewriteRule ^/?xmlrpc.php - [L,F]
Resources
The Drupal Install File: INSTALL.txt in your drupal directory
The Drupal Handbook Install Section [3]