PHP仍未在MAC OSX 10.10 Yosemite上执行

PHP仍未在MAC OSX 10.10 Yosemite上执行

问题描述:

I cannot get PHP to work on my computer. My browser prints out the php code rather than executing it.

The first thing I did was to open up the apache conf file and edit it to uncomment the php line

Opened file:

    sudo nano /etc/apache2/httpd.conf

This is the line I uncommented in that file:

    LoadModule php_module libexec/apache2/libphp5.so

I then restarted apache using:

    sudo apachectl restart

Apache would run, http://127.0.0.1 would show "It works!" I then created a file called test.php, in which I put the following line of code:

    <?php phpinfo(); ?> 

In chrome I clicked file -> open file -> test.php, and all it printed was the code I had written.

I've also tried changing the line "User _www" in the conf file to

    User myusername 

I've tried changing the line "DirectoryIndex index.html" to:

    DirectoryIndex index.php index.html index.htm 

None of these changes have resulted in PHP script executing on my computer. Any help would be appreciated!

我无法让PHP在我的计算机上运行。 我的浏览器打印出PHP代码而不是执行它。 p>

我做的第一件事就是打开apache conf文件并编辑它以取消注释php行 p>

打开文件: p>

  sudo nano /etc/apache2/httpd.conf
nn

这是我在该文件中取消注释的行: p >

  LoadModule php_module libexec / apache2 / libphp5.so 
  code>  pre> 
 
 

然后我使用以下命令重新启动apache: p> \ n

  sudo apachectl restart 
  code>  pre> 
 
 

Apache将运行, http://127.0.0.1 会显示“它有效!” 然后我创建了一个名为test.php的文件,其中我放了以下代码行: p>

 &lt;?php phpinfo();  ?&GT;  
  code>  pre> 
 
 

在Chrome中我点击了文件 - &gt; 打开文件 - &gt; test.php,所有打印的都是我写的代码。 p>

我也尝试将conf文件中的“User _www”更改为 p>

  User myusername 
  code>   pre> 
 
 

我尝试将“DirectoryIndex index.html”行更改为: p>

  DirectoryIndex index.php index.html index.htm  
  code>  pre> 
 
 

这些更改都没有导致我的计算机上执行PHP脚本。 任何帮助,将不胜感激! p> div>

Put the test.php in /Library/WebServer/Documents .

Make sure you have

 <?php phpinfo(); ?> 

inside your test.php

Open Chrome. Go to http://localhost/test.php

You cant just open test.php file using Chrome. PHP script needs to be executed by a PHP Compiler before you can see any output. If you simply open the PHP file in chrome, it will show you the PHP code only.