Reputation: 516
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.
Upvotes: 11
Views: 27144
Reputation: 309
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.
sudo a2dismod mpm_event
sudo systemctl restart apache2
sudo a2enmod mpm_prefork
sudo systemctl restart apache2
sudo a2enmod php7.0
sudo systemctl restart apache2
Upvotes: 1
Reputation: 474
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();
Upvotes: 7
Reputation: 1387
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%.
Upvotes: 6
Reputation: 11
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();
?>
Upvotes: 0
Reputation: 11
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.
Upvotes: 1
Reputation: 3350
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.
Upvotes: 3