11

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.

5
  • 2
    Are you trying with a simple <?php phpinfo() ?> file, or is it a part of a larger file? If your script is larger, can you try with a one-line <?php phpinfo() ?> and see if it works? Commented May 28, 2012 at 21:19
  • 1
    Do PHP scripts on your server work at all? Commented May 28, 2012 at 21:20
  • You are genius. It works this way, lanzz. Commented May 28, 2012 at 21:22
  • probably has php installed but why php.ini is empty ? do you have enough privileges ? did u checked access.log,error.log in apache? Commented May 28, 2012 at 21:23
  • Just make sure the function has not been disabled as many hosting providers disable it for security. Commented Jul 16, 2015 at 9:52

6 Answers 6

7

Just wanted to add, that I was using short tags '<?'

<? phpinfo();

which was failing, becuase I was using short tags when they were disabled so it should have been

<?php phpinfo();
Sign up to request clarification or add additional context in comments.

Comments

6

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%.

Comments

3

First, Check the content of your "access.log" ; if you don't see the call to the phpinfo file, you certainly have a problem on your web server.

Otherwise, try to get a simple php file :

<?php echo "Hello, world.";

Or HTML file :

<h1>Hello, world !</h1>

Then you can determine where is the problem.

Perhaps the PHP module for the web server isn't loaded.

Comments

1

One more case when there is no output from php file is when permission is set incorrectly. For example your web server has no rights to read it.

2 Comments

This would probably be better as a comment.
This answer reminds me... changing permission "sudo chmod 777 -R index.php" saved me...
1

In my case (Ubuntu 22.04), apache was not properly configured to run php. Apache's mpm_prefork module was conflicting with the the php module. I followed the instructions in this answer to solve the problem. Instructions reposted here for convenience.

  1. sudo a2dismod mpm_event
  2. sudo systemctl restart apache2
  3. sudo a2enmod mpm_prefork
  4. sudo systemctl restart apache2
  5. sudo a2enmod php7.0
  6. sudo systemctl restart apache2

Comments

0

I had to use a workaround to make it work. The code I used was: I can't answer why it only works like this but it does.

<?php
  echo phpinfo();
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.