Hey there, folks! Today, we’re going to have a chat about PHP – more specifically, one of the most important files in any PHP installation. I’m talking about php.ini. This handy little file is used for everything from installing php libraries to updating plugins to configuring your entire server – so it’s kind of important. And it’s also more than a little distressing when you can’t find it. Today, we’re going to go over a few tips, tricks, and methods you can use to locate your PHP configuration file when it isn’t where it’s supposed to be.
Where IS php.ini Usually Located?
Unfortunately, here’s where things get a little complicated. The location of php.ini depends on a number of different factors, including your host, the control panel you’re using, and the operating system your server’s running on. On Linux, it might occasionally be found in /etc/php.ini or /usr/bin/php/php.ini. On Windows, it might be located in your control panel’s directory, in C:\php\php.ini, or in C:\program files\php\php.ini.
It gets worse. Some PHP installations can be set up in such a way that there are multiple php.ini files, meaning that if you don’t know exactly what you’re doing, you’re in for some serious guesswork as to which one’s the right one to modify. What’s a server admin to do?
Tracking Down An AWOL PHP Configuration File
Alright, first thing’s first, let’s start with what you can do if you’ve got no idea where your PHP file can be found. Thankfully, this actually isn’t a terribly complicated process. All you need to do is create and run a very simple script; courtesy of OS Training.
Using a script editor or plain text editor, create a file called phpinfo.php. Make sure you don’t use a word processor – they tend to contain markup code that can bork up your script. Anyway, once you’ve created the php file, open it and enter the following code:
<?php phpinfo(); ?>
Save it, then upload the file to your main HTML directory. Next, you’ll access it at http://yoururl.com/phpinfo.php. This will cause your browser to display a complete list of your PHP settings, including your PHP version and the location of php.ini. Easy, right?
There’s also the ‘Loaded Configuration File’ command:
/usr/local/bin/php -i | grep ‘Loaded Configuration File’
Differentiating Between Different Configuration Files
Now, let’s say you’re using a server that’s got multiple different php.ini files. How can you discern which is which – and avoid modifying the incorrect one? Although your phpinfo.php file will show you the currently loaded configuration file, what happens if you’re looking to edit one that’s related to a specific user or application?
In this case, I’d advise you to take a look at the directory of each file. Likely as not, the configuration file for the system, plugin, or program you want to modify will be in the relevant subdirectory – so, for example, a php.ini file connected to Apache would be in the Apache subdirectory of your PHP folder. Makes sense, right?
Of course, if you’re still lost, you could always try making use of the php_ini_loaded_file command. It’ll show you whether or not a particular php.ini file is loaded, and show you where it can be located.
If your server’s using PHP in any way, shape, or form, then php.ini is hands-down one of the most valuable and important files you’ll work with. It’s imperative that you know exactly where it is. Otherwise, you’re likely going to end up running into more than a little trouble when you try to configure PHP.
Image credit: Cal Evans
Complete Digital Server Solutions For All
A single tenant, physical server allowing you full access to its resources.
Virtualized server platform hosted on enterprise-grade physical servers.
High-performance and highly-available infrastructure, delivering a reliable, secure, and scalable solution.