If you are a PHP programmer, you know the power of php.ini file.
It basically a configuration file which set’s rules for php function and variable.
Sometimes a programmer required changing its default variable as per application requirement.
In this article you will learn about how to find PHP.INI location on any environment.
And even create your PHP.INI for more controls.
Create a PHP Information Page
As PHP.INI file contain all the instruction about the PHP functions and PHP working, We can create a file to display all these instruction with a simple function called phpinfo().
Create a empty file and name it phpinfo.php (or anything you like with php extension at the end of file name).
Add following code in the file.
<?php phpinfo(); ?>
Upload / Save the file and access it through url.
The file should give you display similar to image below.
Your PHP.INI location path can be found under Loaded Configuration File header.
Now, you have your PHP.INI location, the question arises “Can you edit it ?”.
How to edit PHP.INI file?
The short answer for “can you edit php.ini file?”.
The answer is Yes, you can.
Editing PHP.INI at localhost environment.
If you are in localhost environment or have full administrator / root access , simple visit the location of the PHP.INI file and edit it.
I recommend making a backup of the original PHP.INI file before modifying it.
Editing PHP.INI at Linux Shared Hosting
Shared hosting service does not allow you to modify the main php.ini file. however, there is a workaround for this problem.
The PHP Information page creation part remains the same as mentioned on first part of this article.
The path shown under the php.ini location header will not be accessible by you due shared hosting limitation.
The simple workaround is to create your own PHP.INI file.
Login to your Cpanel Control panel provided by Netspace (India) or your hosting provider.
Create a file and name it php.ini under public_html.
once you created a file, started defining your setting for PHP under php.ini created by you.
Your PHP will now start taking configuration for your custom PHP.INI in place of default file.
You can verify this be reloading your main PHPINFO.PHP file, which will show output something like the image show below.
Now, you will notice the loaded configuration file path has been changed to your custom php.ini file.
Let me know if you have any related query on the comment below, and I will be happy to help.