Php ini location linux

On the command line execute:

php --ini

You will get something like:

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/xdebug.ini,
/etc/php5/cli/conf.d/xsl.ini

That's from my local dev-machine. However, the second line is the interesting one. If there is nothing mentioned, have a look at the first one. That is the path, where PHP looks for the php.ini file.

You can grep the same information using phpinfo() in a script and call it with a browser. It’s mentioned in the first block of the output. php -i does the same for the command line, but it’s quite uncomfortable.

Php ini location linux

Last updated on June 7th, 2022 | 2 replies

As there are multiple versions of PHP with different sever configurations, php.ini could be located in several different folders.

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.

info.php

<?php
phpinfo();
?>

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

/etc/php/8.1/apache2/php.ini

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.

php -i | grep "Loaded Configuration File"

Or in Windows Command Line:

php -i | findstr /c:"Loaded Configuration File"

The result should be something like this:

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

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.6php7.4, etc.

To edit:

sudo nano /etc/php/8.1/apache2/php.ini

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.6php7.4, etc.

To edit:

sudo nano /etc/php/8.1/fpm/php.ini

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

You must restart Apache after altering php.ini.

sudo systemctl restart apache2

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

sudo service php8.1-fpm restart

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.6php7.4, etc.

sudo nano /etc/php/8.1/fpm/php.ini

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

You must restart Nginx after altering php.ini.

sudo systemctl reload nginx

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.

Where is the PHP ini file in Linux?

The default location for the php. ini file is: Ubuntu 16.04: /etc/php/7.0/apache2. CentOS 7: /etc/php.

Where is located PHP ini?

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

Where is PHP ini file in RHEL?

ini file is found at /etc/php. ini. There are also a couple more configuration files from the php package. The php package requires the httpd package to be installed, which makes sense as these are the configuration files that tell Apache how to work with PHP.

How do I find PHP ini Ubuntu?

the 'correct' one is in the apache2 subdirectory. – Joren. ... .
use updatedb; locate php. ini instead of find . ... .
@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..