Setting up Drupal on OpenBSD can be really simple. You will only need a default installation of the operating system and a few packages from the ports system.
These are handy, but optional:
To install packages from ports and their dependencies, simply type:
$ export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -m`/
And then for each package
$ sudo pkg_add packagename
and follow on-screen instructions.
While you can install Apache 2.2 from the ports system, you will probably find it's not worth the trouble as OpenBSD base ships with a strengthened fork of the Apache 1.3 web server, which does the job just fine.
This requires a few more special steps, mainly in relation to the restricted privileges of the process running the web server.
It runs by default in a "chroot jail", meaning that the web server process httpd cannot access any files outside a pre-defined directory, by default /var/www. If the web server process is trying to open /etc/example.conf, it is actually accessing /var/www/etc/example.conf. This means that the Drupal PHP code fails to connect using the default socket that MySQL emits, by default /var/run/mysql/mysql.sock. Solve this by creating a directory inside the chroot jail, and then a symbolic link pointing to the real socket:
$ sudo mkdir -p /var/www/var/run/mysql
$ sudo chown www:daemon /var/www/var/run/mysql
$ sudo ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock
This symbolic link needs to be reset each time the server reboots, so you might want to do the above in your rc.local (without sudo). The sample hack below additionally waits for the MySQL socket to appear before the symbolic link is made:
### in /etc/rc.local:
# mysql server
if [ -x /usr/local/bin/mysqld_safe ] ; then
su -c mysql root -c '/usr/local/bin/mysqld_safe >/dev/null 2>&1 &'
echo -n ' mysql'
mkdir -p /var/www/var/run/mysql
chown www:daemon /var/www/var/run/mysql
# wait for a socket to appear
for i in 1 2 3 4 5 6; do
if [ -S /var/run/mysql/mysql.sock ]; then
echo -n "."
ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock
You must also provide a separate hosts file in /var/www/etc (since the usual /etc/hosts is outside the jail, and therefore inaccessible), at least containing the following:
127.0.0.1 localhost www.example.tld
Also make sure to similarly copy an instance of any /etc/resolv.conf* files you might have into the chroot, as this is needed for sites that make outward connections and needs to resolve hostnames.
Similarly, a /tmp directory must be created in the chroot jail for file uploads to work:
$ sudo mkdir -p /var/www/tmp
$ sudo chown www:daemon /var/www/tmp
To enable the httpd server at boot:
$ sudo echo "httpd_flags=" >> /etc/rc.conf.local
Then reboot, and verify that mysqld and httpd starts.
Add your user and database to mysql and then test the connection using this snippet in /var/www/htdocs/test.php:
/* fill in your values for $host, $user and $password here */
$host = 'localhost';
$user = 'user';
$password = 'secret';
$conn = mysql_connect($host, $user, $password)
or die("Error connecting: " . mysql_error());
echo "Connection ok";
Setup httpd as you'd normally setup Apache. The default configuration file (/var/www/conf/httpd.conf) goes a long way.
Drupal is included in the ports system as well, but updates are infrequent. You would probably want to install the normal way. Be sure to put the Drupal directory either at/inside the webroot itself (normally /var/www/htdocs) or inside the chroot, such as
and softlink to that target from within the server webroot (great for multisite and upgrade scenarios).
For cron you would normally prefer lynx, as it is included with the OS. Use
$ sudo crontab -e
to add something like
#minute hour mday month wday command
40 * * * * /usr/bin/lynx -source http://www.example.tld/cron.php