June 18, 2013
Apache is not executing PHP scripts
User2495173’s Question:
I changed the httpd.conf as follows:
-
Replaced
DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
with
DocumentRoot "C:/Temp/WebServerCore/Binaries/html"
-
Replaced
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
with
<Directory "C:/Temp/WebServerCore/Binaries/html">
However Apache does not recognize the php code in my .html file. What other changes do I need to make for Apache to execute PHP?
It is by design. Apache will not parse PHP code inside a HTML file by default. You can include HTML codes in a PHP file as you would code them in a HTML document.
Renames your files and add extension .php
at the end they will parsed as you want.
Or you can configure your apache configuration (httpd.conf) to parse PHP code inside HTML too.
AddHandler application/x-httpd-php5 .html .htm
Or you can match extension and set their handlers like
<FilesMatch ".(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>