0

I am trying to display my php files but all I seem to get is the source code. I am running mac 10.7.5 I have installed MAMP and added a file (test.php) to the htdocs folder. I have turned the apache server on.

the code in the file is

<html>
  <head>
    <title>:-)</title>
  </head>
  <body>
    <?php
      echo "<p>Hello, world. I'm a php file.</p>";
     ?>
  </body>
</html>

and when I point my browser (chrome) to this file it shows the source code exactly as above.

Any help would be great!

Thanks.

7
  • you need to add the php support to your httpd.conf file Commented Oct 3, 2013 at 9:41
  • 1
    What URL are you entering ? It should be something like http://localhost.... Also make sure php files have the right file extension. Commented Oct 3, 2013 at 9:42
  • 2
    Are you browsing to the file using http://localhost/ or http://127.0.0.1/? Commented Oct 3, 2013 at 9:42
  • 1
    I am using file:///Applications/MAMP/htdocs/test.php Commented Oct 3, 2013 at 9:43
  • 1
    Guessed as much :) . That's the problem and it's absolutely normal it's showing you the code. Find the equivalent URL to access it through the web server. Commented Oct 3, 2013 at 9:44

1 Answer 1

3

The issue is that you're accessing the script using the file protocol. I guessed as much as I've hit the snag more than once after some late night coding :) .

Try accessing it using the address such as http://localhost/yourfolder/test.php. The part after localhost is relative to htdocs. If MAMP is up and running this will trigger an HTTP request to Apache and get PHP to interpret the file.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you soooo much! how stupid of me... you have saved me from pulling my hair out!
Great. Happy to avoid someone else going bald ;) . Click the tick icon to the left to indicate you've accepted the answer and have a nice day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.