简体   繁体   English

无法在MAMP中执行PHP

[英]Can't execute PHP in MAMP

I installed MAMP in my macbook with osx mavericks, all preferences are the defaults. 我在Macbook上使用osx小牛安装了MAMP,所有首选项均为默认设置。 I copied my test.html to /Applications/MAMP/htdocs and go to http://localhost:8888/test.html and the display is: one three 我将test.html复制到/ Applications / MAMP / htdocs并转到http://localhost:8888/test.html ,显示为: one three

and the test.html file: 和test.html文件:

<html>
<head>
<title>Example</title>
</head>
<body>
one
<?php
echo 'two ';
?>
three
</body>
</html>

The 'two ' of php doesn't appear, anyone knows why? PHP的“ Two”没有出现,有人知道为什么吗?

Your file is being brought to the browser as an html file. 您的文件作为html文件被带到浏览器。 Your server will look to the file extension (in your case .html) in order to figure out what to send to the browser. 您的服务器将查找文件扩展名(在您的情况下为.html),以便确定向浏览器发送的内容。 You need to change the extension to .php so your server will run the php code and then send the resulting html doc to your browser. 您需要将扩展​​名更改为.php,以便您的服务器运行php代码,然后将生成的html文档发送到您的浏览器。

Another option will be to go to the MAMP folder inside Application, and open httpd.conf (~/Application/MAMP/conf/apache/httpd.conf), then add this to the last line 另一个选择是转到应用程序内的MAMP文件夹,然后打开httpd.conf(〜/ Application / MAMP / conf / apache / httpd.conf),然后将其添加到最后一行

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

You will need to restart Apache for the changes to take place. 您将需要重新启动Apache才能进行更改。 You can do that by going to the MAMP window and then clicking "Stop Servers" and "Start Servers". 您可以通过转到MAMP窗口,然后单击“停止服务器”和“启动服务器”来做到这一点。 PHP code will be executed inside .html files afterwards. 之后,PHP代码将在.html文件中执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM