PDA

View Full Version : [ubuntu] firefox does not open php files



migsy16
August 17th, 2010, 12:07 PM
Hi! Firefox doesnt read php files. my files are located at /var/www. html files are displayed without problems. Am I missing anything on my apache config? I've tried Modifying my apache2.conf file by adding an AddType ...... Any insight would be appreciated. Thanks.

DaithiF
August 17th, 2010, 01:02 PM
firefox (or any browser for that matter) does not read & execute the php in php files. you need php to be installed on the server then when serving a php file the server executes the php code, generates (usually) html output, and serves that html to your browser. have you installed php?

migsy16
August 17th, 2010, 01:19 PM
I made a file info.php which basically just contains <?php phpinfo() ?> and firefox was able to parse it. I tried to make a basic html file with a .php extension and it wouldnt load up on my browser. I have checked my php version using dpkg -l|grep -i php and it says I've got PHP 5 on. I am deeply puzzled .....thanks for the quick reply....

DaithiF
August 17th, 2010, 01:32 PM
you're sure its not just firefox caching an earlier blank version of the file? do a force-reload (ctrl + F5) of the page to check.

migsy16
August 17th, 2010, 01:58 PM
I've tried emptying my cache...... no go.......this is disturbing...... grrrrrr

ricks.wesley
August 17th, 2010, 02:02 PM
i am facing the same problem..please help me out of this..

mitsios
August 17th, 2010, 02:13 PM
Post your php file so we can see it.

Cilph
August 17th, 2010, 02:16 PM
PHP is a server-side script. Firefox is not ever supposed to receive and/or read a PHP file. Check your webserver settings because Firefox is supposed to receive plain HTML.

mitsios
August 17th, 2010, 02:25 PM
In order for Apache to parse php files, you need to access the file from firefox by its http address, "http://127.0.0.1/<path to file>"

migsy16
August 17th, 2010, 02:34 PM
<?php
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Basic</title>
</head>
<body>
<?php echo "trial"; ?>
</body>
</html>
?>



TNX!!!

WorMzy
August 17th, 2010, 02:41 PM
If you are trying to view the page through your server (e.g. http://127.0.0.1/pagename.php or http://localhost/pagename.php), then you may have an error in your code. Post it here and we'll take a look, or enable error reporting in the php.ini file and see where the error is being found.

You can edit php settings by editing /etc/php5/apache2/php.ini, e.g.
gksu gedit /etc/php5/apache2/php.ini

After you've made your changes and saved the file, restart the webserver by running

/etc/init.d/apache2 restart
Or possibly

sudo service apache2 restart
I forget what Ubuntu uses these days.

WorMzy
August 17th, 2010, 02:45 PM
<?php
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Basic</title>
</head>
<body>
<?php echo "trial"; ?>
</body>
</html>
?>


The start "<?php" and end "?>" are superfluous. You're telling the PHP parser that all the code after the opening tag is PHP, which it isn't.

You code should look like this:



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Basic</title>
</head>
<body>
<?php echo "trial"; ?>
</body>
</html>

migsy16
August 17th, 2010, 02:45 PM
I think there might have been a problem with the dtd...... ive tried a different dtd for my html and it worked.... i still dont know why an xhtml strict would not parse though......thanks for all your help

WorMzy
August 17th, 2010, 02:48 PM
There's nothing wrong with the DTD, I always use Strict (or HTML5) for my PHP pages.

migsy16
August 17th, 2010, 02:48 PM
tnx worMzy.... I tried it without the PHP tags......and it still didnt work....I tried a different dtd and minus the php tags just as what wormzy described and it finally worked ......Thanks everyone! :)

migsy16
August 17th, 2010, 02:50 PM
funny how mine got an error with the dtd i posted ...... it worked right after i replaced it with a different dtd......hmmmmm

mitsios
August 17th, 2010, 02:57 PM
<removed>

WorMzy
August 17th, 2010, 03:00 PM
If you're really serving it as XHTML with the application/xhtml+xml MIME type, then you'll get an error from the lack of paragraph tags around the text. You could add those and see if it fixes things.