172

Each time I want to see the phpinfo(); I have to:

  • Create a info.php file;
  • Write phpinfo(); in it.
  • Go to the browser and type my "thisproject.dev/info.php"

I'm on Ubuntu.

Isn't there a more practical way to see phpinfo in the browser?

Dharman
  • 30,962
  • 25
  • 85
  • 135
MEM
  • 30,529
  • 42
  • 121
  • 191
  • 3
    As @Jaitsu and Brian Gordon wrote, you can access PHP via command line, but what they didn't mention is that sometimes PHP in command line is different from one in Apache, i.e., they work in different modes and might even have different config files. – binaryLV Aug 25 '11 at 13:12
  • @binaryLV good point, one i overlooked when I answered – JamesHalsall Aug 25 '11 at 17:33

7 Answers7

321

From your command line you can run..

php -i

I know it's not the browser window, but you can't see the phpinfo(); contents without making the function call. Obviously, the best approach would be to have a phpinfo script in the root of your web server directory, that way you have access to it at all times via http://localhost/info.php or something similar (NOTE: don't do this in a production environment or somewhere that is publicly accessible)

EDIT: As mentioned by binaryLV, its quite common to have two versions of a php.ini per installation. One for the command line interface (CLI) and the other for the web server interface. If you want to see phpinfo output for your web server make sure you specify the ini file path, for example...

php -c /etc/php/apache2/php.ini -i 
JamesHalsall
  • 13,224
  • 4
  • 41
  • 66
  • 10
    Don't forget to *secure* it, as output of `phpinfo()` should not be publicly accessible. – binaryLV Aug 25 '11 at 13:09
  • There is also a good reason for [NOT LINKING](http://askubuntu.com/questions/321019/php-ini-cli-symbolic-link) the 2 `php.ini` especially if you are working on a public server. – JohnnyQ Jan 29 '15 at 09:07
  • You should really just use the -c flag and pass in the path for the proper .ini file instead of doing something like symlinking or whatnot. – Chris Rasys Mar 12 '15 at 21:50
  • @ChrisRasys why would you want to have to specify it every time you run CLI scripts? – JamesHalsall Mar 13 '15 at 13:47
  • @JamesHalsall If you need to emulate the PHP settings that your web server is using, that's the proper way to do it. Otherwise you're either erroneously using the CLI settings, or you're removing the separation between CLI settings and web server settings. That separation does exist for a reason. – Chris Rasys Mar 19 '15 at 16:57
  • Whilst that might be useful for some, I usually use the same ini for both. I've only seen debian distributions use the separate ini for apache and CLI – JamesHalsall Mar 20 '15 at 13:35
  • This can be misleading as the PHP binary is not the same as the PHP module that is loaded by apache check this post: https://superuser.com/questions/969861/phpinfo-and-php-v-shows-different-version-of-php – user1803784 Jan 10 '18 at 20:41
  • I hope my edit gets accepted, but anyway: 6 upvotes for @binaryLV is way too little, this should be in bold in the answer: **phpinfo should not be publicly accessible** I wonder how many breaches have been made possible over the years by the "best approach" in this answer. – Douwe Jan 14 '19 at 12:09
  • To add to that: Our logs show that servers are **actively scanned** for the mentioned endpoint "/info.php". Either update your answer or take it down JamesHalsall, I can't believe this has been up for 7 years. – Douwe Jan 14 '19 at 13:47
  • @Douwe if you read my answer, it says `http://localhost/info.php` - I did not say to expose it in production or publicly – JamesHalsall Jan 14 '19 at 15:17
  • @JamesHalsall You start that sentence with "the best approach would be to have a phpinfo script in the root of your web server directory". So any novice that thinks "oh, but mine is on a different domain, I'll use that because it's "something simular" would not be warned. Even bigger issue: A lot of IDE's auto-add files to git. Again, this is actively being exploited, cross referencing phpinfo()'s output with known vulnerabilities is very, very easy. OP's approach of removing after use is actually a far better "best approach" than this. – Douwe Jan 14 '19 at 15:31
27

From the CLI the best way is to use grep like:

php -i | grep libxml
totas
  • 10,288
  • 6
  • 35
  • 32
23

If you have php installed on your local machine try:

$ php -a
Interactive shell

php > phpinfo();
Kirill Fuchs
  • 13,446
  • 4
  • 42
  • 72
Rag
  • 6,405
  • 2
  • 31
  • 38
  • 2
    Does this get the `php.ini` of the cli version or the one in apache? In my case I use 2 `php.ini` for cli and apache. – JohnnyQ Jan 29 '15 at 08:57
  • 2
    I tried this and it gets the `php.ini` from the CLI version. If you keep 2 versions of `php.ini` this might not be applicable. – JohnnyQ Jan 29 '15 at 09:09
15

From the CLI:

php -r 'phpinfo();'
sjas
  • 18,644
  • 14
  • 87
  • 92
3

Use the command line.

touch /var/www/project1/html/phpinfo.php && echo '<?php phpinfo(); ?>' >> /var/www/project1/html/phpinfo.php && firefox --url localhost/project1/phpinfo.php

Something like that? Idk!

Chris G.
  • 3,963
  • 2
  • 21
  • 40
1

You can use this command to print phpinfo to file .txt:

touch phpinfo.txt && php -i >> phpinfo.txt && sudo gedit phpinfo.txt

Explain about that code:

  1. Create new file:

touch phpinfo.txt

  1. Print phpinfo() to file .txt:

php -i >> phpinfo.txt

  1. Open file:

sudo gedit phpinfo.txt

Hope it's help. Thanks.

fudu
  • 617
  • 1
  • 10
  • 19
0

If you are using WAMP then type the following in the browser
http://localhost/?phpinfo=-1, you will get the phpinfo page.

phpinfo() from localhost

You can also click the localhost icon in the wamp menu from the systray and then find the phpinfo page. WAMP localhost from WAMP Menu

venkat
  • 51
  • 1
  • 2