browers not passing script to PHP

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
woodplaner
Forum Newbie
Posts: 13
Joined: Sun Jan 02, 2011 8:12 am

browers not passing script to PHP

Post by woodplaner »

Hello. I can run a PHP script from the URL line by http://localhost/script_name.php. When the same script is embedded into my index.html file, the file runs without executing the php. I understand that the browser is not passing the script to PHP, and the problem is prob a config file. The config files appear to be in place, but I am unsure if it (or they) are located improperly or if the info it contains is not proper or missing.

I am running Apache2 and PHP5. The index.html file is located /var/www/index.html. I appreciate your suggestion to solve this problem.

Thanks
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: browers not passing script to PHP

Post by Doug G »

The obvious solution is "don't put php script in a .html file"

But if you must, you need to configure apache so it understands a .html file needs to go to the php interpreter.
woodplaner
Forum Newbie
Posts: 13
Joined: Sun Jan 02, 2011 8:12 am

Re: browers not passing script to PHP

Post by woodplaner »

Doug G. Thanks for the reply. I am new to php and html, so my language may be a bit imprecise. By script, I am referring to <?php
phpinfo();
?>
I am surprised at your suggestion not to include php in html files. I thought that was one of the benefits of using php.

How do I change the apache configuration to send .html file to the php interpreter? Is there a particular directive to change?

Thanks
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: browers not passing script to PHP

Post by Doug G »

apache figures what do with a page based on the file extension. A .html extension doesn't inform apache it needs to send the page through php, so apache doesn't. The .php extension, however, does tell apache to send the page through the php processor.

Somewhere in httpd.conf (or whatever it's called with your apache) you'll find settings that can change how apache interprets an .html page. I don't do this kind of change, I don't know the exact setting.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: browers not passing script to PHP

Post by s.dot »

You can embed HTML into a .php file. You cannot embed PHP into an .html file (without special server configuration).

index.html (won't work with php code in it)
index.php (will work with html/php in it)

Assuming apache is correctly configured to parse .php extensions with php
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
woodplaner
Forum Newbie
Posts: 13
Joined: Sun Jan 02, 2011 8:12 am

Re: browers not passing script to PHP

Post by woodplaner »

Doug G and s. Dot. The httpd.conf file exists, but there is nothing there, so I will pursue the reason. index.php did run with html and the three lines of php, but it did not work well with the linked css file.

Thanks
Post Reply