MAMP - Apache显示源代码HTML和PHP页面[关闭]

I am trying to install Apache on my Mac (OSX 10.8.2).

I am using MAMP, it runs, but whenever I try to view a page (html or php) other than the phpinfo.php, I only see the source code.

There are no errors in the log file.

I have also tried with the pre-installed webserver, same result. Same for XAMP.

How can I get the server to interpret the logic instead of printing it?

Try typing instead of localhost 127.0.0.1 like 127.0.0.1/index.php

Educated guess. You've tried this code and it runs flawlessly:

<?php
phpinfo();
?>

Now you've copied some PHP code that looks like this:

<?
foo();
bar();
?>

... and it's being ignored by the PHP interpreter. Please note the important difference: <?php vs <?.

If that's they case, you need to do one of these:

  1. Replace your short open tags with <?php.
  2. Enable short open tags either in .htaccess or your php.ini file. You'll find the path to php.ini in the outout of phpinfo().