Why am I seeing the PHP code in my Browser?
Moderator: General Moderators
Why am I seeing the PHP code in my Browser?
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?
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?
php isnt configured for your mamp as standard mime, use wamp
Re: Why am I seeing the PHP code in my Browser?
ok I'm not sure what that meantjazz090 wrote:php isnt configured for your mamp as standard mime, use wamp
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?
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?
pcoder wrote:Try with the full PHP tag, I mean to say. likeCode: 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?
Hmm...that's odd. You definitely have PHP installed?
Try adding this to your httpd.conf file, if it isn't already there:
Try adding this to your httpd.conf file, if it isn't already there:
Code: Select all
AddType application/x-httpd-php .php-
tom_haire50
- Forum Newbie
- Posts: 5
- Joined: Mon Aug 10, 2009 11:28 am
Re: Why am I seeing the PHP code in my Browser?
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?
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 .phpCode: Select all
AddType application/x-httpd-php .php .phtmlWhat 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?
Hmm....I don't have a mac, so I'm just guessing here...
You could try downloading the PHP binaries and installing it seperately?
You could try downloading the PHP binaries and installing it seperately?
Re: Why am I seeing the PHP code in my Browser?
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?
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:
I opened the php_error.log file and it 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 have no idea what any of this means, but I hope it sheds some light on the situation.[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
Re: Why am I seeing the PHP code in my Browser?
Well it looks like PHP is installed then.
As frao_0 asked, what URL are you putting into your browser?
As frao_0 asked, what URL are you putting into your browser?
Re: Why am I seeing the PHP code in my Browser?
I triedjackpf wrote:Well it looks like PHP is installed then.
As frao_0 asked, what URL are you putting into your browser?
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
The phpinfo.php file by the way, has the following code:
Code: Select all
<?php phpinfo(); ?>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?
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:
What happens if you try http://127.0.0.1/phpinfo.php ?
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 ?
-
tobimichigan
- Forum Commoner
- Posts: 48
- Joined: Sun May 10, 2009 1:35 pm
Re: Why am I seeing the PHP code in my Browser?
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...