Rodolfo Bandeira

Rodolfo Bandeira

software, electronics, security, devops, thoughts

OpenBSD 5.6 + NginX + PHP-FPM

Hi there!

Today I’m gonna teach you how to set up a OpenBSD 5.6 + Nginx + PHP-FPM webserver.. Probably you guys heard about DigitalOcean are now dropping FreeBSD instances on their servers. So.. I’m a big fan from OpenBSD since at least 10 years and decided to look for a Cloud SSD host that you can create and run your OpenBSD. I did a search in twitter with words: “digitalocean openbsd” and found more bsd fans like me bringing this amazing host: http://vultr.com

So, what’s the main difference between Vultr over DigitalOcean? In Vultr you can put any .iso and they will provide a console window based on VNC. So, you can install any iso. And.. that’s really cool! Sweet! I’m gonna write a specific post about how to install OpenBSD on vultr.com but today let’s set up a webserver!

  1. First of all, let’s grab a FTP mirror close to you or close to your server. In my case, I’m running a server on New York City and that’s my ftp mirror:
ftp://mirrors.nycbug.org/pub/OpenBSD/
  1. We need to set up the pkg_path. (I’m not running as root. Single user ok? $)
export PKG_PATH=ftp://mirrors.nycbug.org/pub/OpenBSD/5.6/packages/`machine -a`/
  1. Let’s install php-fpm!
sudo pkg_add php-fpm
quirks-2.9 signed on 2014-07-31T22:37:55Z
quirks-2.9: ok
Ambiguous: choose package for php-fpm
 a       0: <None>
         1: php-fpm-5.3.28p9
         2: php-fpm-5.4.30
         3: php-fpm-5.5.14
  1. Of course we’re going to install the newest version. It will ask to you about the PHP version we’re going to install:
Ambiguous: choose dependency for php-fpm-5.5.14: 
 a       0: php-5.5.14p0
         1: php-5.5.14p0-ap2
Your choice: 0
  1. Now let’s see the Package Management download and install:
php-fpm-5.5.14:libiconv-1.14p1: ok
php-fpm-5.5.14:gettext-0.19.1p0 (installing)|***************************************                                                  | 44%debug2: channel 0: window 999041 sent adjust 49535
php-fpm-5.5.14:gettext-0.19.1p0: ok
php-fpm-5.5.14:femail-0.98: ok
php-fpm-5.5.14:femail-chroot-0.98p2: ok
php-fpm-5.5.14:libxml-2.9.1p1: ok
php-fpm-5.5.14:php-5.5.14p0: ok
php-fpm-5.5.14: ok
The following new rcscripts were installed: /etc/rc.d/php_fpm
See rc.d(8) for details.
Look in /usr/local/share/doc/pkg-readmes for extra documentation.
--- +php-5.5.14p0 -------------------
To enable the php-5.5 module please create a symbolic link from
/var/www/conf/modules.sample/php-5.5.conf to
/var/www/conf/modules/php.conf. As root:

    ln -sf /var/www/conf/modules.sample/php-5.5.conf /var/www/conf/modules/php.conf

The recommended php configuration has been installed to:
    /etc/php-5.5.ini.
  1. Let’s start php-fpm:
sudo /etc/rc.d/php_fpm start
php_fpm(ok)
  1. Configuring nginx! Hey.. What? Aren’t we going to install nginx? No ma friend.. Apache was killed by openbsd team and now Nginx become part of the base install. Cool eh? So, just open using “vi” of couse, not vim because OpenBSD guys doesn’t trust in vim in default installation. So, let’s use vi
sudo vi /etc/nginx/nginx.conf
  1. This is a example that what you have to change in /etc/nginx/nginx.conf to make this guy working well:
worker_processes  1;

worker_rlimit_nofile 1024;
events {
    worker_connections  800;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    index         index.php index.html index.htm;
    keepalive_timeout  65;
    server_tokens off;

    server {
        listen       80;
        listen       [::]:80;
        server_name  localhost;
        root         /var/www/htdocs;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root  /var/www/htdocs;
        }
        location ~ \.php$ {
            try_files      $uri $uri/ =404;
            fastcgi_pass   unix:run/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

  1. Let’s restart our nginx:
sudo /etc/rc.d/nginx -f restart
  1. Testing!
sudo vi /var/www/htdocs/index.php
  1. And add this:
<?php
phpinfo();
  1. Test using your public ip, and you’ll see the phpinfo page!

If you get any problems feel free to contact me!
Thanks!

Rodolfo

Last modified:

LinkedIn
WhatsApp