php phpinfo() 在我的 CentOS 服务器上不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17778264/
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:26:03  来源:igfitidea点击:

phpinfo() is not working on my CentOS server

phpcentosphpinfo

提问by user1137313

I have PHP installed on my CentOS server. However, when running a phpinfo() inside my script to test it, I receive the HTML, not the interpreted information.

我的 CentOS 服务器上安装了 PHP。但是,当在我的脚本中运行 phpinfo() 来测试它时,我收到的是 HTML,而不是解释的信息。

I can see the folders for PHP. I can even see the php.ini in the etcfolder. But PHP itself does not seem to be working.

我可以看到 PHP 的文件夹。我什至可以在etc文件夹中看到 php.ini 。但是 PHP 本身似乎不起作用。

I mean my test.php file looks like this:

我的意思是我的 test.php 文件是这样的:

<?php
    phpinfo();
?>

And the response looks like this:

响应如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: monospace;}
a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
...

and so on.

等等。

What seems to be the problem and how do I solve it?

似乎是什么问题,我该如何解决?

If I copy the HTML returned, paste it into an HTML file, and run it from there, I can see the formatted result, but not by running the test.php. I assume PHP is not loaded somehow... even if in the interpreted HTML I can see the:

如果我复制返回的 HTML,将其粘贴到一个 HTML 文件中,然后从那里运行它,我可以看到格式化的结果,但不能通过运行 test.php。我认为 PHP 没有以某种方式加载......即使在解释的 HTML 中我也可以看到:

**Server API    Apache 2.0 Handler
Virtual Directory Support    disabled
Configuration File (php.ini) Path    /etc/php.ini
Scan this dir for additional .ini files    /etc/php.d
additional .ini files parsed    /etc/php.d/dbase.ini, /etc/php.d/json.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini
PHP API    20041225
PHP Extension    20050922
Zend Extension    220051025
Debug Build    no
Thread Safety    disabled
Zend Memory Manager    enabled
IPv6 Support    enabled
Registered PHP Streams    php, file, http, ftp, compress.bzip2, compress.zlib, https, ftps**

and so on...

等等...

On this system, there are three websites hosted. Does that have anything to do with this problem?

在这个系统上,托管了三个网站。这与这个问题有关系吗?

回答by user6204369

This happened to me as well. The fix was wrapping it in HTML tags. Then I saved the file as /var/www/html/info.phpand ran http://localhost/info.phpin the browser. That's it.

这也发生在我身上。修复方法是将其包装在 HTML 标签中。然后我将文件保存为/var/www/html/info.php并在浏览器中运行http://localhost/info.php。就是这样。

<html>
    <body>
        <?php
            phpinfo();
        ?>
    </body>
</html>

回答by Friend

Save the page which contains

保存包含的页面

<?php
    phpinfo();
?>

with the .php extension. Something like info.php, not info.html...

带有 .php 扩展名。类似的东西info.php,不是info.html...

回答by cmorrissey

You need to update your Apache configuration to make sure it's outputting phpas the type text/HTML.

您需要更新您的 Apache 配置以确保它php以 text/HTML 类型输出。

The below code should work, but some configurations are different.

下面的代码应该可以工作,但有些配置不同。

AddHandler php5-script .php
AddType text/html .php

回答by Sam Bing

This did it for me (the second answer): Why are my PHP files showing as plain text?

这是为我做的(第二个答案):为什么我的 PHP 文件显示为纯文本?

Simply adding this, nothing else worked.

简单地添加这个,没有其他工作。

apt-get install libapache2-mod-php5

回答by John Magnolia

I just had the same issue and found that a client had disabled this function from their php.inifile:

我刚刚遇到了同样的问题,发现客户已从他们的php.ini文件中禁用了此功能:

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
disable_functions = phpinfo;

More information: Enabling and disabling phpinfo() for security reasons

更多信息:出于安全原因启用和禁用 phpinfo()

回答by Ahmad

Try to create a php.inifile in root and write the following command in and save it.

尝试php.ini在 root 中创建一个文件并写入以下命令并保存它。

disable_functions =

Using this code will enable the phpinfo() function for you if it is disabled by the global PHP configuration.

如果全局 PHP 配置禁用了 phpinfo() 函数,则使用此代码将为您启用该函数。

回答by NarcosdaCol

My solution was uninstalling and installing the PHP instance (7.0 in my case) again:

我的解决方案是再次卸载和安装 PHP 实例(在我的例子中是 7.0):

sudo apt-get purge php7.0
sudo apt-get install php7.0

After that you will need to restart the Apache service:

之后,您将需要重新启动 Apache 服务:

sudo service apache2 restart

Finally, verify again in your browser with your localhost or IP address.

最后,在您的浏览器中再次验证您的 localhost 或 IP 地址。

回答by peterk

For people who have no experience in building websites (like me) I tried a lot, only to find out that I hadn't used the .phpextension, but the .htmlextension.

对于没有构建网站经验的人(比如我),我尝试了很多,才发现我没有使用.php扩展程序,而是.html扩展程序。

回答by Toqero_Mohamed

Be sure that the tag "php" is stick in the code like this:

确保标签“php”像这样粘贴在代码中:

?phpphpinfo(); ?>

? phpphpinfo(); ?>

Not likethis:

不是这样的

? phpphpinfo(); ?>

? phpphpinfo(); ?>

OR the server will treat it as a (normal word), so the server will not understand the language you are writing to deal with it so it will be blank.

或者服务器会将其视为(普通词),因此服务器将无法理解您正在编写的语言来处理它,因此它将为空白

I know it's a silly error ...but it happened ^_^

我知道这是一个愚蠢的错误......但它发生了^_^

回答by Omari Victor Omosa

It happened to me as well. On a newly provisioned Red Hat Linux 7 server.

它也发生在我身上。在新配置的 Red Hat Linux 7 服务器上。

When I run a PHP page, i.e. info.php, I could see plain text PHP scripts instead of executing them.

当我运行一个 PHP 页面,即 info.php 时,我可以看到纯文本 PHP 脚本而不是执行它们。

I just installed PHP:

我刚刚安装了 PHP:

[root@localhost ~]# yum install php

And then restarted Apache HTTP Server:

然后重新启动 Apache HTTP 服务器:

[root@localhost ~]# systemctl restart httpd