Introduction
Continuing on with my previous article, today I am going through the process of configuring our OpenBSD httpd instance to handle dynamic content such as PHP scripts. The way httpd
will accomplish this is by using the FastCGI protocol. I’ve talked about FastCGI as well as using it with Nginx in this article. So perhaps, you might want to check that out first.
Installing packages
Since we’re going to run PHP scripts, we’ll obviously need the PHP package.
doas pkg_add -z php
Installing this package also includes the php-fpm
script. Let’s start the script.
doas rcctl start php81_fpm
The name contains the version number, so you should keep that in mind.
Configuring httpd
Now we need to tell OpenBSD httpd to use the FastCGI socket for files ending with .php
. Edit /etc/httpd.conf
to look something like the following:
server "openbsd.local" {
listen on * port 80
directory index index.php
location "*.php" {
fastcgi socket "/run/php-fpm.sock"
}
}
Now place a sample index.php
file inside /var/www/htdocs/
. I’ve just gone with the following:
<?php
phpinfo();
?>
Now time for trying out our setup.
And it’s working!
Conclusion
This was a short article, and in a way that’s good. It shows how simple it is to configure OpenBSD httpd
. I highly suggest you read the man page httpd.conf(5)
. It’s nicely written and shouldn’t take longer than 30 minutes to complete.