PHP logo with the text 'Find and Edit php.ini' on a purple geometric background.

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 PHP’s primary configuration file. It controls critical settings such as maximum file upload size, memory limits, execution time, and much more. Depending on your operating system and server setup (Apache, Nginx with PHP-FPM, CLI, etc.), the php.ini file can reside in different locations.

This guide will walk you through various methods to locate the active php.ini on both Linux and Windows, and explain how to edit it safely. We’ll cover setups for Apache (mod_php), Nginx (with PHP-FPM), and the PHP CLI, along with tips, common edits, and troubleshooting advice.

Where Is php.ini Usually Stored?

The location of php.ini varies by operating system and how PHP is installed. Below are some typical locations:

Linux

  • Debian/Ubuntu: CLI – /etc/php/8.x/cli/php.ini; Apache – /etc/php/8.x/apache2/php.ini; PHP-FPM – /etc/php/8.x/fpm/php.ini. (Replace “8.x” with your PHP version, e.g. 8.2. Note: Older Ubuntu versions (pre-16.04) used /etc/php5/... for PHP 5.)
  • Red Hat/CentOS (Fedora, AlmaLinux): /etc/php.ini (a single global php.ini for all PHP environments by default).

Windows

  • XAMPP: C:\xampp\php\php.ini
  • WAMP: C:\wamp64\bin\php\php8.x\php.ini (adjust the path for your PHP version)
  • Manual installation: C:\php\php.ini (or C:\Program Files\PHP\php.ini if PHP was installed in Program Files)
  • IIS (Windows Server): If using PHP on IIS, check a PHP info page or the PHP Manager in IIS Manager to find which php.ini is loaded. Typically, it resides in the PHP installation directory.

Why Are There Multiple php.ini Files?

You might notice more than one php.ini file on your system. This is because PHP can run under different modes (different SAPIs – Server API interfaces), each potentially using its own php.ini. Common scenarios include:

  • CLI: The command-line interface. Settings here affect PHP scripts run in a terminal (e.g., php script.php).
  • Apache (mod_php): PHP running as an Apache module. This php.ini is used by Apache to apply settings for PHP in web requests.
  • PHP-FPM (FastCGI Process Manager): PHP running as a separate process manager (commonly used with Nginx, or Apache via FastCGI). PHP-FPM generally has its own php.ini for these processes.

Each of these can have different configurations. For example, you might enable more error display in CLI for debugging but keep it off in the web server environment. Knowing which php.ini you need to edit is crucial for your changes to take effect in the right context.

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

One of the easiest ways to find out which php.ini file your web server is using is by creating a PHP info page. Save the following content to a file named info.php in your web server’s document root (e.g., /var/www/html/ for Apache on Ubuntu):

<?php
phpinfo();
?>

Upload this info.php file to your server and access it via a web browser (for example, http://your-server/info.php). The phpinfo() output will display a lot of information about your PHP environment. Use Ctrl + F (or Command + F on Mac) to search for “Loaded Configuration File”. You should see a line showing the path to the php.ini that is in use. For example:

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

In this example, the server is using the php.ini located at /etc/php/8.4/cli/php.ini. (If you ran the PHP info page under Apache, it might show .../apache2/php.ini; under PHP-FPM, it might show .../fpm/php.ini.) Once you’ve noted the location, remember to delete the info.php file from your server after use, as it exposes sensitive configuration information to anyone who can access it.

Method 2: Use the Command Line (Linux & Windows)

You can also determine the active php.ini by using PHP’s command-line interface and some simple commands.

On Linux

Open a terminal on your server and run:

php -i | grep "Loaded Configuration File"

This command prints the configuration file path for the PHP CLI. The output will look something like:

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

In this case, it shows the CLI’s php.ini path. If you need the php.ini used by your web server, remember it might be different. For example, if the above output points to .../cli/php.ini, the Apache module php.ini might be at .../apache2/php.ini, or the PHP-FPM one at .../fpm/php.ini. Use Method 1 or check the corresponding directory to find the exact file for your web service.

On Windows

Open the Command Prompt (or PowerShell) and run:

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

This will display the path of the php.ini used by the PHP CLI on Windows. In most cases, if you installed PHP on Windows (or are using something like XAMPP/WAMP), the web server will use that same php.ini file. However, if you have multiple PHP installations on Windows, the one used by IIS or Apache could differ. It’s a good idea to verify via a phpinfo page (Method 1) which php.ini is active for your web server in Windows if there’s any doubt.

Method 3: Use the locate Command (Linux)

On Linux systems, if you have the locate utility installed, it can quickly find files by name. To list all php.ini files on the server, run:

locate php.ini

If you get a “command not found” error, install the locate utility (on Debian/Ubuntu this is the mlocate package) and update its database:

sudo apt update && sudo apt install mlocate

After installing, update the database (usually updatedb runs automatically post-install). Then run locate php.ini again. You should get a list of all php.ini files on your system. There might be multiple results (for example, one for CLI, one for Apache, one for PHP-FPM, or even sample configuration files like php.ini-development). Identify the one that matches your environment’s path (as noted in the section above).

Tip: If locate is not available and you cannot install it, you can use the find command as an alternative (though it will be slower). For example:

sudo find / -type f -name "php.ini" 2>/dev/null

This will search your entire filesystem for any file named “php.ini”, ignoring permission errors (2>/dev/null). It might take a while, but it will eventually list out any php.ini files it finds, even if locate is unavailable.

Editing php.ini on Linux

Once you’ve located the correct php.ini file on a Linux system, you can edit it with your preferred text editor (via the command line). Because system configuration files require elevated privileges, remember to use sudo (or switch to root) when editing. It’s also a good idea to make a backup of the original php.ini before making changes. For example, you can run sudo cp /etc/php/8.4/apache2/php.ini /etc/php/8.4/apache2/php.ini.bak to back it up (adjust the path to the one you’re editing).

Below are instructions for editing php.ini in common Linux setups. After making changes in php.ini, you will need to restart the appropriate service for the changes to take effect (Apache, Nginx/PHP-FPM, etc.).

Apache (mod_php)

For Apache with PHP running as an Apache module (mod_php), the php.ini file is typically located at /etc/php/8.4/apache2/php.ini on Debian/Ubuntu. (On CentOS/RHEL, Apache uses the global /etc/php.ini.) Open the php.ini file in a text editor such as nano or vim:

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

Make the necessary edits to the configuration values in the file (for example, changing memory limits or upload sizes). After editing, save the file and exit the editor. Then restart Apache to apply the changes:

sudo systemctl restart apache2

On Debian/Ubuntu systems the Apache service is apache2 as shown above. On CentOS/RHEL, the service name is httpd, so you would run sudo systemctl restart httpd instead. Restarting ensures Apache picks up the new PHP configuration.

Nginx or Apache with PHP-FPM

For Nginx (which uses PHP-FPM) or Apache setups that use PHP-FPM (FastCGI), the php.ini file is typically /etc/php/8.4/fpm/php.ini on Debian/Ubuntu. (On CentOS/RHEL, PHP-FPM also uses the global /etc/php.ini by default.) Open this file for editing:

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

After saving your changes to php.ini, restart the PHP-FPM service and then reload (or restart) your web server to apply the changes. For example, on Ubuntu you can run:

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

This will restart PHP-FPM and gracefully reload Nginx. If you’re using Apache with PHP-FPM via FastCGI, you would restart PHP-FPM (as above) and you can reload Apache (though Apache doesn’t need a restart to use updated PHP-FPM settings, it’s often done as a precaution).

Editing php.ini on Windows

On Windows, first locate your php.ini file (using the methods above or knowing your installation path). Then open the file in a text editor like Notepad (or a code editor like VS Code). If the file is in a system-protected location (for example, under C:\Program Files), be sure to run your editor as an administrator so you can save the changes.

After making the desired changes in php.ini (such as adjusting upload size or memory limits), save the file. To apply the new settings, you must restart the environment in which PHP is running:

  • Apache on Windows (XAMPP/WAMP): Restart the Apache service. If you’re using XAMPP, you can use the XAMPP Control Panel (stop and start Apache). If you’re using WAMP, use the tray icon to restart Apache.
  • IIS (Internet Information Services): Restart IIS to load the updated PHP configuration. You can do this from IIS Manager or by running iisreset in an elevated Command Prompt.
  • CLI or Development Server: If you changed php.ini for CLI usage or a built-in development server, there’s no persistent process to restart — the next time you run the PHP script or start the dev server, it will use the updated settings.

Once the relevant service is restarted, the changes in php.ini will take effect. You can confirm the new values by running php -i again or reloading a phpinfo page.

Common php.ini Edits

Here are some of the most common configuration directives you might need to change in php.ini:

  • memory_limit – The maximum amount of memory a PHP script can use. Increase this if your applications need to handle large data or images.
  • upload_max_filesize – The largest file size that PHP will allow to be uploaded. Increase this for larger file uploads.
  • post_max_size – The maximum size of POST data that PHP will accept. This setting should be equal or larger than upload_max_filesize to accommodate file uploads.
  • max_execution_time – How long (in seconds) a PHP script is allowed to run before it’s terminated by the parser. You might raise this for long-running scripts.
  • error_reporting and display_errors – These control PHP error logging and display. In development, you might set error_reporting to a high level and display_errors to On to debug issues. In production, you’d typically log errors but not show them to users.
  • date.timezone – The default timezone used by PHP date/time functions. Set this to your timezone (e.g., UTC, America/Los_Angeles) to ensure date functions operate correctly and to avoid timezone warnings.

After modifying php.ini, always restart your web server or PHP process (as applicable) to load the new settings.

Frequently Asked Questions

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

If you’re on a shared host (or any environment where you don’t have direct filesystem access to php.ini), there are usually alternative ways to adjust PHP settings:

  • Many shared hosts provide a tool in the control panel (e.g., cPanel’s “MultiPHP INI Editor”) that lets you edit PHP configuration for your account. Use that interface to find and change settings like memory_limit, upload_max_filesize, etc.
  • Some shared hosting setups allow a custom php.ini (or a .user.ini) in your web root or home directory. You can create or edit this file to override certain PHP settings for your site. Check your host’s documentation for the supported method.
  • If your site is using Apache with mod_php on the host, you might be able to use an .htaccess file to override PHP settings (see the next question for an example). Note that this doesn’t apply to PHP-FPM setups.

When in doubt, contact your hosting provider’s support or documentation — they often have specific instructions for changing PHP settings on their platform.

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

If you edited php.ini but aren’t seeing the changes apply:

  • Did you restart the service? Remember to restart your web server or PHP-FPM process after saving php.ini. Until the service is restarted (or reloaded), it continues using the old settings.
  • Are you editing the correct php.ini? Double-check the path of the file you modified. Use phpinfo() or php -i to confirm the “Loaded Configuration File” path. It’s a common mistake to edit /etc/php/X/cli/php.ini when the server is actually using /etc/php/X/fpm/php.ini, for example.
  • Caching issues: If you use an opcode cache like OPcache, sometimes changes in php.ini (especially disabling functions or extensions) might be cached. A restart usually clears this. Also, some distributions have a separate php.ini for Apache vs CLI — ensure both are updated if needed.

After making sure of the above, you can verify the effect by running a phpinfo page or php -i again to see if your new settings are reflected.

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

If you’re using Apache with PHP as a module (mod_php), yes — you can override many php.ini settings in a .htaccess file using the php_value and php_flag directives. For example, to change the PHP memory limit for a specific directory via .htaccess, you could add:

php_value memory_limit 256M

This would set the memory_limit to 256M for PHP scripts in that directory (and subdirectories). Keep in mind:

  • .htaccess PHP overrides only work when PHP is running as an Apache module. They do not work for PHP-FPM or when using Nginx (which doesn’t use .htaccess at all).
  • For PHP-FPM or Nginx setups, you cannot use .htaccess. Instead, you must change php.ini or use per-directory .user.ini files (if enabled in PHP configuration). By default, PHP (when used as CGI/FPM) supports .user.ini files in each directory (similar in concept to .htaccess, but only for PHP settings).
  • Not all settings are overrideable in .htaccess. Some may be marked PHP_INI_SYSTEM which means they can only be changed in php.ini or the server configuration.

In summary, use .htaccess for Apache/mod_php overrides and php.ini (or .user.ini) for everything else.

Conclusion

Finding and editing your php.ini file might seem tricky at first due to different configurations and environments, but using the methods outlined above will help you pinpoint the correct file. Whether you’re on a Linux server or a Windows machine, the key steps are: identify the active php.ini, make a backup, edit the needed settings, and then restart the appropriate service. By doing so, you gain fine-grained control over PHP’s behavior on your system, allowing you to optimize performance, increase limits for your applications, and enable or disable features as needed.

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 *