Linux найти php ini

How can I find the php.ini file used by the command line?

I need to enable pdo_mysql in my EasyPHP environment, so I went to the php.ini file and uncommented the following line:

extension=php_pdo_mysql.dll 

Unfortunately I still have the same problem. I’m using the CLI so I suppose I need to locate the php.ini file used by the CLI. How can I find it?

Some context: «The root cause of the problem is that in EasyPHP 5.3 there isn’t any php.ini file in the php folder.

15 Answers 15

Just run php —ini and look for Loaded Configuration File in the output for the location of php.ini used by your CLI.

@AntonyD’Andrea: which is exactly what the question is about. See? It does state so even in the title: How to find the php.ini file used by the command line?

@Mchl: I have shamelessly edited your answer to include the informative not to look for Loaded Configuration File in output 🙂

@Fr0zenFyr: thank you. It’s been so long time ago sine I worked with PHP I don’t even recall if the output from php —ini was always this way, or it has changed since my answer.

You can get a full phpinfo() using:

And, in there, there is the php.ini file used:

$ php -i | grep 'Configuration File' Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini 
php -i | find/i"configuration file" 

Then this php instance used no php.ini at all but the default values. The Configuration File line of phpinfo() shows the last place where php looked for an ini file. That can either be the place where it found such a file or the last option which happens to be %SYSTEMROOT% on windows.

@pascal: php -i | find «Configuration file» should work on Windows. Definitely not as powerful as grep, but find will do basic string searching for you. Of course, if php -i dumps its output to stderr, you’re probably SOL.

find is case-sensitive by default, so it has to be perfect ( php -i | find «Configuration File» ) or made case-insensitive ( php -i | find /i «Configuration file» — note the /i flag).

Читайте также:  Команда повышения прав линукс

Nobody mentioned, that it’s possible to take that value from script by calling php_ini_loaded_file and when needed php_ini_scanned_files

To check whether the system is using a configuration file, try retrieving the value of the cfg_file_path configuration setting. If this is available, a configuration file is being used.

var_dump( get_cfg_var('cfg_file_path') ); 

And you can simply set the location of the php.ini. You’re using the command line version, so using the -c parameter you can specify the location for this particular run, e.g.

php -c /home/me/php.ini -f /home/me/test.php 

Run php —ini in your terminal, and you’ll get all details about ini files:

Configuration File (php.ini) Path: /etc Loaded Configuration File: /etc/php.ini Scan for additional .ini files in: /etc/php.d Additional .ini files parsed: /etc/php.d/apc.ini, /etc/php.d/bcmath.ini, /etc/php.d/curl.ini, /etc/php.d/dba.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, /etc/php.d/gd.ini, /etc/php.d/imap.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/memcache.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/phar.ini, /etc/php.d/posix.ini, /etc/php.d/sqlite3.ini, /etc/php.d/ssh2.ini, /etc/php.d/sysvmsg.ini, /etc/php.d/sysvsem.ini, /etc/php.d/sysvshm.ini, /etc/php.d/wddx.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini 

For more, use helping command php —help . It’ll display all the possible options.

Источник

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?

Читайте также:  Rsync windows and linux

@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.

Источник

Where is my PHP php.ini Configuration File Located?

PHP php.ini Configuration File location

In this article, we will guide you on a treasure hunt to find the php.ini configuration file, unravel its mysteries, and unlock the full capabilities of your PHP environment. Whether you are a seasoned PHP developer or a newcomer to the world of web development, understanding the ins and outs of this essential configuration file will make your journey smoother and your projects more efficient. So, let’s embark on this exciting quest to locate and master the php.ini file!

Method 1

One way to find out exactly which php.ini file your web sever is using is by creating a new PHP file in document root called info.php .

Load this file in your browser, press CTRL + F (or Command + F on Mac) and search for “Loaded Configuration File”. You should see something like

This will tell you the exact location of the php.ini file you want to edit.

Method 2

In Linux, run this command to locate the PHP.ini configuration file.

Or in Windows Command Line:

Читайте также:  Linux screen or tmux

The result should be something like this:

In the above example, we can see that the PHP install is located in /etc/php/8.1 . Note that there are three different configuration files you should we aware of:

CLI

/etc/php/8.1/cli/php.ini is for the CLI PHP program. Changes to this config file will only affect PHP as it runs in the terminal – it will NOT affect the web server.

Apache

/etc/php/8.1/apache2/php.ini is for the PHP plugin used by Apache. This is the one you need to edit if you are using the Apache web server.

Nginx or Apache with PHP-FPM

/etc/php/8.1/fpm/php.ini is a fastcgi-compatible ‘wrapper’ for PHP processing. This is the one you need to edit if you’re using the Nginx web server or Apache with PHP-FPM.

Method 3

Using the locate command in Linux,. If it’s not already installed, run sudo apt update && sudo apt install mlocate .

You should see a list of php.ini files here. Try editing one of them and restarting you web server to see if makes the required changes.

Editing php.ini in Linux

Apache

On Apache, php.ini is usually located in /etc/php/8.1/apache2/php.ini . Replace 8.1 with your own version, e.g, php5.6 , php7.4 , etc.

However, if you are using PHP FPM, it may be located in /etc/php/8.1/fpm/php.ini . Replace 8.1 with your own version, e.g, php5.6 , php7.4 , etc.

To save file and exit, press CTRL + X , press Y and then press ENTER

You must restart Apache after altering php.ini .

If you are using PHP-FPM, you must restart that service. Replace php8.1 with your own version, e.g, php5.6 , php7.4 , etc.

Nginx or Apache with PHP-FPM

Nginx uses PHP FPM and php.ini is usually located in /etc/php/8.1/fpm/php.ini . Replace 8.1 with your own version, e.g, php5.6 , php7.4 , etc.

Save and exit (press CTRL + X , press Y and then press ENTER )

You must restart Nginx after altering php.ini .

Older Versions

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.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

No replies yet

Join the full discussion at the DevAnswe.rs Forums →

2 replies

Leave a reply Cancel reply

Very good… this information saved me!

Источник

Оцените статью
Adblock
detector