Suppose you are using a shared hosting environment and want to control the maximum size of file uploads for your PHP applications (like WordPress, Laravel, etc.). In that case, you can often do this by modifying the php.ini file provided by your host that allows custom PHP settings.
This guide shows how to increase or limit the upload size using php.ini in shared hosting.
Follow the steps to change upload limits using php.ini in Shared Hosting:
- Check if Your Hosting Supports Custom php.ini:
Some shared hosting providers allow a per-directory php.ini. Check your control panel (like cPanel) or ask support whether you can use custom php.ini files. - Create or Edit the php.ini File:
- In the root directory of your website (e.g., public_html), create or edit a file named:
ini
- Add or update the following lines:
upload_max_filesize = 10M post_max_size = 12M max_execution_time = 30
Here’s what these settings do:
- upload_max_filesize defines the maximum size allowed for a single file upload.
- post_max_size sets the maximum size of the entire POST request, which should be slightly higher than upload_max_filesize.
- max_execution_time determines how long a PHP script is allowed to run before timing out (useful when uploading large files).
You can increase the values (e.g., 20M, 50M) based on your requirements.
- In the root directory of your website (e.g., public_html), create or edit a file named:
- (Optional) Modify .htaccess if php.ini doesn’t work:
If php.ini changes aren’t applied, try adding these lines to your .htaccess file (in the same directory):php_value upload_max_filesize 10M php_value post_max_size 12M php_value max_execution_time 30
Note: Not all shared hosts allow .htaccess PHP directives. If your site throws a 500 error after this, remove these lines.
- Check if the Changes Are Applied by Creating a PHP Info File:
<?php phpinfo(); ?>
Upload the file to your hosting account, open it in your browser, and check the values for upload_max_filesize and post_max_size.
Important Notes:
- post_max_size should be larger than upload_max_filesize.
- Restarting the web server isn’t necessary in shared hosting, as changes are applied automatically (if supported).
- Always delete the phpinfo.php file after checking, to avoid exposing server info.
Setting file upload limits via php.ini in shared hosting is simple and improves security and performance. If changes don’t apply, try .htaccess or contact our support team for help.
A cPanel Web Hosting solution gives you the flexibility to manage PHP configurations, website resources and application requirements with ease.
Need broader control over upload limits? Learn How to change the maximum upload file size for your website