How To – OpenBSD 4.0 + MySQL + PHP 5

We do all know that OpenBSD secure by default, and we all know that how hard to work web server on OpenBSD. And may this how to help you all. First of all the apache is chroot-ed at the /var/www, if you want to disable this ‘jailing’ thing you may need to do this command$sudo /sbin/httpd -u
edit the /etc/rc.conf.local
# use -u to disable chroot, see httpd(8)

And lets get start, we need all these packages mysql-server, php5-core, php5-mysql, php5-mcrypt, php5-mhash, php5-domxml, php5-imap, php5-pear. You could add more modules later.

First we need to export the PKG_PATH, do this to export your nearest OpenBSD ftp, and you may need to take a look what arch you use (i386, amd64 and so on).

$export PKG_PATH=

Then we just need to install all the packages :

$sudo /usr/sbin/pkg_add -v mysql-server
$sudo /usr/sbin/pkg_add -v php5-core
$sudo /usr/local/sbin/phpxs -s
$sudo cp /usr/local/share/examples/php5/php.ini-recommended /var/www/conf/php.ini

And now install the modules, and activate it
$sudo /usr/sbin/pkg_add -v php5-mysql
$sudo /usr/local/sbin/phpxs -a mysql
Activating extension : mysql

$sudo /usr/sbin/pkg_add -v php5-mhash
$sudo /usr/local/sbin/phpxs -a mhash

$sudo /usr/sbin/pkg_add -v php5-mcrypt
$sudo /usr/local/sbin/phpxs -a mcrypt

$sudo /usr/sbin/pkg_add -v php5-domxml
$sudo /usr/local/sbin/phpxs -a domxml

$sudo /usr/sbin/pkg_add -v php5-imap
$sudo /usr/local/sbin/phpxs -a imap

$sudo /usr/sbin/pkg_add -v php5-pear
$sudo /usr/local/sbin/phpxs -a pear

Now we all set, now we need to run the mysql server
$sudo /usr/local/bin/mysqld_safe &

And now you must make your own login password.After that you need to edit the httpd.conf and add un-comment this following line AddType application/x-httpd-conf .php

$sudo nano /var/www/conf/httpd.conf

Now, restart the apache server using apachectl or /usr/sbin/httpd -u.

On OpenBSD, apache comes chrooted in the /var/www directory. MySQL’s default socket location is in /var/run/mysql/mysql.sock. This causes a problem since apache can’t “see” the /var/run directory. To overcome this, we need to make a hard link to the mysql.sock socket file. This is achieved by typing the following at the command prompt:

# mkdir -p /var/www/var/run/mysql# ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock

If you want to make sure that mysql and apache server is running or not you can use nmap to see what port is listening. Hope you all enjoy …


    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s

%d bloggers like this: