Anyone help me figure out why php won't run even though I'm using MAMP

Joined
Feb 6, 2011
Messages
2
Reaction score
0
Points
1
First off I am new to the web design/programming world and this will probably be akin to someone posting to an automotive forum "How do I put a spare tire on?"

So I'm trying to get PHP up and running on my MBP. I am new to programming like I said, however I'm not bad at getting into dreamweaver and making changes to get things how I want to look and can get files saved from there opened via Safari/Firefox just fine. Now I'm trying to run a very basic php script (going through a php for absolute beginners page to start to learn it) just so I can check to make sure systems are all running. I've installed MAMP and it turns on fine and shows as everything working there. However when I open up the script I saved (PHPtest1.php) all the code appears along with text rather then the clean text. I'm not sure if I'm leaving out any info you might need but any and all help would be appreciated as I've just lost a ton of time to figuring out something that by all accounts should be quick and painless. I do have "websharing" turned on in my preferencs.


Here is the script that I try to open (and consequently appears in the broswer exactly this way) :


<html>
<head></head>
<body>

Agent: So who do you think you are, anyhow?
<br />

<?php
// print output
echo 'Neo: I am Neo, but my people call me The One.';
?>

</body>
</html>
 
Joined
Jun 18, 2006
Messages
191
Reaction score
5
Points
18
Location
Minneapolis
Your Mac's Specs
MacBook Pro
You have the text marked out with the // and you only need the print or echo command
<?php print "Neo: I am Neo, but my people call me The One."; ?>

Here is a good place to start PHP Tutorial
 
Joined
Apr 7, 2008
Messages
17
Reaction score
2
Points
3
Location
Coeur d' Alene, Idaho
Your Mac's Specs
Macbook Pro, iMac
I had a jolly time getting php working. It wasn't hard, just needed a few defaults in the php.ini file changed... especially the option for "short_tags".

In /etc/php.ini, under Language Options, change

short_open_tag = Off


to

short_open_tag = On

Once I did this, my php files worked.

Also, the first file I would use to verify php is one like this that I made: I make a file called phpinfo.php. In this file I typed:

<?php
phpinfo();
?>


If php is working, you will get a printout of all php's configuration. VERY helpful to diagnose problems.

Hope this helps.

Mike
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I am by no means a PHP expert but I believe the issue has something to do with the permissions on the page. Try the following:

1. Open up Terminal (/Applications/Utilities) and type the following:
Code:
chmod 644
2. Now, drag the php file from Finder onto the Terminal window. The line in the terminal should now something like the following:
Code:
chmod 644 /path/to/phpfile/file.php
Press enter. Reload the page.
 
OP
Z
Joined
Feb 6, 2011
Messages
2
Reaction score
0
Points
1
Before I try fooling with anything in terminal I just wanted to give everyone an update. I tried saving the .php files to sites in "User" on the HD and voila php scripts run beautifully from there. Not sure if this would pinpoint why when saved to MAMP (Applications> Mamp> phpscript.php) php won't run.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top