Benjamin Crozat “Heard about Sevalla? They let you deploy PHP apps with ease.” Claim $50 →

This is the location of your php.ini

3 minutes read

This is the location of your php.ini

What is php.ini and why does it matter?

The php.ini file is a PHP configuration file used to control your PHP environment’s behavior. You might tweak it to increase memory limits, adjust error reporting, or handle file uploads. Official PHP docs cover all directives in depth.

Locate php.ini using phpinfo()

The fastest method PHP developers usually discover first is through phpinfo():

  • Create a new PHP file, index.php, and add:
<?php
phpinfo();
?>
  • Open the file in your web browser.

Look under “Loaded Configuration File” for the exact location.

phpinfo showing php.ini location

Locate php.ini using the command line

For command-line enthusiasts, PHP provides simple commands:

  • Open your terminal and run:
php --ini

The terminal output clearly shows the active php.ini path.

Terminal command to find php.ini

Alternatively, use:

php -i | grep "Loaded Configuration File"

Common php.ini locations (by OS)

Operating System Typical php.ini Location
Ubuntu/Debian (CLI) /etc/php/<version>/cli/php.ini
Ubuntu/Debian (Apache) /etc/php/<version>/apache2/php.ini
CentOS/Fedora /etc/php.ini or /etc/php/<version>/php.ini
macOS (Homebrew) /opt/homebrew/etc/php/<version>/php.ini
Windows (XAMPP/WAMP) C:\xampp\php\php.ini or C:\wamp64\bin\php\php<version>\php.ini

How to safely edit php.ini

  • Open the file in a text editor with admin privileges.
  • Make your changes (e.g., adjust memory_limit = 256M).
  • Save the file and restart your PHP service:

Apache:

sudo systemctl restart apache2

PHP-FPM:

sudo systemctl restart php<version>-fpm

Troubleshooting FAQ

Changes to php.ini not taking effect?

  • Ensure you’re editing the correct file (verify via php --ini).
  • Restart your PHP/Apache server.

Multiple php.ini files found?

  • PHP CLI and Web Server (Apache/Nginx) typically use separate php.ini files.
  • Check via phpinfo() in your browser vs. php --ini in your terminal.

Common php.ini directives cheat-sheet

Directive Default Purpose
memory_limit 128M Max memory per script
upload_max_filesize 2M Max upload file size
post_max_size 8M Max POST data size
max_execution_time 30 Max execution time (seconds)
error_reporting E_ALL Error reporting level

Conclusion

Now you know exactly how and where to find your php.ini file, tweak it safely, and troubleshoot common issues. Bookmark this guide for quick reference anytime you need it.


Did you like this article? Then, keep learning:

0 comments

Guest

Great deals for developers

Check all deals →