MAMP not processing PHP

2020-05-06 08:23发布

问题:

So I was working with MAMP on my Macbook Pro (running OS X 10.10) and it was working fine, but now MAMP wont process PHP at all.

I have a file named 'index.php' in /MAMP/htdocs/

It contains only one line (minus the first space before the opening ?):

< ?php echo "hello"; ?>

MAMP runs just fine, but when I load the file it just outputs the code directly

http://imgur.com/a/Ay6km#1

If I include some simple HTML in the index.php, like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <?php echo "hello"; ?>
</body>
</html>

Then it simply adds the PHP line as a comment to the file.

http://imgur.com/a/Ay6km#2

I made sure to uncomment the LoadModule line in the /private/etc/apache2/httpd.conf file. I had to add the AddModule line because it wasn't anywhere in the file.

I've reinstalled MAMP with no difference. MAMP is running PHP v5.5.14, cache is turned off.

I've tried just using a simple Apache server (after stopping MAMP and restarting) by running sudo apachectl start, and I don't get any errors in Terminal, but when I try to load http://localhost the webpage is not found.

Anyone have any advice? Is there a place I can check for errors?

edit: a copy of my httpd file has been added to the comments

回答1:

The PHP documentation says that httpd.conf should have the following lines:

<IfModule mod_php5.c>
    # If php is turned on, we respect .php and .phps files.
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    # Since most users will want index.php to work we
    # also automatically enable index.php
    <IfModule mod_dir.c>
        DirectoryIndex index.html index.php
    </IfModule>
</IfModule>

This block is missing from your file.

Check the other steps at the above documentation link as well.



标签: php apache mamp