phpinfo() is not working

2019-02-09 02:16发布

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. I can see the folders for PHP. I can even see the php.ini in the etc folder. But php itself does not seem to be working. I mean my test.php file looks like this:

<?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 :

**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 3 websites hosted. Does that have anything to do with this problem?

14条回答
▲ chillily
2楼-- · 2019-02-09 02:36

I had the same problem. The solution in my case was to set default_mimetype = "text/html" inside php.ini file.

查看更多
甜甜的少女心
3楼-- · 2019-02-09 02:37

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

查看更多
时光不老,我们不散
4楼-- · 2019-02-09 02:40

happened to me as well. In a newly provisioned REDHAT 7 server.

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

Just installed php

[root@localhost ~]# yum install php

Then restart apache

[root@localhost ~]# systemctl restart httpd
查看更多
贼婆χ
5楼-- · 2019-02-09 02:41

I accidentally set the wrong file permissions. After chmod 644 phpinfo.php the info indeed showed up as expected.

查看更多
Anthone
6楼-- · 2019-02-09 02:42

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

Simply adding this, nothing else worked.

apt-get install libapache2-mod-php5
查看更多
冷血范
7楼-- · 2019-02-09 02:43

have you saved the page which contains

<?php
 phpinfo();
?>

with .php extension ? something like info.php not info.html ...

查看更多
登录 后发表回答