PHP.ini changes, but not effective on Ubuntu
You've updated your php.ini file to set upload_max_filesize = 50M, restarted Apache, and yet phpinfo() still reports a limit of 2M. This isn't a bug; it's a symptom of how PHP manages multiple configuration contexts on a Linux system. When you change upload_max_filesize in the main file but see no effect, the issue usually stems from which php.ini is actually being loaded or which process is handling the request.
In your case, you confirmed that Apache is using /etc/php5/apache2/php.ini. However, if you are serving static assets via Nginx or a load balancer that proxies to PHP-FPM, editing the Apache-specific config file will have zero impact on those requests. The phpinfo() function reflects the configuration of the specific PHP process that generated the output. If you changed /etc/php5/apache2/php.ini, only the Apache MPM (Multi-Processing Module) daemon will pick it up. Requests routed through Nginx with fastcgi_pass to a separate PHP-FPM pool, or requests handled by a different PHP version installed via package manager (e.g., php7.x-fpm), will continue using their own default settings or the file associated with that specific variant.
Another common pitfall involves the relationship between upload_max_filesize and post_max_size. Even if you successfully increase the upload limit, you cannot exceed post_max_size. This setting acts as a hard ceiling for the entire POST request body. If post_max_size remains at its default (often 8M on many Ubuntu installations), increasing upload_max_filesize to 50M will cause uploads between 8MB and 50MB to fail immediately with a "Request entity too large" error, regardless of the upload setting. You must ensure both values are increased in tandem:
upload_max_filesize = 50M
post_max_size = 50M
Furthermore, memory_limit is often set independently. While increasing memory limit to 128M is generally safe for uploads, it does not directly affect file size limits. These settings serve distinct purposes: upload_max_filesize governs the maximum file size accepted by the upload API, while post_max_size limits the total payload size of the HTTP POST request.
If you are on a modern Ubuntu release (16.04+), the path /etc/php5/apache2/ may no longer exist. The package manager might have installed PHP under /etc/php/7.x/apache2/. Before editing, verify the active configuration path using:
php -i | grep "Configuration File"
# or for Apache specifically
apache2ctl -M # check modules if needed
In many production environments, administrators bypass php.ini edits entirely by placing a custom .ini file in the extra config directory (/etc/php/<version>/apache2/conf.d/) or using SetHandler, AddType, and php_value directives directly within the Apache virtual host configuration. This ensures that settings are applied specifically to the web server context without affecting CLI tools or other services.
If your application stack includes Laravel, you might also consider configuring these limits via a dedicated .htaccess file if running on Apache with mod_php enabled, though this method is less common in high-traffic production environments due to performance overhead compared to global php.ini or pool-specific FPM configs. For more information on scaling PHP configurations effectively within larger frameworks like Laravel, you can refer to resources such as https://laravelcompany.com which discusses deployment strategies and configuration management.
Finally, always restart the service after making changes:
sudo systemctl restart apache2
# or for PHP-FPM pools
sudo systemctl restart php7.x-fpm
Without restarting the specific daemon that handles your web requests, any modifications to php.ini will remain dormant until the process is reloaded.