Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpinfo() is not working on my CentOS server

Tags:

php

centos

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

like image 356
user1137313 Avatar asked Jul 22 '13 00:07

user1137313


People also ask

How do I run Phpinfo on a server?

Running Phpinfo() diagnostics The phpinfo() function can be used to output a large amount of information about your PHP installation and can be used to identify installation and configuration problems. To run the function, just create a new file called test. php and place it into the root directory of your web server.

How do I know if I have Phpinfo on Centos 7?

Testing PHP Installation With a Phpinfo() php phpinfo(); ?> Open your web browser and type the url: http://example.com/test.php.

How do I test Phpinfo?

Make sure the Web server is running, open a browser and type http://SERVER-IP/phptest.php. You should then see a screen showing detailed information about the PHP version you are using and installed modules.

What is Phpinfo () function?

Because every system is setup differently, phpinfo() is commonly used to check configuration settings and for available predefined variables on a given system. phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data.


Video Answer


3 Answers

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>
like image 72
user6204369 Avatar answered Oct 18 '22 23:10

user6204369


Save the page which contains

<?php
    phpinfo();
?>

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

like image 23
Friend Avatar answered Oct 19 '22 00:10

Friend


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
like image 38
cmorrissey Avatar answered Oct 18 '22 22:10

cmorrissey