Php /

Install PHP for OpenHTTPd

Install

$ doas pkg_add php-8.0.8
$ doas rcctl enable php80_fpm
$ doas rcctl start php80_fpm

Then, in /etc/httpd.conf, add the following block:

server "example.com" {
        listen on * port 80
        location "/.well-known/acme-challenge/*" {
                root "/acme"
                request strip 2
        }
        location "*.php" {
                fastcgi socket "/run/php-fpm.sock"
		root "/htdocs/example.com"
        }
}

Lines 3-7, the location "/.well-known/acme-challenge/*" block, is for acme-client, for requesting new SSL certs.

Lines 8-11, the location "*.php" block, tells the web server to use PHP for any file that ends with a .php file extension.

Line 10 says where the document root is located -- where web files should be placed. By default, openhttpd chroots into /var/www, so if your document root is /htdocs/example.com, then your actual web files need to be placed in /var/www/htdocs/example.com.

NOTE: Make sure to replace example.com with your real domain.

To test your installation, create the file /var/www/htdocs/example.com/index.php:

<?php phpinfo(); ?>

Then, have your web browser visit http://example.com/ . If you set everything up correctly, you should see a screen full of PHP installation information.

For SSL, you will want to follow the OpenHTTPD TLS? or relayd guides.

Troubleshooting

If you run into any PHP configuration errors, check the logs folder in /var/www/logs:

$ less /var/www/logs/access.log
$ less /var/www/logs/error.log

Files

File PathPurpose
/var/www/logs/access.logWeb access logs
/var/www/logs/error.logWeb error logs