Last updated November 24, 2011. Created by JohnNoc on March 1, 2010.
Edited by Kami Petersen, Wieland. Log in to edit this page.
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.
Recommended packages:
- mysql-server
- php5-core
- php5-mysql
- php5-curl
- php5-gd
- php5-mbstring
- php5-mcrypt
These are handy, but optional:
- pecl-APC
- pecl-uploadprogress
- phpMyAdmin
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 packagenameand 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.sockThis 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
break
else
sleep 1
echo -n "."
fi
done
ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock
fiYou 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.tldAlso 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/tmpTo enable the httpd server at boot:
$ sudo echo "httpd_flags=" >> /etc/rc.conf.localThen 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:
<?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
/var/www/drupal-6.xand 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 -eto add something like
#minute hour mday month wday command
40 * * * * /usr/bin/lynx -source http://www.example.tld/cron.php
Comments
Drupal 6.x on OpenBSD (cont.)
I also had to setup an /etc file within the chroot jail (/var/www/etc/) and create a hosts file within the /etc file for the localhost 127.0.0.1. This fixed several problems with the "status report" and allowed updates and update checks to work normally. Multisite has so far also required an alias in the hosts file to localhost as well, although I am still playing around with my configuration. Haven't had time to sort all this out yet as I am still pretty new to Drupal overall.
PDO extensions
For Drupal 7, PDO extensions are required.
I wrote a blogpost on how to install those on OpenBSD.
http://www.guusbosman.nl/2010/10/23/drupal-7-openbsd-pdo-extension-required
resolv.conf also needed in the jail
The error message Your system or network configuration does not allow Drupal to access web pages ... under Home->Administration->Reports->Status report appeared after some system maintenance. After several hours of searching the web for answers, I stumbled on a PHP script that checked the web server's ability to make outside connections:
<?php$domain = 'drupal.org';
$fp = fsockopen($domain, 80, $errno, $errstr, 30);
if (!$fp) {
echo "Darn!<br />\n";
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\n";
$out .= "Host: $domain\n";
$out .= "Connection: Close\n\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
(copied from http://techdebug.com/blog/2008/02/26/openbsd-akismet-key-could-not-be-ve...)
This test failed on our server, so the problem was related to the web server failing to connecting to the outside world. It turned out that the server process also needs access to
/etc/resolv.conf, so if you get this error, you might try to copy that file to/var/www/etc/resolv.conf.