Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know which 'php.ini' file is used?

Tags:

php

php-ini

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini files when executing the command find / -name php.ini. So how can I know exactly from a PHP script web page where the php.ini is located?

like image 551
pheromix Avatar asked Jan 28 '13 08:01

pheromix


People also ask

What type file PHP ini is?

The php. ini file is a special file for PHP. It is where you declare changes to your PHP settings. The server is already configured with standard settings for PHP, which your site will use by default.

How do I use a different PHP ini file?

For example, you can set the environment variable PHPRC , or you can put a different php. ini file in each current working directory, assuming each virtual host has a distinct cwd. Note that when using Apache and mod_php, or other module embedding PHP in the web server (e.g. FastCGI), the php.

How do I find PHP ini on Linux?

If you can access one of your PHP files, open it in a editor (Notepad) and insert phpinfo(); after <? php on a new line. This will tell you the php. ini location.


2 Answers

php --ini 

For the webserver-SAPIs use phpinfo()

Here's some sample output:

bash-3.2# php --ini Configuration File (php.ini) Path: /usr/local/php5/lib Loaded Configuration File:         /usr/local/php5/lib/php.ini Scan for additional .ini files in: /usr/local/php5/php.d Additional .ini files parsed:      /usr/local/php5/php.d/10-extension_dir.ini, /usr/local/php5/php.d/20-extension-opcache.ini, /usr/local/php5/php.d/40-openssl.ini, /usr/local/php5/php.d/50-extension-apcu.ini, /usr/local/php5/php.d/50-extension-curl.ini, /usr/local/php5/php.d/50-extension-gmp.ini, /usr/local/php5/php.d/50-extension-imap.ini, /usr/local/php5/php.d/50-extension-intl.ini, /usr/local/php5/php.d/50-extension-mcrypt.ini, /usr/local/php5/php.d/50-extension-mssql.ini, /usr/local/php5/php.d/50-extension-pdo_pgsql.ini, /usr/local/php5/php.d/50-extension-pgsql.ini, /usr/local/php5/php.d/50-extension-propro.ini, /usr/local/php5/php.d/50-extension-raphf.ini, /usr/local/php5/php.d/50-extension-readline.ini, /usr/local/php5/php.d/50-extension-xdebug.ini, /usr/local/php5/php.d/50-extension-xsl.ini, /usr/local/php5/php.d/60-extension-pecl_http.ini, /usr/local/php5/php.d/99-liip-developer.ini 
like image 97
KingCrunch Avatar answered Oct 16 '22 02:10

KingCrunch


You can use php_ini_loaded_file().

Taken from php.net:

$inipath = php_ini_loaded_file(); if ($inipath) {     echo 'Loaded php.ini: ' . $inipath; } else {     echo 'A php.ini file is not loaded'; } 

You may also want to check php_ini_scanned_files().

Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini file will be used than if a server (e.g., nginx or Apache) runs it.

Other options:

  • php -i|grep 'php.ini'
  • create info.php that contains <?php phpinfo(); in the webroot, and run it in your browser
like image 41
Vlad Preda Avatar answered Oct 16 '22 02:10

Vlad Preda