≡ Menu

OpenBSD 5.2 Web Server: Apache + MySql + PHP

OpenBSD is a great OS for hosting Apache/MySQL/PHP web apps. Because OpenBSD locks down Apache by default, and the version of PHP supplied by the OpenBSD team already has several security-enhancing patches in place.

Step 1: Set up the package manager

I’m using OpenBSD mirror at kartolo.sby.datautama.net.id for best speed in Indonesia.

Step 2: Installing Packages

1. Apache 2.2

2. PHP-MySql

Running the following command:

3. MySql Server

3. Setting MySql Instalation

4. Secure MySql Instalation

5. Installing phpMyAdmin

Running the following command:

Since Apache is locked away, it can’t talk to the database software, MySQL. The default install doesn’t automatically place MySQL inside Apache’s jail. Currently is impossible for the two to even communicate. You need to move the communication file: /var/run/mysql/mysql.sock

To make Apache happy we have to place this special file inside the jail. This can be done on startup using your handy rc.local file.

Put the following lines:

Step 3: Start OAMP services automatically

put the following lines:

Step 4: Reboot

Once everything is installed and configured to start automatically, reboot to make sure everything starts up as expected.

Step 5: Testing

Create phpinfo file:

Open phpinfo script:

phpInfo OpenBSD

Open phpMyadmin:


phpmyadmin openbsd

– http://www.h-i-r.net/p/hirs-secure-openbsd-apache-mysql-and.html
– http://www.openbsdsupport.org/e107_CMS.html

{ 7 comments… add one }
  • giyang April 5, 2013, 8:36 pm


    Thanks for your directions. I can running Webserver now.

    How ever I can’t running phpmyadmin.  I did follow install but I can only see like

    Not Found
    The requested URL /phpMyAdmin/index.php was not found on this server.

    Do you have any thought and help can get that one?


  • Kang Asep April 6, 2013, 1:49 am

    @giyang have you run this command : ln -s ../phpMyAdmin /var/www/htdocs/phpMyAdmin ?

  • jose cely April 19, 2013, 10:27 am

    Thanks a lot!
    I wrote and spanish article based on yours work:


  • tom June 15, 2013, 4:12 pm

    hi,its    echo -n ” mysqld” or    echo -n “mysqld” ?


    Your tut maybe working but not for me… im using apache that comes by default.

    can it be the reason?

    i followed the OAMP tutorial from hir. the same you followed and its working.

    when i try to install your phpmyadmin way, i cant see any phpmyadmin and it gives an error at boot:

    mysqld130615 – mysqld_safe Logging to ‘/var/mysql/mymachine.localdomain.error

    and also this:

    ln: /var/run/mysql/mysql.sock: No such file or directory


  • Kang Asep June 28, 2013, 1:29 pm

    i use echo -n ” mysqld”

    are you sure that you’re installing mysql correctly ?

  • Daniel August 29, 2013, 1:22 pm

    Just for info, since this is first result of google query “apache mysql php openbsd” on google, there are no reasons for add apache-httpd packet since openbsd have native apache demon httpd. If you are going to install it you need to include


    into your /etc/rc.conf.local instead of “mysqld_flags=”.

    If you need to run apache2 into your obsd it’s ok, but with this tutorial your going to install apache2 package but going to configure your server as apache 1 (httpd_flags=””) since you need to install ap2 package (for php, mysql etc) and take your configuration directory as /var/apache2 .

    As of mysql rc.local script, that’s cool tip but you can however force mysql to use tcp connection and avoid socket script specifying instead localhost into your php connection scripts.


    Anyway your tutorial is cool but “# pkg_add apache-httpd” is useless passage.

  • Daniel August 29, 2013, 1:24 pm

    errata correge:

    into your /etc/rc.conf.local instead of “mysqld_flags=”.


    into your /etc/rc.conf.local instead of “httpd_flags=”.

Leave a Comment