phpinfo() is not working on my CentOS server

…衆ロ難τιáo~ 提交于 2019-11-30 08:48:06
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.php and ran http://localhost/info.php in the browser. That's it.

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

Save the page which contains

<?php
    phpinfo();
?>

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

cmorrissey

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

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

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

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
John Magnolia

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

; 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

Ahmad

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

disable_functions =

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

Toqero_Mohamed

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

?php phpinfo(); ?>

Not like this:

? php phpinfo(); ?>

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 ^_^

NarcosdaCol

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

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

After that you will need to restart the Apache service:

sudo service apache2 restart

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

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 .php extension, but the .html extension.

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

M Kamakshaiah

It may not work for you if you use localhost/info.php.

You may be able to found the clue from the error. Find the port number in the error message. To me it was 80. I changed address as http://localhost:80/info.php, and then it worked to me.

Omari Victor Omosa

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

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

I just installed PHP:

[root@localhost ~]# yum install php

And then restarted Apache HTTP Server:

[root@localhost ~]# systemctl restart httpd
W.M.

I had the same problem.

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

miehmg

Another possible answer for Windows 10:

The command httpd -k restart does not work on my machine somehow.

Try to use the Windows 10 Service to restart the relative service.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!