Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles!

Nginx, PHP-FPM and MySQL setup on OpenBSD 5.6

Last Updated: Sat, Feb 28, 2015
BSD Web Servers
Archived content

This article is outdated and may not work correctly for current operating systems or software.

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)

Requirements:

  • OpenBSD 5.6 installed on your vultr.com VPS.
  • The following PKG_PATH set.
   PKG_PATH = ftp://ftp.openbsd.org/pub/OpenBSD/5.6/packages/\`arch -s\`
  • Super user access.

Install Nginx

$ sudo pkg_add -v nginx
Ambiguous: choose package for nginx
a     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:

nginx_flags=""

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 order
pkg_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   127.0.0.1:9000;
            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 = www
group = www


; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port'    - 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 = 127.0.0.1:9000

Install MySQL

$ sudo pkg_add -v mysql-server-5.1.73p0v0.tgz

Update candidates: quirks-2.9 -> quirks-2.9 (ok)
quirks-2.9 signed on 2014-07-31T22:37:55Z
mysql-server-5.1.73p0v0:p5-Net-Daemon-0.48: ok
mysql-server-5.1.73p0v0:p5-PlRPC-0.2018p1: ok
mysql-server-5.1.73p0v0:p5-Clone-0.36p0: ok
mysql-server-5.1.73p0v0:p5-Params-Util-1.07p0: ok
mysql-server-5.1.73p0v0:p5-SQL-Statement-1.405: ok
mysql-server-5.1.73p0v0:p5-FreezeThaw-0.5001: ok
mysql-server-5.1.73p0v0:p5-MLDBM-2.05: ok
mysql-server-5.1.73p0v0:p5-DBI-1.631p0: ok
mysql-server-5.1.73p0v0:mysql-client-5.1.73v0: ok
mysql-server-5.1.73p0v0:p5-DBD-mysql-4.027: ok
mysql-server-5.1.73p0v0: ok
The following new rcscripts were installed: /etc/rc.d/mysqld
See 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 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.1.73-log OpenBSD port: mysql-server-5.1.73p0v0

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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/example.com.

<?php
    phpinfo();
?>

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

Logs

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

Enjoy.

Want to contribute?

You could earn up to $600 by adding new articles