Extended Brain Storage

OpenBSD: HTTPD with PHP Support

Posted on September 19, 2016

A quick introduction to install PHP) support to httpd in OpenBSD


Currently, there is a lot of web server software available and it’s up to anyone to decide for themselves which one to choose. OpenBSD comes with a built-in HTTP daemon called httpd, which is a HTTP server with TLS and FastCGI support (i.e. a binary protocol for interfacing interactive programs such as PHP).

The installation of httpd is outlined in OpenBSD: HTTPD with TLS Support Using ACME. Therefore, the following lines deal with PHP-related notes only.

PHP Installation

PHP: Hypertext Preprocessor (PHP) is a server-side scripting language designed for web development but also used as a general-purpose programming language. In OpenBSD 6.2, there are two versions of PHP available. The currently installed version (if any) can be checked as follows:

$ pkg_info -I php
php-5.6.31          server-side HTML-embedded scripting language

It is up to the application requirement, which version of PHP should be installed:

$ pkg_add php
quirks-2.367 signed on 2017-10-03T11:21:28Z
Ambiguous: choose package for php
a       0: <None>
        1: php-5.6.31
        2: php-7.0.23
Your choice: 

PHP Modules

It is up to the application requirement, which PHP modules should be installed. Usually, they are “hardwired” as hard package dependencies. Hence, they are installed along with the application (package). To name a few “typical” PHP modules:

$ pkg_add php-curl php-gd php-intl php-mcrypt php-zip
$ pkg_add php-gmp php-ldap php-pspell php-xmlrpc php-xsl
$ pkg_add php-opcache php-pdo_pgsql php-pgsql

Once installed, the installed and available modules can be checked in:

$ ls -lA /etc/php-*.sample/

In order to enable the desired modules, the following links need to be created for each module (or, they can be copied to the /etc/php-VERSION directory):

$ ln -s /etc/php-VERSION.sample/MODULE.ini /etc/php-VERSION/MODULE.ini

Unless desired otherwise, it is a good practise to update the date.timezone value in:

$ vi /etc/php-*.ini
date.timezone = CONTINENT/CITY

PHP daemon can now be enabled and started as follows:

$ rcctl {enable|start} phpVERSION_fpm

HTTPD and PHP Integration

Considering that the httpd listens only on the default host (i.e. egress IP address and TCP port 80), its configuration needs to be updated as follows:

$ vi /etc/httpd.conf
server "default" {
  listen on egress port 80
  directory {
    index "index.php"
  location "/*.php*" {
    root { "/htdocs/default" }
    fastcgi socket "/run/php-fpm.sock"
  location "/*" {
    root { "/htdocs/default" }

In order to support hosting of different domains (virtual-hosts), the previous setup needs to be applied for each of them.

A PHP-testing webpage can be created as follows:

$ echo "<?php\nphpinfo();\n?>" > /var/www/htdocs/default/index.php

The HTTPd needs to be reloaded:

$ rcctl reload httpd

Tags: #OpenBSD #security #httpd #HTTPS #PHP

⏴ Previous Post Next Post ⏵