Page 1 of 3

Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 9:22 am
by sirab33
Hi All,

Actionscript/Javascript programmer new to PHP, just installed MAMP on my MacBook - no problems, all works well. Successfully configured Dreamweaver to work with Apache/MySql (using official Adobe instructions)- again, no problems.

I'm now trying to run some very basic PHP pages - intro/tutorials type stuff - but they don't work:
-content generated with regular HTML shows up correctly but anything in <?php> tags does not show up at all.
-pages that are exclusively in PHP show up as literal code on the browser, as if I was looking at them in my text-editor.

Obviously there's some issues having to do with PHP being incorrectly interpreted - any ideas on how to fix this?

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 9:27 am
by jazz090
php isnt configured for your mamp as standard mime, use wamp

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 9:54 am
by sirab33
jazz090 wrote:php isnt configured for your mamp as standard mime, use wamp
ok I'm not sure what that meant :-)

I'm working on a Mac and I think WAMP is for Windows users...

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 10:46 am
by pcoder
Try with the full PHP tag, I mean to say. like

Code: Select all

 
<?php
content...
?>
 

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 10:53 am
by sirab33
pcoder wrote:Try with the full PHP tag, I mean to say. like

Code: Select all

 
<?php
content...
?>
 

I don't think the problem is with the tags or the code itself - I'll paste it below so you can see (I got it from an online Tutorial) - I think its some other problem that's preventing the server from interpreting the PHP files correctly.

Here's the code:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>NEO</title>
</head>
 
<body>
 
 
Agent: So who do you think you are, anyhow? 
<br /> 
 
<?php 
// define variables 
$name = 'Neo'; 
$rank = 'Anomaly'; 
$serialNumber = 1; 
 
// print output 
echo "Neo: I am <b>$name</b>, the <b>$rank</b>. You can call me by my serial number, <b>$serialNumber</b>."; 
?> 
 
</body>
</html>
 

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 11:20 am
by jackpf
Hmm...that's odd. You definitely have PHP installed?

Try adding this to your httpd.conf file, if it isn't already there:

Code: Select all

AddType application/x-httpd-php .php

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 11:35 am
by tom_haire50
Are you opening the page http://127.0.0.1/~your_username/test.php . The file has to be saved in your username folder or linked in.

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 12:34 pm
by sirab33
jackpf wrote:Hmm...that's odd. You definitely have PHP installed?

Try adding this to your httpd.conf file, if it isn't already there:

Code: Select all

AddType application/x-httpd-php .php

I'm assuming I have PHP installed because I went through the entire MAMP installation as I described before and it claims to have everything you may ever need (Apache, MySQL, etc.)
And the install went without any glitches, so...

Aa per your suggestions, I opened the "httpd.conf" so as to add

Code: Select all

AddType application/x-httpd-php .php
but found that it already has a similar line:

Code: Select all

AddType application/x-httpd-php .php .phtml
I'm assuming they're pretty much the same thing...?

What else could it be? Are there any type of diagnostics I can run to figure out what might be missing or where the problem might be?

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 1:03 pm
by jackpf
Hmm....I don't have a mac, so I'm just guessing here...

You could try downloading the PHP binaries and installing it seperately?

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 1:06 pm
by frao_0
What is the url? http://127.0.0.1/... ? does it end by .php?

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 1:35 pm
by sirab33
frao_0 wrote:What is the url? http://127.0.0.1/... ? does it end by .php?
Are you opening the page http://127.0.0.1/~your_username/test.php . The file has to be saved in your username folder or linked in.

The READ ME file that came with the MAMP install says the following:
README for MAMP 1.0

- Put your HTML and PHP files in the htdocs folder!
- Database files are stored in the folder db/mysql or db/sqlite.
- MAMP Control is a dashboard widget to control the MAMP servers
- To install the widgets just copy them to ~/Library/Widgets. Please note that the widgets are only working under Mac OSX 10.4 or higher.
- PHP errors are logged in the file logs/php_error.log. If you doubleclick the logfile, the console will be open, which show the last errors.
I opened the php_error.log file and it says the following:
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 83
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 86
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 89
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 92
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 95
[10-Aug-2009 11:57:52] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 98
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 83
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 86
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 89
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 92
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 95
[10-Aug-2009 11:57:56] PHP Notice: Undefined variable: localtheme in /Applications/MAMP/bin/SQLiteManager/include/defined.inc.php on line 98
I have no idea what any of this means, but I hope it sheds some light on the situation.

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 2:00 pm
by jackpf
Well it looks like PHP is installed then.

As frao_0 asked, what URL are you putting into your browser?

Re: Why am I seeing the PHP code in my Browser?

Posted: Mon Aug 10, 2009 2:49 pm
by sirab33
jackpf wrote:Well it looks like PHP is installed then.

As frao_0 asked, what URL are you putting into your browser?
I tried
http://127.0.0.1/~myusername/phpinfo.php

and I get:

Code: Select all

Not Found
 
The requested URL /~xxxxx/phpinfo.php was not found on this server.
 
Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2 Server at 127.0.0.1 Port 80
 
I obviously x'd out my user-name.

The phpinfo.php file by the way, has the following code:

Code: Select all

<?php phpinfo(); ?>
I found this online, seems to be what everyone recommends to use for the most basic troubleshooting.

So the server is seen, but this file isn't.

Since I don't understand this whole "http://127.0.0.1/~username etc" business to begin with (why am I supposed to use this http address? what's unique about it? why not just open a regular PHP file - which is what I'm supposed to be doing anyway?) - so I'm not sure what to suggest or even ask at this point.

But if I may, I'll go over the file-path with you so we can ascertain at least that much is correct:
The file "phpinfo.php" is inside the "htdcos folder", which is inside the MAMP folder, sitting in the APPLICATIONS folder - all as was created during the installation of MAMP and as per the instructions that came with MAMP.
So its: Macintosh/Applications/MAMP/htdocs/phpinfo.php

But its not finding it.

Last thing - my username - this would be the same name that I log in with to my Mac with, correct?
I just wanna make sure where I could find it - in the Accounts tab of System Preferences?

Re: Why am I seeing the PHP code in my Browser?

Posted: Tue Aug 11, 2009 3:49 am
by robnet
If I remember correctly the document root on MAMP is, by default, "/Applications/MAMP/htdocs" so I'm not sure why you need to add your username in..

You can double check your apache config file here: /Applications/MAMP/conf/apache/httpd.conf and look for the line that starts with DocumentRoot. I would expect this:

Code: Select all

 
DocumentRoot "/Applications/MAMP/htdocs"
 

What happens if you try http://127.0.0.1/phpinfo.php ?

Re: Why am I seeing the PHP code in my Browser?

Posted: Tue Aug 11, 2009 5:06 am
by tobimichigan
Rob, u obviously have some conflicting programs more likely web-server-like programs that intermittently interupt php from running. My best advise for you is to uninstall all such... reinstall a webserver like wamp, xampp etc then try re-testing php. Make sure the program files holding mysql is deleted through safe mode. otherwise they'd be more conflicts. Most of these programs are library functions are public routines/functions. Hope this helps...