It may not seem like php is working in MAMP

I am trying to learn php, and step one is to get php to work in some quality. I am trying to use MAMP, but I am having problems.

In particular: if I create a file with the code below and save it as index.html in the MAMP "Document Root" directory, I get a blank page when my browser points to http: // localhost: 8888 / index.html .

the code:

<html> <body> <?php echo "Hello World!"; ?> </body> </head> 

Alternatively, if I put a little php in my own file (say test.php) and then point my browser in that file, it just displays the full text of the file in the browser.

Any ideas what I can do wrong?

+6
source share
4 answers

You must save the file with PHP inside it with the extension .php. Therefore, you will need to name it index.php instead of index.html . Simple fix.

+5
source

I had a similar problem.

Create a new file in TextWrangler or Komodo or something else, and add the following code:

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

You are about to save the file as .htaccess (with a dot at the beginning, this is the name of the file). Save it to / Applications / MAMP / htdocs. This is the same place where you save the php and html files. This .htaccess will be an invisible file; you will not see it in Finder, you can, if you connect to it in the terminal, or search in Finder and select the type of file visibility under Kind.

Now try switching to localhost: 8888 / and you will see all the files there. And with this newly created .htaccess file, you can now embed php inside the html file.

+12
source

In MAMP, edit the file:

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

and then search for '#AddHandler type-map' (exclude quotation marks). Below add

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

Save the file and stop and run MAMP again. PHP analysis will occur in files ending with extensions: .php and .html.

+3
source

So this just worked for me:

instead of:

MAMP / HTDOCS / folder-containing-all files /

put all your files directly in the htdocs folder!

So:

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

Hope this helps!

0
source

Source: https://habr.com/ru/post/909905/


All Articles