You can set up your website to handle larger file uploads and execute PHP scripts more efficiently by adjusting some configurations on your website's .htaccess file. This will help you fix issues such as crashes or errors when uploading large files, script execution timeouts, or memory limitations while running resource-intensive PHP applications.
Step 1 – Preparations
First, make sure that your website, script, or application is optimized. Changing the limits is a temporary fix if there are underlying issues in your code, such as inefficient memory usage or memory leaks.
Next, check the fixed maximum PHP values on the PHP Info page of your hosting plan. The recommendation is to set values that meet your requirements while also leaving free resources for other essential processes. That is, while you can add a buffer for occasional usage spikes, it's best to avoid allocating the maximum available PHP memory limit.
Step 2 – Edit the .htaccess File
Once there, add the following lines at the end of the file:
php_value upload_max_filesize 256M
php_value post_max_size 256M
php_value memory_limit 512M
php_value max_input_time 180
php_value max_execution_time 180
Replacing the sample limits according to your desired values and click on Save to apply the changes.
If your project is growing and you consistently need more resources, consider upgrading your hosting plan 🚀