Setting the PHP maximum upload file size in an .htaccess file
The upload_max_filesize directive in PHP defines the largest file size that can be uploaded through scripts. By default, this value is often set to 2 MB or 8 MB depending on the hosting environment. On ruachost.com, you can override this limit using a custom .htaccess file.
???? Why Change upload_max_filesize?
Section titled “???? Why Change upload_max_filesize?”-
Allow larger uploads (images, videos, PDFs, backups).
-
Support CMS platforms like WordPress or Joomla that require bigger limits.
-
Prevent errors such as:
The uploaded file exceeds the upload_max_filesize directive in php.ini.
Steps to Set upload_max_filesize in .htaccess
Section titled “Steps to Set upload_max_filesize in .htaccess”Step 1: Access Your Hosting Account
Section titled “Step 1: Access Your Hosting Account”- Log in to cPanel or use FTP/File Manager.
- Navigate to your site’s root directory (e.g.,
/public_html).
Step 2: Create or Edit .htaccess
Section titled “Step 2: Create or Edit .htaccess”- If
.htaccessalready exists, open it for editing. - If not, create a new file named
.htaccess.
Step 3: Add the Directives
Section titled “Step 3: Add the Directives”Insert the following lines:
php_value upload_max_filesize 64Mphp_value post_max_size 64M- Replace
64Mwith the desired size (e.g.,128M). - Always set
post_max_sizeequal to or larger thanupload_max_filesize.
Step 4: Save and Verify
Section titled “Step 4: Save and Verify”-
Save the
.htaccessfile. -
Create a test file
info.phpwith:<?php phpinfo(); ?> -
Load it in your browser and search for
upload_max_filesizeandpost_max_size. -
Confirm the new values are active.
-
Delete the test file afterward for security.
Best Practices
Section titled “Best Practices”- Increase gradually (e.g., 32M → 64M → 128M).
- Adjust related directives (
memory_limit,max_execution_time) for very large uploads. - Test uploads after making changes to ensure stability.