php 为什么php没有运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18086011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:57:50  来源:igfitidea点击:

Why is php not running?

phpapacheubuntuamazon-web-services

提问by Christian

I've seen this question answered many times, but most end either unanswered or by telling the asker to put this:

我已经多次看到这个问题得到了回答,但大多数人要么没有回答,要么告诉提问者提出这个问题:

<?php phpinfo() ?>

in a test file. Obviously, if that produced what was expected, I wouldn't be here. Instead, I get a 404 error.

在一个测试文件中。显然,如果这产生了预期的结果,我就不会在这里。相反,我收到了 404 错误。

I'm using an ubuntu 12.04 server with Amazon. Apache is installed, php5 is installed, and apache was restarted. I followed the following sequence:

我在亚马逊上使用 ubuntu 12.04 服务器。安装了Apache,安装了php5,重启了apache。我遵循以下顺序:

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo /etc/init.d/apache2 restart

Each one of the first three commands now gives me "apache2 is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded" Obviously, replace apache2 with php5 and libapache2-mod-php5 for the other two.

前三个命令中的每一个现在都给我“apache2 已经是最新版本。0 升级,0 新安装,0 删除和 3 未升级”显然,将 apache2 替换为 php5,将 libapache2-mod-php5 替换为其他两个。

This is a sure way to tell me it's installed, correct? Well, when I use the command "top", php is not one of the services that are running, which tells me it's not running, correct?

这是告诉我它已安装的可靠方法,对吗?好吧,当我使用命令“top”时,php 不是正在运行的服务之一,这告诉我它没有运行,对吗?

Navigating to the IP address gives me Amazon's "It Works!" page, but navigating to any other page on the server produces a 404 error.

导航到 IP 地址给了我亚马逊的“It Works!” 页面,但导航到服务器上的任何其他页面会产生 404 错误。

Any help is much appreciated.

任何帮助深表感谢。

回答by castis

Check out the apache config files. For Debian/Ubuntu theyre in /etc/apache2/sites-available/for RedHat/CentOS/etc they're in /etc/httpd/conf.d/. If you've just installed it, the file in there is probably named default.

查看 apache 配置文件。对于 Debian/Ubuntu,/etc/apache2/sites-available/它们在 RedHat/CentOS/etc 中,它们在/etc/httpd/conf.d/. 如果您刚刚安装了它,其中的文件可能名为default.

Make sure that the config file in there is pointing to the correct folder and then make sure your scripts are located there.

确保那里的配置文件指向正确的文件夹,然后确保您的脚本位于那里。

The line you're looking for in those files is DocumentRoot /path/to/directory.

您在这些文件中查找的行是DocumentRoot /path/to/directory.

For a blank install, your php files most likely needs to be in /var/www/.

对于空白安装,您的 php 文件很可能需要在/var/www/.

What you'll also need to do is find your php.ini file, probably located at /etc/php5/apache2/php.inior /etc/php.iniand find the entry for display_errorsand switch it to On.

您还需要做的是找到您的 php.ini 文件,可能位于/etc/php5/apache2/php.ini/etc/php.ini并找到条目display_errors并将其切换到On.

回答by MagicLAMP

One big gotcha is that PHP is disabled in user home directories by default, so if you are testing from ~/public_html it doesn't work. Check /etc/apache2/mods-enabled/php5.conf

一个大问题是默认情况下在用户主目录中禁用 PHP,因此如果您从 ~/public_html 进行测试,则它不起作用。检查 /etc/apache2/mods-enabled/php5.conf

# Running PHP scripts in user directories is disabled by default
# 
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_flag engine Off
#    </Directory>
#</IfModule>

Other than that installing in Ubuntu is real easy, as all the stuff you used to have to put in httpd.conf is done automatically.

除此之外,在 Ubuntu 中安装非常简单,因为您过去必须放在 httpd.conf 中的所有内容都是自动完成的。

回答by Dan

To answer the original question "Why is php not running?" The file your browser is asking for must have the .php extension. If the file has the .html extension, php will not be executed.

要回答最初的问题“为什么 php 没有运行?”您的浏览器要求的文件必须具有 .php 扩展名。如果文件具有 .html 扩展名,则不会执行 php。

回答by Dipankar Biswas

Type in browser localhost:80//test5.php[where 80 is your port and test.php is your file name] instead of c://xampp/htdocs/test.php.

在浏览器中输入 localhost:80//test5.php[其中 80 是您的端口,test.php 是您的文件名] 而不是 c://xampp/htdocs/test.php。

回答by davidgo

When installing Apache and PHP under Ubuntu 14.04, I needed to specifically enable php configs by issuing a2enmod php5-cgi

在 Ubuntu 14.04 下安装 Apache 和 PHP 时,我需要通过发出 a2enmod php5-cgi 来专门启用 php 配置

回答by Mic1780

You need to add the semicolon to the end of all php things like echo, functions, etc.

您需要在所有 php 内容(如 echo、函数等)的末尾添加分号。

change <?php phpinfo() ?>to <?php phpinfo(); ?>

更改<?php phpinfo() ?><?php phpinfo(); ?>

If that does not work, use php's function ini_set to show errors: ini_set('display_errors', 1);

如果这不起作用,请使用 php 的函数 ini_set 显示错误: ini_set('display_errors', 1);