Skip to main content
All CollectionscPanelPHP
How to edit PHP values via .htaccess
How to edit PHP values via .htaccess

Increasing PHP limits via the .htaccess file

Updated over 2 months ago

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, ensure your website, script, or application is optimized. Changing the limits is a temporary fix if your code has underlying issues, 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. While you can add a buffer for occasional usage spikes, avoiding allocating the maximum available PHP memory limit is best.

Step 2 – Edit the .htaccess file

Open the .htaccess file using the file editor. If the file is not present in the public_html folder of your website, create it.

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, click on Save to apply the changes.

If your project is growing, and you consistently need more resources, consider upgrading your hosting plan 🚀

Did this answer your question?