How Do I Know php.ini Location?

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 knowing php.ini location is important.



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 location.


What's php.ini Location?

Whether you’re working on localhost, or on a live server, the easiest 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.

  1. Create a file (name it however you want, in our case it’s ‘test.php’), and make sure it ends with .php extension.
  2. Put this line of code in it:
<?php phpinfo(); ?>
  1. Open the file via your browser. For example if you placed it into your root folder, run http://mywebsite.com/test.php.

You should see something like this:

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.


Other solutions

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.

Local server

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.


WAMP

php.ini on WAMP

Left click on your WAPM server icon, then go to PHP -> php.ini. Easy? Easy.


XAMPP

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:

php.ini XAMPP

Linux

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’.


Live server

The location of php.ini mostly depends on the hosting you’re using, but we’ll cover here some of the most common scenarios.

cPanel

Open your file manager, and navigate to the root directory. Our little guy should be sitting at the bottom.

php.ini cPanel

If you don’t know how to find your root folder, simply go one level up your main public_html directory.


Shared Hosting

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:

/etc/init.d/httpd restart

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.


Final words

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.


FAQ

What is php.ini?

It is a file that defines the work of all programs which demand PHP. It contains default configurations and controls such important things as resource limits and upload size.

Why could you need to find the php.ini?

As was previously said – it contains very important configurations for the apps that work on PHP. If you want to change some of them – you will need phph.ini.

What are the parameters that are changed the most frequently?

Well, first of all, it will probably be upload_max_filesize. The default value for it (2Mb) is commonly too small and website owners make it bigger. Besides that, chances are you would like to change the values of register_globals, safe_mode, and max_execution_time.

Read Also

How to Build & Maintain Elementor WordPress Website? [Free Course]

How to Build and Maintain an HTML5 Website? [Free Course]

Ultimate Gutenberg Editor Learning Course