0

I have been trying to setup an environment to develop php and html on my windows 10 machine. I've spent all evening and finally I believe I have Apache 2.4 and php 7 installed correctly as I can correctly execute info.php () through the localhost:667/info.php.

However, any php inside my html docs located in localhost:667 (apache24/htdocs) does not work.

Here are the lines I added to apache/httpd.conf:

LoadModule php7_module "c:/php/php7apache2_4.dll"
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php
DirectoryIndex index.html index.php
#configure the path to php.ini
PHPIniDir "C:/php"

...as well as redefining the listening port as default 80 was conflicting with something.

I renamed php/php.ini-development to php.ini as instructed by an installation manual, and have uncommented the line:

extension_dir = "ext"

as per installation instructions.

Why is the php in my html files still not executing and being shown raw in the source output? Thanks in advance and let me know if you need more information.

  • PHP in html files will never be displayed. Only PHP in PHP files. They have to end with .php – larsAnders Apr 26 '16 at 23:27
  • Unless you configure that differently in php.ini. – GolezTrol Apr 26 '16 at 23:43
  • Just for the record. You mean *executed*. The code is not executed and therefore its *output* is not displayed. Because it is not executed, the code itself is outputted as-is (probably). But your browser doesn't recognize `` as a valid tag and just doesn't render it. If you view the source of your page, though, you will probably see the PHP source code. If so, this is a bad thing. The code should run on the server and not be visible in the browser. – GolezTrol Apr 26 '16 at 23:50
  • yes you are totally correct. I just have a simple embedded in html page which isn't executing and is viewable in the page's source code through the browser, both ff and chrome. however code in .php extensions works fine. what would cause the server to fail to recognise tag when parsing html pages? – Aaron Saluci Apr 27 '16 at 08:04
  • So simply redefining all my html extensions as php would solve the problem I am guessing.Is there a downside to this? doesn't seem right that I must change extension just to serve some php in an html document. My confusion was that last time i used this system this wasn't the case - one could just inline the php and the server would recognise it. I could change all the html extensions to php but does this introduce any other complexities/disadvantages? otherwise how do I setup to enable php to be parsed in an html extended file? – Aaron Saluci Apr 27 '16 at 08:08

1 Answers1

0

Ok so Apache 2.4 httpd.conf isn't setup to parse php embedded in .htm/.html extensions by default. Adding the line

AddHandler php7-script .php .html .htm

...to the file fixed this issue.

Sigh. Seems obvious now I see it. At least I have learned something. Seems documentation provided by php to install their product isn't exactly extensive. I get the feeling php is a little neglected. I am behind on the times, are people using another other methods now?

Thanks for all participants.

  • Thanks! This worked for me. Also on my machine, the config file is apache2.conf and not httpd.conf. I looked everywhere for that one! – Linnea Huxford Dec 24 '16 at 19:54