jkjenner
jkjenner

Reputation: 450

can't seem to get php working in MAMP

I'm trying to learn php and step one is getting php working in some capacity. I'm attempting to use MAMP but I'm having some trouble.

Specifically: if I create a file with the below code and save it as index.html in MAMP's "Document Root" directory, I get a blank page when pointing my browser at http://localhost:8888/index.html.

Code:

<html>
<body>

    <?php
    echo "Hello World!";
    ?>

</body>
</head>

Alternatively, if I put a bit of php into its own file (say test.php) and then point my browser at this file, it just displays the full text of the file in the browser.

Any ideas what I might be doing wrong?

Upvotes: 7

Views: 17405

Answers (5)

odbdux
odbdux

Reputation: 43

Modifying /Applications/MAMP/conf/apache/httpd.conf

searching for #AddHandler type-map

and inserting AddHandler application/x-httpd-php .php .html

worked for me.

Upvotes: 0

Ralph Frost
Ralph Frost

Reputation: 81

In MAMP, edit the file:

/Applications/MAMP/conf/apache/httpd.conf

and then search for '#AddHandler type-map' (exclude quotes). Below that, add,

AddHandler application/x-httpd-php .php .html

Save the file and stop and re-start MAMP. Php parsing will occur in files ending with the extensions: .php and .html.

Upvotes: 7

Roanna Sold
Roanna Sold

Reputation: 21

So, this just worked for me:

instead of having:

MAMP/htdocs/folder-that-contains-all-files/

put all your files directly in the htdocs folder!

so:

MAMP/htdocs/all your files including index.php etc.

Hope that helps!

Upvotes: 2

Thomas
Thomas

Reputation: 121

I had the similar issue.

Make a new file in TextWrangler or Komodo, or whatever, and add the folllowing code:

AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php .html .htm

You're going to save the file as .htaccess (with the dot in the front; this is the file name). Save it in /Applications/MAMP/htdocs. This is the same place you'll save your php and html files. This .htaccess will be an invisible file; you will not see it in Finder, tho you can if you cd to it in Terminal, or searching w/in Finder and choosing the File Visibility type under Kind.

Now try going to localhost:8888/ and you should see all of the available files there. And with this newly created .htaccess file, you can now embed php inside an html file too.

Upvotes: 12

Joe Torraca
Joe Torraca

Reputation: 2018

You must save a file with PHP inside it with a .php extension. So you would need to name it index.php instead of index.html. Simple fix.

Upvotes: 5

Related Questions