- Find the correct php.ini file [closed]
- How can I know which ‘php.ini’ file is used?
- 7 Answers 7
- Find the correct php.ini file
- 7 Answers 7
- How to find the php.ini file used by the command line?
- What is php.ini
- Where is php.ini file located by default
- How can I find the php.ini file from command line
- php –ini
- php-config –ini-dir
- php -i and grep
- Conclusions
Find the correct php.ini file [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
I am currently trying to locate the correct php.ini file to edit it and restart Apache, so the changes will take place and I’m stumped. What I have done. I have found three different php.ini files (I don’t have any idea why there are three). This is how I found the files: sudo find / -name php.ini . It resulted in the following.
/etc/php5/cli/php.ini /etc/php5/apache2/php.ini /etc/php5/cgi/php.ini
sudo php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc/php5/cli Loaded Configuration File => /etc/php5/cli/php.ini
sudo service apache2 restart
* Restarting web server apache2
echo ini_get('post_max_size');
Which was supposed to be changed to 20M, but it was still only 2M. I tried rebooting my computer thinking maybe that would legit stop the Apache server and reload the php.ini file with the correct setting, but alas that attempt also failed. Is there any chance there could be another php.ini file that could be interfering? A better, more helpful for other users answer can be found here: Find the correct php.ini file
How can I know which ‘php.ini’ file is used?
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?
7 Answers 7
For the webserver-SAPIs use phpinfo()
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
Find the correct php.ini file
I am currently trying to locate the correct php.ini file to edit it and restart apache so the changes will take place and I’m stumped. I have found three different php.ini files (no idea why there are three) this is how I found the files
$ sudo find / -name php.ini /etc/php5/cli/php.ini /etc/php5/apache2/php.ini /etc/php5/cgi/php.ini
$ sudo php -i | grep 'Configuration File' Configuration File (php.ini) Path => /etc/php5/cli Loaded Configuration File => /etc/php5/cli/php.ini
sudo service apache2 restart
* Restarting web server apache2
echo ini_get('post_max_size');
Which was supposed to be changed to 20M but was still only 2M I tried rebooting my computer thinking maybe that would stop the apache server and reload the php.ini file with the correct setting, but alas that attempt also failed. Is there any chance there could be another php.ini file that could be interfering?
@Michael The file is /etc/php/5.6/apache2/php.ini in Ubuntu 16.04 LTS Xenial Xerus, where 5.6/ is the version of php installed. First copy the file to php.original.ini then open for editing with sudo gedit /etc/php/5.6/apache2/php.ini
7 Answers 7
The three files you have there are each meant for different uses.
/etc/php/5.6/cli/php.ini is for the CLI PHP program, which you found by running php on the terminal.
/etc/php/5.6/cgi/php.ini is for the php-cgi system which isn’t specifically used in this setup.
/etc/php/5.6/apache2/php.ini is for the PHP plugin used by Apache. This is the one you need to edit for changes to be applied for your Apache setup which utilizes the in-built PHP module to Apache.
/etc/php/5.6/fpm/php.ini is for the php5-fpm processor, which is a fastcgi-compatible ‘wrapper’ for PHP processing (such as to hand off from NGINX to php5-fpm ) and runs as a standalone process on the system (unlike the Apache PHP plugin)
For versions of Ubuntu lower than 16.04, /etc/php/5.6/ , /etc/php/7.0/ , /etc/php/7.1/ , and so on, are replaced by /etc/php5/ and so on. Otherwise, these paths remain accurate. Adapt this accordingly for your environment, replacing the 5.6 or number with the actual version folder that exists on your environment.
How to find the php.ini file used by the command line?
There are a few ways to locate php.ini file by command line on Linux Ubuntu, Linux Mint, and other Linux distributions. Some of the options showed here are also compatible with Windows, specially usin WSL.
What is php.ini
The php.ini file is the configuration file that is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.
It is the main place where you declare changes to your PHP settings. The server is already configured with standard settings for PHP, which your site or application will use by default. Unless you need to change one or more settings, there is no need to create or modify a php.ini file.
Where is php.ini file located by default
The php.ini file is searched for in these locations (in order):
- SAPI module specific location (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI)
- The PHPRC environment variable.
- The location of the php.ini file can be set for different versions of PHP. The root of the registry keys depends on 32- or 64-bitness of the installed OS and PHP. For 32-bit PHP on a 32-bit OS or a 64-bit PHP on a 64-bit OS use [(HKEY_LOCAL_MACHINE\SOFTWARE\PHP] for 32-bit version of PHP on a 64-bit OS use [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP]] instead. For same bitness installation the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP major, minor and release versions. For 32 bit versions of PHP on a 64 bit OS the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
- [HKEY_LOCAL_MACHINE\SOFTWARE\PHP] or [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP], value of IniFilePath (Windows only).
- Current working directory (except CLI).
- The web server’s directory (for SAPI modules), or directory of PHP (otherwise in Windows).
- Windows directory (C:\windows or C:\winnt) (for Windows), or –with-config-file-path compile time option.
If php-SAPI.ini exists (where SAPI is the SAPI in use, so, for example, php-cli.ini or php-apache.ini ), it is used instead of php.ini . The SAPI name can be determined with php_sapi_name() (returns the type of interface between web server and PHP).
The Apache web server changes the directory to root at startup, causing PHP to attempt to read php.ini from the root filesystem if it exists.
How can I find the php.ini file from command line
php –ini
There is a simple option called —ini that you can use when run php command:
The output will show where is the php.ini used by command line, as well additional scanned configuration files:
Configuration File (php.ini) Path: /etc/php/7.4/cli Loaded Configuration File: /etc/php/7.4/cli/php.ini Scan for additional .ini files in: /etc/php/7.4/cli/conf.d Additional .ini files parsed: /etc/php/7.4/cli/conf.d/10-mysqlnd.ini, /etc/php/7.4/cli/conf.d/10-pdo.ini, /etc/php/7.4/cli/conf.d/15-xml.ini, /etc/php/7.4/cli/conf.d/20-bcmath.ini, /etc/php/7.4/cli/conf.d/20-exif.ini, /etc/php/7.4/cli/conf.d/20-gd.ini, /etc/php/7.4/cli/conf.d/20-gettext.ini, /etc/php/7.4/cli/conf.d/20-iconv.ini, /etc/php/7.4/cli/conf.d/20-intl.ini, /etc/php/7.4/cli/conf.d/20-json.ini, /etc/php/7.4/cli/conf.d/20-mbstring.ini, /etc/php/7.4/cli/conf.d/20-mysqli.ini, /etc/php/7.4/cli/conf.d/20-pdo_mysql.ini, /etc/php/7.4/cli/conf.d/20-pdo_pgsql.ini, /etc/php/7.4/cli/conf.d/20-pdo_sqlite.ini, /etc/php/7.4/cli/conf.d/20-pgsql.ini, /etc/php/7.4/cli/conf.d/20-redis.ini, /etc/php/7.4/cli/conf.d/20-simplexml.ini, /etc/php/7.4/cli/conf.d/20-sockets.ini, /etc/php/7.4/cli/conf.d/20-sqlite3.ini, /etc/php/7.4/cli/conf.d/20-xmlreader.ini, /etc/php/7.4/cli/conf.d/20-xmlwriter.ini, /etc/php/7.4/cli/conf.d/20-xsl.ini, /etc/php/7.4/cli/conf.d/20-zip.ini, /etc/php/7.4/cli/conf.d/xdebug.ini
php-config –ini-dir
Using php-config you can list only the path where the main PHP configuration file is located:
The output is something like:
php -i and grep
The command php -i shows a complete phpinfo() result. You can find all configurations and apply grep command to filter only the .ini configuration file:
php -i | grep 'Configuration File'
Or in Windows you can use find instead:
php -i | find/i"configuration file"
The result to both command will be similar to:
Configuration File (php.ini) Path => /etc/php/7.4/cli Loaded Configuration File => /etc/php/7.4/cli/php.ini
Finally you can use grep to filter all lines of the phpinfo() that shows .ini :
The output will be similar to php -i command:
Configuration File (php.ini) Path: /etc/php/7.4/cli Loaded Configuration File: /etc/php/7.4/cli/php.ini Scan for additional .ini files in: /etc/php/7.4/cli/conf.d Additional .ini files parsed: /etc/php/7.4/cli/conf.d/10-mysqlnd.ini, /etc/php/7.4/cli/conf.d/10-pdo.ini, /etc/php/7.4/cli/conf.d/15-xml.ini, /etc/php/7.4/cli/conf.d/20-bcmath.ini, /etc/php/7.4/cli/conf.d/20-exif.ini, /etc/php/7.4/cli/conf.d/20-gd.ini, /etc/php/7.4/cli/conf.d/20-gettext.ini, /etc/php/7.4/cli/conf.d/20-iconv.ini, /etc/php/7.4/cli/conf.d/20-intl.ini, /etc/php/7.4/cli/conf.d/20-json.ini, /etc/php/7.4/cli/conf.d/20-mbstring.ini, /etc/php/7.4/cli/conf.d/20-mysqli.ini, /etc/php/7.4/cli/conf.d/20-pdo_mysql.ini, /etc/php/7.4/cli/conf.d/20-pdo_pgsql.ini, /etc/php/7.4/cli/conf.d/20-pdo_sqlite.ini, /etc/php/7.4/cli/conf.d/20-pgsql.ini, /etc/php/7.4/cli/conf.d/20-redis.ini, /etc/php/7.4/cli/conf.d/20-simplexml.ini, /etc/php/7.4/cli/conf.d/20-sockets.ini, /etc/php/7.4/cli/conf.d/20-sqlite3.ini, /etc/php/7.4/cli/conf.d/20-xmlreader.ini, /etc/php/7.4/cli/conf.d/20-xmlwriter.ini, /etc/php/7.4/cli/conf.d/20-xsl.ini, /etc/php/7.4/cli/conf.d/20-zip.ini, /etc/php/7.4/cli/conf.d/xdebug.ini
Conclusions
There are several ways to find php.ini file and other configurations files of your PHP installation using native commands on terminal.