How Do I Find php.ini File in WordPress?
If you’re dealing with WordPress, sooner or later you have to ask yourself this question. Although not directly connected to WordPress, php.ini is one of the most important configuration files on your server because it is responsible for configuring your PHP installation, and in such a way your WordPress site and php.ini often go hand in hand.
The most frequent parameter that you might need to change is upload_max_filesize. By default it’s 2Mb, which can be quite low. Other popular ones include register_globals, safe_mode, and max_execution_time. You can also use this file to enable or disable extensions of your PHP installation.
Depending on your system and server environment there are different places and ways you can find the php.ini file.
The best way to find php.ini
Whether you’re working on localhost, or on a live server, the most easy and proven way to locate your php.ini file is to create a php file with a single line of code in it, and view the output.
- Create a file (name it however you want, in our case it’s ‘test.php’), and make sure it ends with .php extension.
- Put this line of code in it:
<?php phpinfo(); ?>
- Open the file via your browser. For exapmple if you placed it into your root folder, run http://mywebsite.com/test.php.
Your php.ini file should be located either in the ‘Configuration File Path’ section, or like in my case in ‘Loaded Configuration File’ section. The first location is the default one, the second location applies in case your PHP installation is used as a module.
If in some cases creating a php file and inserting a single line of code doesn’t work for you, there are some other ways to find php.ini.
If you’re working locally, finding php.ini would depend on the server environment you’re using. Let’s go quickly through some of the most popular ones.
Left click on your WAPM server icon, then go to PHP -> php.ini. Easy? Easy.
XAMPP is a bit different beast, but also can be tamed without much difficulty. Run your XAMPP installation, right click the ‘Config’ button (in front of the Apache module) and here it is, our little guy:
If you’re on Linux, run the following command in the terminal:
php -i | grep "Loaded Configuration File"
It should output something like this:
Loaded Configuration File => /usr/local/lib/php.ini
In most cases the php.ini would be located in the ‘Loaded Configuration File’, but if it’s not there, replace the ‘Loaded Configuration File’ string with ‘Configuration File’.
The location of php.ini mostly depends on the hosting you’re using, but we’ll cover here some of the most common scenarios.
Open your file manager, and navigate to the root directory. Our little guy should be sitting at the bottom.
If you don’t know how to find your root folder, simply go one level up your main public_html directory.
Unfortunately, if you’re on a shared hosting, you cannot access your php.ini file. The workaround would be to specify the needed configuration settings in your .htaccess file in the following pattern:
php_value name value
The name here represents the name of the PHP property you need to change. The same applies to the value. For example this line changes the maximum uploaded file size to 8 Mb:
php_value upload_max_filesize 8M
Restart after the changes
If you made at least one change to php.ini file, you have to restart your server, otherwise the changes won’t apply. If you’re on Linux write the following command:
The WAMP users have to right click on the server icon in the toolbar, and choose ‘Restart all services’.
If you’re using XAMPP, go to the main dashboard, click the ‘stop’ button in front of the ‘Apache’ module, and then click the ‘start’ button again.
As you can see, finding php.ini can be both tricky and easy at the same time. I’ve tried to cover the most common solutions and server environments, and hope this guide would help you to finally locate this file. If you know any other ways to find php.ini, feel free to share your thoughts in the comments below.