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"


    DocumentRoot "C:/Temp/WebServerCore/Binaries/html"
  • Replaced

    <Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">


    <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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!