r/apache • u/grepnoid • Aug 26 '26
PHP in HTML files displays, doesn't execute
I know there are dozens of pages on this subject, but I've tried most of their suggestions and this seems different.
I have apache2 and php8.2 (libapache etc) installed, on a new VPS install with Debian12.
http://mysite.com/test.php executes the PHP
PHP embedded in the body of http://mysite.com/test.html, as
<?php
echo "<br/>does it work?</br>";
?>displays the text in the page
does it work?
"; ?>Mods enabled, after enmod and dismod of various modules as suggested:
a2query -m
authn_file (enabled by maintainer script)
proxy_fcgi (enabled by site administrator)
authz_user (enabled by maintainer script)
dir (enabled by maintainer script)
env (enabled by maintainer script)
php8.2 (enabled by maintainer script)
setenvif (enabled by maintainer script)
autoindex (enabled by maintainer script)
deflate (enabled by maintainer script)
mpm_prefork (enabled by maintainer script)
negotiation (enabled by maintainer script)
status (enabled by maintainer script)
alias (enabled by maintainer script)
reqtimeout (enabled by maintainer script)
authz_host (enabled by maintainer script)
mime (enabled by maintainer script)
filter (enabled by maintainer script)
authz_core (enabled by maintainer script)
authn_core (enabled by maintainer script)
proxy (enabled by site administrator)
access_compat (enabled by maintainer script)
auth_basic (enabled by maintainer script)The web root where my files are is /var/www/html. I have no .httpaccess file. The apache2.conf is the default which seems to have nothing to prevent normal execution.
View all comments
Show parent comment
1
u/Maude-Boivin-02 Aug 28 '26
That should be in site’s Apache config file:
«
<Directory /> AllowOverride None Order allow,deny Require all granted Allow from all DirectoryIndex default.php
# Direct PHP requests to PHP-FPM via the Unix socket
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.5-fpm-dynamic.sock|fcgi://localhost"
</FilesMatch>
# ==========================================================================
# PHP-FPM STATUS PAGE
# ==========================================================================
# <LocationMatch "^/(status-myapp|ping-myapp)$">
# SetHandler "proxy:unix:/run/php/php8.3-fpm-myapp.sock|fcgi://localhost"
# Restrict access
# Require ip 127.0.0.1 ::1
# Require ip 192.168.0.5
# </LocationMatch>
# Or use TCP (useful if PHP-FPM is on a different machine)
# <FilesMatch "\.php$">
# SetHandler "proxy:fcgi://192.168.0.5:54222"
# </FilesMatch>
«
The <FilesMatch part in my example is for php8.5-fpm specifically… your’s might be different but it’s NOT an AddHandler