PHP php.ini Configuration File location

How to Find and Edit php.ini on Linux and Windows (Apache, Nginx, PHP-FPM)

Last updated on | 2 replies

The php.ini file is the core configuration file for PHP—it controls settings like maximum file upload size, memory limits, execution time, and more. Depending on your OS and environment (Apache, Nginx, PHP-FPM, CLI), php.ini can be located in various folders. In this guide, we’ll walk through multiple methods to locate—and safely edit—your php.ini in Linux or Windows.

Where Is php.ini Usually Stored?

Typical directory structures for Debian/Ubuntu-based systems:

  • CLI: /etc/php/8.4/cli/php.ini
  • Apache: /etc/php/8.4/apache2/php.ini
  • PHP-FPM (Nginx or Apache with FPM): /etc/php/8.4/fpm/php.ini

Replace 8.4 with your actual PHP version, such as 7.4 or 8.1. If you’re on an older Ubuntu (pre-16.04), you might see /etc/php5/ instead.

On Windows, the php.ini file is typically located where you installed PHP. Common examples include:

  • XAMPP: C:\xampp\php\php.ini
  • WAMP: C:\wamp64\bin\php\php8.4\php.ini
  • Manual Install: C:\php\php.ini or C:\Program Files\PHP\php.ini

If you’re using IIS, check the phpinfo() page or your PHP Manager settings in IIS Manager to confirm which php.ini file is in use.

Why Are There Multiple php.ini Files?

Because PHP can run under different modes, you might see multiple php.ini files. For example:

  • CLI: Settings only affect commands run directly in your terminal (e.g., php script.php).
  • Apache (mod_php): Used by the Apache module to execute PHP in the web server.
  • PHP-FPM: Runs PHP processes separately for Nginx or for Apache with FastCGI. Config changes here only affect sites using PHP-FPM.

Now that you know where php.ini is usually stored and why there might be multiple copies, let’s look at some practical ways to pinpoint exactly which file your server is using. The simplest approach is to create a quick PHP info page—let’s dive right into it.

Method 1: Use a PHP Info Page (Works on Most Setups)

One of the easiest ways to find out which php.ini file your server is using is to create a simple info page in your document root. Let’s call it info.php:

info.php
<?php
phpinfo();
?>

Next, load info.php in your browser (e.g., http://example.com/info.php). Press Ctrl + F (or Command + F on Mac) and search for “Loaded Configuration File.” You should see something like:

/etc/php/8.4/apache2/php.ini

This line shows the exact php.ini file your web server is using.

Method 2: Use Built-in Commands (Linux, Windows)

2.1 On Linux

Open your terminal and run:

php -i | grep "Loaded Configuration File"

The output will look something like:

Loaded Configuration File => /etc/php/8.4/cli/php.ini

Notice that this references the CLI version of PHP. For web server settings, you may need to specifically check the apache2 or fpm directories (see Method 1 or the next section below).

2.2 On Windows

Open Command Prompt and run:

php -i | findstr /c:"Loaded Configuration File"

This will also show you which php.ini is being used by the command-line version of PHP. IIS or other servers may be using a different file path.

Method 3: Use the locate Command (Linux)

You can also find php.ini files with locate:

locate php.ini

If locate isn’t installed, run sudo apt update && sudo apt install mlocate. This will display all instances of php.ini on your server. Check the paths, make your edits, and then restart your web server to see if it affects the desired PHP instance.

Editing php.ini on Linux

Apache (mod_php or libapache2-mod-php)

For Apache, it’s often /etc/php/8.4/apache2/php.ini. Edit with nano or vim:

sudo nano /etc/php/8.4/apache2/php.ini

After saving, restart Apache:

sudo systemctl restart apache2

Nginx or Apache with PHP-FPM

For Nginx or Apache with PHP-FPM, it’s often /etc/php/8.4/fpm/php.ini. Edit with nano:

sudo nano /etc/php/8.4/fpm/php.ini

Save and exit (press CTRL + X, press Y, then press ENTER)

After saving, restart the PHP-FPM and web server services:

sudo service php8.4-fpm restart
sudo systemctl reload nginx

Common php.ini Edits

  • memory_limit: Increase available memory for PHP scripts.
  • upload_max_filesize: Raise the max file upload size.
  • post_max_size: Increase the max POST request size (affects file uploads).
  • max_execution_time: Extend the maximum time a script can run.
  • error_reporting & display_errors: Adjust how PHP handles and displays errors (useful for debugging).

Always remember to restart your service (Apache or PHP-FPM) to apply changes.

Frequently Asked Questions

1. What if I’m on shared hosting or cPanel?

Many shared hosting providers let you edit php.ini or an equivalent .user.ini file via cPanel. Check your hosting documentation or contact support. Some hosts provide a “MultiPHP INI Editor” in cPanel for easy configuration changes.

2. Why aren’t my php.ini changes taking effect?

Remember to restart or reload your web server (Apache, Nginx) or PHP-FPM after editing php.ini. Also, verify that you’re editing the correct file (CLI vs. web server vs. FPM config).

3. Can I override php.ini settings via .htaccess?

Yes, if your server allows .htaccess overrides and you’re using mod_php with Apache. For example, php_value memory_limit 256M. This won’t work for PHP-FPM or Nginx setups—those require changes in php.ini or php-fpm.conf.

Conclusion

Finding the right php.ini can be confusing at first, especially when multiple configurations exist for CLI, Apache, or Nginx PHP-FPM. However, with the methods above—info.php, php -i, locate, or simply checking typical paths—you’ll be able to pinpoint and edit the correct file. Just remember to restart your services, and you’ll have complete control over your PHP environment.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

2 replies

Leave a reply

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