Secret Sauce, OpenBSD, NGinx and PHP


I’ve been struggling with getting nginx and php to be friendly to each other in OpenBSD.

Read all the wonderful allocates for nginx and thought it was time to test the waters when OpenBSD embraced the web server by incorporating it into the Base build.

Successfully deployed html serving nginx, reverse proxy nginx, and now I really really need to get PHP hosting, and SSL hosting to work. All the documentation out there says it is sooo simple, but why haven’t I been able to do it for the 1st 3 tries?

  • pkg_add nginx
  • pkg_add php-fpm

Ingredient #1

As always, the key thing to (L)earning something new is, not to chew off more than you can.

So, if you’re going to try something new. Take a list of the minimal ingredients, and only work with those ingredients.

Like the fool I am, I tried the new install using a mix of the base install of nginx with the package install.

  • nginx is in the base install of 5.2
  • unless you really know what you’re doing, just use that.

Ingredient #2

Basics Works.

Keep your above, simplified environment, sane.

Don’t be like me, where I’m mixing things randomly.


  • install nginx web server package
  • install php-fpm package for PHP FastCGI
  • /etc/rc.d/nginx start (base install) works (typo)
  • change configurations
  • /etc/rc.d/enginx restart (ports install) everything html works, php breaks.
  • confirm /etc/php-fpm.conf has chroot enabled
  • /etc/rc.d/enginx restart everything breaks
  • read documentation, ooops nginx package is not yet chroot
  • edit /etc/php-fpm.conf has chroot disabled
  • /etc/rc.d/enginx restart everything breaks

When I finally realised:

  • php-fpm configuration sample is chroot
  • nginx base install is chroot
  • nginx package install is not chroot

My random behaving system isn’t so random after all. It just took a long time to realise this.

The php-fpm sample configuration file is chroot (just like the default Apache 1.3 chroot base install.)

Ingredient #3

Don’t get ahead of myself. Why am I installing the nginx package?

  • There’s mention that there are some features supported in ports that aren’t available in the base install
  • There’s a new version on the web, and I may need some of those features?
  • My install is going live and will need to add features along the way, do I need those non-base install features?

OpenBSD systems are relatively easy to rebuild, reinstall, just build the basic, feature complete system you require and nothing more.