Ubuntu自建LAMP服务器上传限制无法突破2MB,急求技术支持
Hey there, I feel your pain—trying to upload a premium theme but hitting that stubborn 2MB limit even after tweaking settings is super frustrating. Let’s walk through a thorough troubleshooting process tailored to Ubuntu’s LAMP setup:
1. Locate & Edit the Correct php.ini Files
Ubuntu often has separate php.ini files for CLI and web server contexts, so you might’ve edited the wrong one without realizing it.
- First, find the
php.iniused by Apache:
This will output a path likephp -i | grep "Loaded Configuration File"/etc/php/8.1/apache2/php.ini(adjust the version number to match your PHP install). - Open this file with a text editor (e.g., nano):
sudo nano /etc/php/8.1/apache2/php.ini - Update these critical parameters (set values larger than your theme’s file size—64M is a safe default for most premium themes):
upload_max_filesize = 64M post_max_size = 64M # Must be equal to or larger than upload_max_filesize memory_limit = 128M max_execution_time = 300 # Gives enough time for large file uploads - Save the file (Ctrl+O, Enter, then Ctrl+X in nano) and restart Apache to apply changes:
sudo systemctl restart apache2
2. Check for .htaccess Overrides
If your website uses an .htaccess file (common with WordPress, Drupal, etc.), it might be overriding your php.ini settings.
- Navigate to your site’s root directory and open
.htaccess:sudo nano /var/www/html/.htaccess - Look for lines like these—if they exist, update the values:
php_value upload_max_filesize 64M php_value post_max_size 64M php_value memory_limit 128M php_value max_execution_time 300 - If the lines aren’t present, add them to enforce your desired limits. Save and close the file.
3. Verify PHP-FPM Settings (If Using FPM)
Many modern LAMP setups use PHP-FPM instead of mod_php. If that’s your case:
- Find the FPM
php.inifile (path example:/etc/php/8.1/fpm/php.ini) and repeat the parameter updates from step 1. - Restart PHP-FPM and Apache:
sudo systemctl restart php8.1-fpm sudo systemctl restart apache2
4. Confirm Changes Are Active
Create a quick test file to verify your settings took effect:
- Make a
phpinfo.phpfile in your site’s root:sudo nano /var/www/html/phpinfo.php - Add this content:
<?php phpinfo(); ?> - Save the file, then visit
http://your-server-ip/phpinfo.phpin a browser. - Search for
upload_max_filesizeandpost_max_size—they should show your updated values. If not, double-check that you edited the correctphp.inifile and restarted the right services.
5. Check CMS-Specific Limits
If you’re using a CMS like WordPress, double-check its internal settings:
- For WordPress: Go to Settings > Media and ensure the "Max upload file size" matches your PHP settings. Some themes/plugins might override this, so you may need to adjust it here too.
If you still run into issues, share details like your PHP version, Apache version, and which CMS you’re using—that’ll help narrow down the problem further.
内容的提问来源于stack exchange,提问作者kaos

