Install PHP for OpenHTTPd
Install PHP8
$ doas pkg_add php%8
Depending on the version of php you install, you will need to enable different versions of php_fpm. In this example, we install php-8.3:
$ doas rcctl enable php83_fpm $ doas rcctl start php83_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 Path | Purpose |
---|---|
/var/www/logs/access.log | Web access logs |
/var/www/logs/error.log | Web error logs |
Upgrading Notes
If you are upgrading to php8.0 and you have got pmwiki, then make sure that you update your pmwiki, else it will spam your logs and it will be within a minute that you got no space left on /var