"Where is this damn php.ini?" — a question that drives even experienced developers crazy
\n\nHave you ever felt like a treasure hunter, but instead of gold, you were looking for php.ini? If so — you are not alone. The question "Where can I find php.ini?" on Stack Overflow has gathered tens of thousands of views. And this is no accident.
\n\nImagine: you installed PHP, wrote perfect code, but it stubbornly refuses to work. Or you change settings in php.ini, restart the server, but the changes... are not applied. Sound familiar? Welcome to the club.
\n\nIn this article, we will not just show where php.ini is located. We will break down the 5 most common errors that developers make and give clear instructions on how to avoid them. Let's go!
\n\nWhat is php.ini and why is it needed?
\n\nphp.ini is the main PHP configuration file. This is where you control the behavior of the language: from the maximum upload file size to the script execution time. Without it, PHP works "however it pleases" — with default settings.
\n\nHere are a few parameters you can change in php.ini:
\n\n- \n
upload_max_filesize— maximum upload file size \n max_execution_time— maximum script execution time \n memory_limit— memory limit for a script \n display_errors— whether to display errors on the screen \n error_reporting— error reporting level \n
The problem is that on different operating systems and environments, the location of php.ini differs. And this is the first trap for beginners.
\n\nWhere to look for php.ini: a cheat sheet for all OS
\n\nLinux (Ubuntu, Debian, CentOS)
\n\nOn Linux, the file can be in several places. The most popular ones:
\n\n/etc/php/8.1/cli/php.ini # for command line (CLI)\n/etc/php/8.1/apache2/php.ini # for Apache\n/etc/php/8.1/fpm/php.ini # for PHP-FPM\n\nNote: the PHP version (8.1) may differ. If you have PHP 8.0, the path will be /etc/php/8.0/....
How to find it quickly? Run in the terminal:
\n\nphp --ini\n\nThis command will show the path to the loaded configuration file.
\n\nWindows
\n\nOn Windows, php.ini is usually located in the PHP installation folder:
\n\nC:\\php\\php.ini\nC:\\Program Files\\PHP\\php.ini\nC:\\xampp\\php\\php.ini # if using XAMPP\nC:\\wamp64\\bin\\php\\php8.1.0\\php.ini # for WAMP\n\nmacOS
\n\nOn macOS (if PHP is installed via Homebrew):
\n\n/usr/local/etc/php/8.1/php.ini\n/opt/homebrew/etc/php/8.1/php.ini # for Apple Silicon\n\nIf you are using the built-in PHP from Apple (not recommended), the path may be different.
\n\nDocker
\n\nIn a Docker container, the path is standard for Linux:
\n\n/usr/local/etc/php/php.ini\n\nBut it's better to mount your own php.ini via volumes:
\n\ndocker run -v /path/to/your/php.ini:/usr/local/etc/php/php.ini my-php-app\n\nTop 5 errors when working with php.ini (and how to avoid them)
\n\nError #1: I am editing the wrong php.ini
\n\nThis is the most common problem. You open a file, change settings, restart the server, but PHP continues to work as before. Why? Because you changed the wrong file!
\n\nPHP can use different php.ini files for CLI (command line) and the web server (Apache/Nginx).
\n\nHow to avoid:
\n\n- \n
- Create a PHP file with the content: \n
<?php\nphpinfo();\n?>\n\n- \n
- Run it in the browser (if checking the web version) or in the terminal (
php yourfile.php). \n - Find the line Loaded Configuration File — this is the path to the active