0

I am on a server with multiple domains. I would like to find out which php.ini gets loaded in each domain.
I've got a few different tools at hand. Perhaps they get me closer to what I want.

  1. A simple php -i|grep 'Loaded Configuration File' returns the system php.ini.
  2. find /home/ -xdev -name php.ini 2>/dev/null returns all php.ini belonging to all hosted domains.
  3. virtualmin list-php-directories --domain this.is.a.domain --multiline returns all directories in which a specific version of PHP has been activated.

Some sample output:
1. Returns:

Loaded Configuration File => /etc/php/7.0/cli/php.ini

This is obviously the php.ini which gets loaded by the host OS.
2. Returns:

...
/home/domain.x.com/etc/php5/php.ini
/home/domain.x.com/etc/php7.0/php.ini
/home/domain.x.com/etc/php.ini
/home/domain.y.com/etc/php7.0/php.ini
/home/domain.y.com/etc/php.ini
...

This is a complete list of all php.ini in those domains.
3. Returns:

/home/domain.x.com/public_html
  PHP version: 7.0
  Full version: 7.0.8
  Execution mode: fcgid
  Web root directory: Yes

There is always a php.ini in /home/domain.foo.com/etc/. Is that the one that hets loaded? Or do I have to check virtualmin for which version of PHP is loaded to traverse into the appropriate subdir? Is there a completely different way?

Note: I only have the command line at hand and only one user for monitoring purposes. Also, the process should be non-invasive. So I dont' think that I can put some php files in those domains to get my answer through a browser. Is the info perhaps stored in some file I can parse?

sebastian
  • 478
  • 8
  • 22
  • 1
    `php --ini` ? It will show you in details all the PHP.ini paths specifying which is loaded. Not sure how this will work for multiple domains, but worth a try. – Marin N. Apr 10 '17 at 12:17
  • Looks like you answered your own question! What is the output of command number 2 above? Is that not what you are looking for? – Kanad Godse Apr 10 '17 at 12:24
  • Also check if you have a real file or just a symlink to another real file! – JustOnUnderMillions Apr 10 '17 at 12:28
  • And php function `php_ini_loaded_file()`. Also there are 3 `php.ini` in use, always, one for CLI one for CGI and one for WEB. Sometimes they point via `symlink` to one real `php.ini`. Under linux you can do `locate php.ini` and you well see all you have on the hardware. – JustOnUnderMillions Apr 10 '17 at 12:29
  • 1
    @MarinNedea this returns only info for the host OS. – sebastian Apr 10 '17 at 12:32
  • @KanadGodse Command 2 returns all `php.ini`. Not which is actually loaded. – sebastian Apr 10 '17 at 12:33
  • Well, then please see my answer below, you can get the exact php.ini which is loaded from each domain by doing that. – Kanad Godse Apr 10 '17 at 12:35
  • @JustOnUnderMillions that return the same result as Command 1 – sebastian Apr 10 '17 at 12:37
  • `that`? I have dropped 2 comments?!? Keep in mind via command line there is not the same php.ini used as if you test it via browser. Use `php_ini_loaded_file()` in you php script, load the page from webbrowser, then check if the used `php.ini` is a symlink to another on the hardware. – JustOnUnderMillions Apr 10 '17 at 12:39
  • @JustOnUnderMillions ahh. right. From a browser this will be different. My question stated, that I can only use the command line. – sebastian Apr 10 '17 at 12:44
  • But `in each domain` sounds like you want to know, whats loaded when accessed via web-browser, too me ;-) Like the answer below :-) – JustOnUnderMillions Apr 10 '17 at 12:45
  • Yes. That is what I want to do. I know that I can do it in the way described in the answer below. It just could be that I dont have that option to put some file in each domain. So I was wondering if the information is listed in some file I could parse without tinkering with the filesystem of the customers. – sebastian Apr 10 '17 at 12:51

1 Answers1

1

From only the command line, you would need to:

  1. Install a command line web browser OR you can use wget to hit the script and save the response in a file.
  2. Have a php file with <?php phpinfo(); in all of the domains
  3. Make sure that all the domains are able to be loaded on the webserver or the webserver has internet access to load the domains directly from web. Best would be to map all the domains to localhost in the hosts file.
  4. Open the phpinfo script from each domain in the command line browser and check the loaded configuration file OR if you have chosen to use wget, just save the output to file and inspect the contents of the file and you would get the loaded config file.
Kanad Godse
  • 309
  • 1
  • 6
  • This looks good. I will try this with wget when I get write access there. Thanks a bunch. – sebastian Apr 10 '17 at 12:46
  • So you don't see a way to do this `read-only`? Is the info not stored in some file I could parse? Given that some of the domains belong to customers it is not so great to put some file in their domain. – sebastian Apr 10 '17 at 12:53
  • I believe the php config path should be stored in the domain's vhost file if each domain is loading a custom php.ini file. Could you please check the server configuration files? From your question above, if you don't want to put files in your customer's domains, the 3rd command you mentioned should do the trick, but you would again be guessing and the only sureshot way to know would be to actually have a php page execute and show the config file location through `php-info()` as I have mentioned. Let me know if you need any help. Thanks! – Kanad Godse Apr 11 '17 at 06:02