PHP php.ini Configuration File location

Where is my PHP php.ini Configuration File Located?

Last updated on

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/7.2/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/7.2/cli/php.ini

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

CLI

/etc/php/7.2/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/7.2/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/7.2/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.

Editing php.ini in Linux

Apache

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

To edit:

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

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

To edit:

sudo nano /etc/php/7.2/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 php7.2 with your own version, e.g, php5.6php7.1, etc.

sudo service php7.2-fpm restart

Nginx

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

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

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

You must restart Nginx after altering php.ini.

sudo service nginx restart

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 in the comments if this helped. Follow me on Twitter, Facebook and YouTube.

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

1 Star2 Stars3 Stars4 Stars5 Stars 4.67 (18 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces