PHP仍未在MAC OSX 10.10 Yosemite上执行

时间:2021-08-28 02:38:15

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

我不能让PHP在我的电脑上工作。我的浏览器打印出PHP代码而不是执行它。

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

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

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:

然后我使用以下命令重启apache:

    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:

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

    <?php phpinfo(); ?> 

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

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

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

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

    User myusername 

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

我已经尝试将“DirectoryIndex index.html”行更改为:

    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脚本。任何帮助,将不胜感激!

1 个解决方案

#1


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

将test.php放在/ Library / WebServer / Documents中。

Make sure you have

确保你有

 <?php phpinfo(); ?> 

inside your test.php

在你的test.php里面

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

打开Chrome。转到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.

你不能使用Chrome打开test.php文件。 PHP脚本需要由PHP编译器执行才能看到任何输出。如果您只是在chrome中打开PHP文件,它将只显示PHP代码。

#1


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

将test.php放在/ Library / WebServer / Documents中。

Make sure you have

确保你有

 <?php phpinfo(); ?> 

inside your test.php

在你的test.php里面

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

打开Chrome。转到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.

你不能使用Chrome打开test.php文件。 PHP脚本需要由PHP编译器执行才能看到任何输出。如果您只是在chrome中打开PHP文件,它将只显示PHP代码。