Php ini file location in ubuntu

Php ini file location in ubuntu

In this post, we will learn How to find php.ini Location on Ubuntu 20.04. In most cases, we find the php.ini file in the server but we did not find the php.ini file, so in this tutorial, how to find the location of the loaded php.ini. file. we check two ways to find php.ini file. first How to find the location of php.ini from the command line and How to find the location of php.ini by using the phpinfo() function.

Find location of php.ini by using the phpinfo()

Create a file phpinfo.php within your web-server root directory eg. /var/www/html/ with the following content:

<?php
#phpinfo.php
// show all information

phpinfo();

Php ini file location in ubuntu
Find the location of php.ini on Ubuntu 20.04

Find location of php.ini from command line

Find the location of php.ini from the command line execute the following command to locate the loaded php.ini configuration file for the command line PHP command:

php --ini | grep Loaded
Loaded Configuration File:         /etc/php/7.3/cli/php.ini

Note: The above php.ini file location is used by the PHP command.

For the Apache web-server the above path will translate to:

/etc/php/7.3/apache2/php.ini

For Nginx or Apache with PHP-FPM:

/etc/php/7.3/fpm/php.ini

There are several ways to find the php.ini file location in Ubuntu and Centos Linux servers. It is also interesting to note that there are usually several php.ini files on the server. Here will show you how to find the file and determine which one is the active configuration file.

Using Locate to Find php.ini File Location

Use the following command to get a list of all of the php.ini files.

$ locate php.ini

This will give an output similar to this:

/etc/php/7.2/apache2/php.ini
/etc/php/7.2/cli/php.ini
/etc/php/7.2/fpm/php.ini
/etc/php/7.3/cli/php.ini
/etc/php/7.4/apache2/php.ini
/etc/php/7.4/apache2/php.ini.save
/etc/php/7.4/apache2/php.ini.ucf-dist
/etc/php/7.4/cli/php.ini
/etc/php/7.4/cli/php.ini.ucf-dist
/etc/php/7.4/fpm/php.ini
/etc/php/7.4/fpm/php.ini.ucf-dist
/etc/php/8.0/cli/php.ini
/usr/lib/php/5.6/php.ini-development
/usr/lib/php/5.6/php.ini-production
/usr/lib/php/5.6/php.ini-production.cli
/usr/lib/php/7.0/php.ini-development
/usr/lib/php/7.0/php.ini-production
/usr/lib/php/7.0/php.ini-production.cli
/usr/lib/php/7.1/php.ini-development
/usr/lib/php/7.1/php.ini-production
/usr/lib/php/7.1/php.ini-production.cli
/usr/lib/php/7.2/php.ini-development
/usr/lib/php/7.2/php.ini-production
/usr/lib/php/7.2/php.ini-production.cli
/usr/lib/php/7.3/php.ini-development
/usr/lib/php/7.3/php.ini-production
/usr/lib/php/7.3/php.ini-production.cli
/usr/lib/php/7.4/php.ini-development
/usr/lib/php/7.4/php.ini-production
/usr/lib/php/7.4/php.ini-production.cli
/usr/lib/php/8.0/php.ini-development
/usr/lib/php/8.0/php.ini-production
/usr/lib/php/8.0/php.ini-production.cli

The above output may not be very helpful in drilling down to the active php.ini file location.

You can use the PHP CLI to get the configuration file that is being used in your setup with the following command:

$ php -i | grep 'php.ini'

From the output look for the line similar to this:

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

You can also use the following to retrieve the same output:

$ php -r "echo php_ini_loaded_file().PHP_EOL;"

With the expected result being:

/etc/php/7.4/cli/php.ini

You can use PHPs phpinfo function as follows:

$ php -r "phpinfo();" | grep php.ini

With the following as the result.

Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini

In case you need to get the php.ini file location for the settings used by the webserver you will need to use the following function from within a PHP file created in the web server document root and accessed from a web browser.

echo php_ini_loaded_file().PHP_EOL;

There you have it you should now be able to find the php.ini file location in Ubuntu and Centos Linux servers including determining the one that is active.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Where is PHP ini file Linux?

ini is usually located in /etc/php/8.1/fpm/php.

How do I open a config PHP file in Ubuntu?

How to Edit PHP ini File in Ubuntu Terminal.
sudo nano /etc/php5/apache2/php.ini. sudo nano /etc/php5/apache2/php.ini. Change PHP parameters. ... .
max_execution_time = 60. max_execution_time = 60. Once you have changed the configuration values, save and exit the editor. ... .
sudo service apache2 restart. sudo service apache2 restart..

How do I find my PHP ini server?

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.

How do I change PHP settings in Ubuntu 20?

How to Modify the PHP Configuration File on Ubuntu.
Open the terminal and run the following command to open the php. ini file. ... .
Change the PHP settings. ... .
Once you modified the PHP configuration values as per your needs, save changes and exit editor..
Now restart the web server to enable the changes you have done..