Why Modifying php.ini Directly Often Fails in Laravel
Attempting to increase post_max_size and upload_max_filesize by editing a system-wide php.ini file is a common approach, but it frequently results in the settings not taking effect. This happens because modern PHP environments, particularly those running on Linux or managed servers, rarely rely solely on a monolithic configuration file. Instead, they often use virtual hosting configurations or separate process managers that override global defaults. When you see values like 5M in your phpinfo() output despite adding directives to the main php.ini, it usually means the web server is not using that specific file for the PHP-FPM or Apache process handling your requests.
In a typical Laravel deployment, you might have multiple configuration layers interacting. The system-wide php.ini sets baseline defaults, but the actual active configuration often resides in php-fpm.d/ directories (on Linux) or within .ini files specific to the virtual host (on Apache/Nginx). If you simply reset your environment like WAMP after editing the global file, you might be restarting the wrong service instance or missing a per-directory override that resets the value back to default.
To correctly apply these changes in Laravel, you must identify which configuration file is actually loaded for your specific PHP process. Run php -i | grep "Loaded Configuration File" from your server terminal. This command reveals the exact path of the active configuration. If this returns a path pointing to a system directory (e.g., /etc/php/8.1/fpm/php.ini), you should edit that file directly. However, if it shows none, the values are likely being set via php-fpm.d/www.conf or the Apache virtual host configuration files.
For instance, on a standard Linux setup using PHP-FPM, editing /etc/php/8.1/fpm/php.ini is often insufficient. You must also check /etc/php/8.1/fpm/conf.d/. The settings in these conf.d files take precedence over the main php.ini. If you increase upload_max_filesize in php.ini but leave a conflicting value in conf.d, your changes will be ignored. Ensure that any directive added to the conf.d directory is consistent with your needs and that no other file overrides it later in the load order.
When working with Nginx, remember that post_max_size and client_max_body_size are distinct concepts. Modifying PHP settings alone will not suffice if Nginx rejects the request before it reaches PHP. You must also update the nginx.conf or your server block configuration to allow larger payloads:
# Inside your nginx server block
client_max_body_size 10M;
post_max_size 9M;
If you are using Apache, ensure that php_admin_value directives in .htaccess or the virtual host config do not override your changes. Note that php_admin_value takes precedence over php_value, so if you see a directive defined as php_admin_value upload_max_filesize in your Apache config, editing the PHP file will have no effect.
After making these changes, always restart the specific service responsible for handling PHP requests. On Linux with systemd, this usually involves restarting php-fpm:
sudo systemctl restart php8.1-fpm
Or if using Apache directly:
sudo systemctl reload apache2
Once restarted, verify the changes by creating a new info.php file in your public directory with <?php phpinfo(); ?>, then visiting it through your browser or running php -i via SSH. Ensure that both post_max_size and upload_max_filesize reflect your desired values.
If you are deploying on a shared hosting environment, these options may be locked down entirely. In such cases, you must contact your host to request an increase in upload limits. For production Laravel applications, managing large file uploads also involves optimizing the max_file_size limit in Laravel's configuration and ensuring the storage driver handles large files efficiently without exhausting memory.