Experts Round Table Network

Serverside Technology => PHP => Topic started by: Jack on January 09, 2008, 06:39:41 AM



Title: Apache 2.2 and PHP 5 not working
Post by: Jack on January 09, 2008, 06:39:41 AM
Hi all. I am new to this environment and I hope you can help me with my test server running as Localhost on my laptop.

I have installed Apache2.2 and php5 together with MySql 5 and PHPMyAdmin. On the face of it all seems to be working, I can view the Apache test page, phpinfo page and the PHPMyAdmin home page with Mysql database. However, when I try to view an file called test.htm with php code embeded in the html and all I get is the HTML in the localhost browser window not the php. The directory for Apache and php has been changed to D:\www, does this make a difference? Any suggestions please?

Regards
Jack


Title: Re: Apache 2.2 and PHP 5 not working
Post by: GrandSchtroumpf on January 09, 2008, 01:59:27 PM
That's because your Apache server is not configured to process php on files that end in ".htm".
Rename your file from "test.htm" to "test.php" and it should work.
Another solution is to change your Apache configuration, but i don't recommend that.  If you want to work with ".htm" uri's instead of ".php" uri's, then it's better to use mod-rewrite.

Cheers.


Title: Re: Apache 2.2 and PHP 5 not working
Post by: VGR on January 10, 2008, 02:47:02 PM
IMHO you should definitely change this line in your httpd.conf file and then restart Apache :

AddType application/x-httpd-php .php

into :

AddType application/x-httpd-php .php .htm .html .phtml

you'll lose less than 3% CPU speed on pure static HTML but on the reverse side you'll be able NOT to rename all your pages once they get dynamic.
It's better than play silly games with mod_rewrite ;-)


Title: Re: Apache 2.2 and PHP 5 not working
Post by: Jack on January 11, 2008, 10:43:28 AM
I have changed the httpd.conf file as you suggested and its ok now. thank's for your help.
Regards
Jack


Title: Re: Apache 2.2 and PHP 5 not working
Post by: GrandSchtroumpf on January 11, 2008, 12:26:57 PM
> It's better than play silly games with mod_rewrite ;-)
Depends if you want your pages to work on mutualized hosting plans where you often cannot change apache's settings.
And who talked about renaming all the pages?  AFAIK, for the time being, there is only one file named "test.htm".
I love mod-rewrite and pretty uri's.  Decoupling uri and file-name is great for flexibility and ease of management.


Title: Re: Apache 2.2 and PHP 5 not working
Post by: CrYpTiC_MauleR on January 12, 2008, 07:36:35 PM
Also isn't that a security risk running .html and .htm as PHP files. Many times those types of files are assumed trusted serverside and not expected to contain executable PHP code. I suggest still using .php extensions and just make a simple 1 line mod_rewrite rule that will make xyz.html redirect transparently in background to xyz.php so user sees xyz.html in browser but server runs the file xyz.php that way you know only .php files will contain executable code and you limit the risk of some code your's or a 3rd party's from accidentally running malicious code in what would have been a benign .html file.