phpinfo() outputs nothing

Uhehesh picture Uhehesh · May 28, 2012 · Viewed 19.6k times · Source

I've tried phpinfo() but it output nothing. It is interesting that php-r "phpinfo();" works correctly while using phpinfo() in web outputs nothing. Again, nothing is written to error.log too. php.ini is empty.

I don't know what to do now.

Edit:

Thanks to lanzz, I got that phpinfo() requires no output before it.

Answer

DevOpsSauce picture DevOpsSauce · Jan 5, 2017

I had a similar issue. I am running Apache2 on my Ubuntu machine for local testing of projects before deployment. I created a phpinfo(); page, and noticed it was blank. Upon inspecting in my browser, the php function would be commented out.

Your browser has nothing to do with php.

In order for PHP scripts to execute, you have to save the file as a .php file, which I'm sure you did.

PHP tags alone aren't valid in HTML documents, so you need to create an actual HTML document, and save it as .php. Then, include a basic HTML document like so:

<?php
   phpinfo();
?>

<html>
  <head>
    <title>Php Info</title>
  </head>
    <body>
    </body>
</html>

Then you would do: localhost/phpinfo.php or whatever you're working on. In my case it was an actual domain name that was mapped to my localhost, so 'myProjectName'.com/phpinfo.php

This is just from my experience and it worked 100%.