Setting up OpenBSD's httpd webserver with PHP Support - OpenBSD's httpd webserver comes installed with OpenBSD, so all you need to do is setup /etc/httpd.conf. Installing and setting up PHP is also very easy. First thing you need to do is setup /etc/httpd.conf which doesn't exist, so you will have to create it. It's definitely worth mentioning that httpd runs in a chroot jail for security purposes. So if your webserver is ever compromised, it won't affect the rest of your system.

Configure your webserver

Below is a sample /etc/httpd.conf file which configures httpd to listen on port 80 and support PHP.

server "default" {
       listen on * port 80
root "/htdocs/"
directory index "index.php" 

location "/*.php*" { 
fastcgi socket "/run/php-fpm.sock" 
   }
}

Install PHP

Now, you need to install and setup PHP. It is very easy to do. First type pkg_add php, then choose the version you wish to install.

# pkg_add php
        0: <None>
	1: php-8.0.28p1
	2: php-8.1.19
	3: php-8.2.6
Your choice: 3

Start httpd and php

Once the installer finishes installing, you need to start httpd and php82_fpm (assuming you chose number 3, the latest release). You will also need to enable these daemons to start automatically when you boot OpenBSD.

# rcctl enable httpd php82_fpm
# rcctl start httpd php82_fpm

Your new webserver is now up and running with PHP support. Below is a sample PHP script, you can name index.php and place in /var/www/htdocs

<?php
phpinfo();
?>

Now just point your browser to your internal ip address i.e, http://10.0.0.157 and you should see your new website.

Relevant pages that might be useful to you
Enable SSL/TLS on OpenBSD httpd
OpenBSD httpd tips and tricks
IPv6 website reachability test


Powered by OpenBSD httpd on a Raspberry Pi | This website is IPv6 enabled