How to Locate the PHP.ini Configuration File [Linux/Ubuntu]

Locate PHP ini configuration

Here’s a quick tip on how to locate the php.ini configuration file which is currently in use by PHP on your system or web host.

Locate PHP.ini From the Command Line

You can usually find out which php.ini file PHP is pulling its configuration from from the command line. The php -i command will print the information about your current PHP environment and grep will filter that output to only lines containing the string ‘Configuration File’, including it’s location:

php -i | grep 'Configuration File'

Finding the PHP.ini Configuration in Use for a Web Host

It is possible that your web server is using a different php.ini file to the one used for the whole system/command line – different virtual hosts may even be using different configuration files themselves. This is particularly common in shared hosting scenarios.

In this case, create a PHP file containing the following code:

<?php
var_dump( get_cfg_var('cfg_file_path') );
?>

When accessed from a web browser, it will print the location of the php.ini file in use for that web host.

SHARE:
nv-author-image

Brad Morton

I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Reply

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