Using Apache httpd with PHP
Run PHP in Apache httpd
Me
272 Words 1 Minute, 14 Seconds
22 Oct 2025
Apache2 with PHP (without FPM)
OpenBSD comes with its own HTTP server named httpd, but it's possible to install Apache httpd "Apache2".
Installing Apache httpd with PHP
Apache httpd is a dependency of the package php-apache, so if you plan to use PHP you can just enter the following command:
doas pkg_add php-apacheChoose the version (the higher is better) and submit. The package apache-httpd will be installed too because it's a dependency of php-apache. You could have installed apache-httpd alone instead.
Apache httpd can be enabled / disabled using rcctl like any services, and it can be controlled by the apachectl command.
Enabling PHP module
To enable the PHP module in Apache httpd, you can edit the file /etc/apache2/httpd2.conf:
Find the area in the file where all the LoadModule are and add the following line below. Don't forget to change the PHP version to match the one you installed.
LoadModule php_module /usr/local/lib/apache2/php-8.4/libphp.soEnabling PHP handler
By default, PHP files aren't executed, it's needed to enable the PHP handler.
In /etc/apache2/httpd2.conf locate the "IfModule mime_module" section, and add the following inside:
AddType application/x-httpd-php .php
AddHandler php-script .phpInstalling and enabling PHP extensions
You can find available PHP extensions by running the following command:
pkg_info -Q php-To install an extension, here pdo_mysql, run the following command:
doas pkg_add php-pdo_mysqlAlways be sure to select the same PHP version that you installed when asked.
To enable the extension, copy the file or create a symlink:
doas ln -s /etc/php-8.4.sample/pdo_mysql.ini /etc/php-8.4/pdo_mysql.iniEdit PHP configuration
The PHP configuration can be found and edited in /etc/php-8.4.ini.
Restart Apache httpd after editing PHP configuration:
doas apachectl restart