cannot enable php8.2 with Apache2 compiled from sources

cannot enable php8.2 with Apache2 compiled from sources

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

cannot enable php8.2 with Apache2 compiled from sources

When you compile Apache from source, particularly alongside a custom OpenSSL build, the standard Debian/Ubuntu packaging utilities like a2enmod often fail to function as expected. The core issue in your scenario isn't necessarily that PHP is missing, but rather that the integration mechanism relies on finding specific .so files and configuration snippets in paths that a source-built Apache does not search by default.

The command sudo a2enmod php8.2 attempts to modify /etc/apache2/mods-available/php8.2.load and symlink it to the mods-enabled directory. This process assumes that Apache is looking for PHP modules at /usr/lib/php/... or similar standard library paths, and that the configuration file includes a line pointing to LoadModule. However, if you compiled Apache from source in /usr/local/apache2, your binary is likely hardcoded to look for modules relative to its own installation prefix (e.g., /usr/local/apache2/modules/).

If you run sudo a2enmod php8.2 and see no changes or errors, it usually means the module loader isn't finding the PHP Shared Object (.so) file in the expected location. When you request /test.php and only see raw code, Apache has successfully served the static file because the PHP handler is not registered in the httpd.conf or its included configuration files.

To resolve this, you must manually ensure that the PHP module is loaded by your custom-built Apache. First, verify where the PHP module was installed during the compilation process. If you followed a standard tutorial for compiling PHP 8.2 with OpenSSL, the .so file is likely located at /usr/local/lib/php/20240924/php8.so or similar, depending on your specific ./configure flags and build options.

You need to explicitly add a LoadModule directive in your Apache configuration. Open your main config file (often found in /usr/local/apache2/conf/httpd.conf) or the include directory used by your source build. Add the following line, ensuring the path matches exactly where your PHP module resides:

LoadModule php_module /usr/local/lib/php/20240924/php8.so

Next, you must define a handler for files with the .php extension. Without this, Apache treats .php files as plain text, which explains why you are seeing the raw code in your browser. Add these directives to your httpd.conf:

AddType application/x-httpd-php .php
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

You also need to ensure that PHP's internal configuration is included. If you installed PHP with the --enable-mbstring or similar options, the php.ini file should be loaded via an Include directive:

Include /usr/local/lib/php/20240924/php.ini

Regarding your observation about a2enmod: it is normal for this command to make no visible changes if it cannot locate the module definition files in /etc/apache2/mods-available. Source-built software often bypasses these system directories entirely, installing everything under /usr/local. In such cases, you must manage your configuration manually.

If you are planning to stream a video using FFPlay over HTTPS with your custom OpenSSL, ensure that your SSL certificates are correctly configured in the ssl.conf or an equivalent file within your source build's config directory. You will need to verify that the LoadModule ssl_module is present and that your SSLCertificateFile and SSLCertificateKeyFile point to valid paths relative to your custom installation.

A common pitfall when mixing source-built Apache with system-installed PHP (or vice versa) is a mismatch in the OpenSSL versions. Since you mentioned using a custom OpenSSL version, ensure that the openssl.so library linked during the PHP compilation matches the one provided by your custom build. If they differ, PHP may fail to initialize silently or throw fatal errors when accessed via phpinfo().

For a robust setup involving streaming and secure connections, consider isolating your SSL configuration in a dedicated file included at the end of your main config to keep things organized. This approach minimizes conflicts between system packages and custom compilations.

Our network