Nginx, PHP-FPM and MySQL setup on OpenBSD 5.6

OpenBSD is mostly used in firewall implementations, however, many people around the world are using OpenBSD as a web server. This includes programmers and sysadmins. We assume a knowledge of OpenBSD, Nginx, and Unix in general.

Nginx (engine x) is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. For a long time, it has been running on many heavily loaded Russian sites. (from their website)

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. (from their website)


  • OpenBSD 5.6 installed on your VPS.
  • The following PKG_PATH set.
   PKG_PATH =`arch -s/`
  • Super user access.

Install Nginx

$ sudo pkg_add -v nginxAmbiguous: choose package for nginxa     0: <None>      1: nginx-1.4.7p0      2: nginx-1.4.7p0-lua      3: nginx-1.4.7p0-naxsi      4: nginx-1.4.7p0-passenger      5: nginx-1.5.7p3      6: nginx-1.5.7p3-lua      7: nginx-1.5.7p3-naxsi      8: nginx-1.5.7p3-passenger  Your choice:

For the purposes of this document, we install the “5” option.

Install PHP-FPM

$ sudo pkg_add -v php-fpm-5.5.14.tgz

The /etc/rc.conf.local must contain the following:


And /etc/rc.conf must contain the following for these services to start automatically after each reboot.

# rc.d(8) packages scripts# started in the specified order and stopped in reverse orderpkg_scripts=nginx

Edit nginx.conf

Basic requirements for /etc/nginx/nginx.conf in the server section.

location ~ /.php$ {            try_files $uri =404;            fastcgi_split_path_info ^(.+/.php)(/.+)$;            fastcgi_pass;            fastcgi_index index.php;            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;            include fastcgi_params;    }

Edit php-fpm.conf

Update the following in /etc/php-fpm.conf:

; Unix user/group of processes; Note: The user is mandatory. If the group is not set, the default user's ; group will be used.user = wwwgroup = www; The address on which to accept FastCGI requests.; Valid syntaxes are:; ''    - to listen on a TCP socket to a specific address on;                            a specific port;;   'port'                 - to listen on a TCP socket to all addresses on a;                            specific port;;   '/path/to/unix/socket' - to listen on a unix socket.; Note: This value is mandatory.listen =

Install MySQL

$ sudo pkg_add -v mysql-server-5.1.73p0v0.tgzUpdate candidates: quirks-2.9 -> quirks-2.9 (ok)quirks-2.9 signed on 2014-07-31T22:37:55Zmysql-server-5.1.73p0v0:p5-Net-Daemon-0.48: okmysql-server-5.1.73p0v0:p5-PlRPC-0.2018p1: okmysql-server-5.1.73p0v0:p5-Clone-0.36p0: okmysql-server-5.1.73p0v0:p5-Params-Util-1.07p0: okmysql-server-5.1.73p0v0:p5-SQL-Statement-1.405: okmysql-server-5.1.73p0v0:p5-FreezeThaw-0.5001: okmysql-server-5.1.73p0v0:p5-MLDBM-2.05: okmysql-server-5.1.73p0v0:p5-DBI-1.631p0: okmysql-server-5.1.73p0v0:mysql-client-5.1.73v0: okmysql-server-5.1.73p0v0:p5-DBD-mysql-4.027: okmysql-server-5.1.73p0v0: okThe following new rcscripts were installed: /etc/rc.d/mysqldSee rc.d(8) for details.Look in /usr/local/share/doc/pkg-readmes for extra documentation.Extracted 39040357 from 39044890

Initial setup

Create the initial database:

$ sudo /usr/local/bin/mysql_install_db

You can run the /usr/local/bin/mysql_secure_installation script to optimize your MySQL installation. Otherwise, set the root password directly.

$ sudo /usr/local/bin/mysqladmin -u root password 'password'

To access MySQL for administrative tasks – like creating databases and users, you can use the following command:

$ mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or /g.Your MySQL connection id is 47Server version: 5.1.73-log OpenBSD port: mysql-server-5.1.73p0v0Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql>

Add MySQL support for PHP

$ sudo pkg_add -v php-pdo_mysql-5.5.14.tgz

Start Daemons

$ sudo /etc/rc.d/nginx start$ sudo /etc/rc.d/php-fpm start$ sudo /etc/rc.d/mysqld start

Test your installation by writing a basic info.php file into a document root, /var/www/htdocs/

<?php    phpinfo();?>

Upon success, you will be able to view the PHP information web page.


Basic log files are found in the /var/log/nginx directory.


Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

No comments

Powered by Blogger.