PHP configuration (directives) like PHP memory limit, maximum upload size, post max size, and others can be set or changed using a [.htaccess] file. WordPress and other content management systems create a [.htaccess] file by default to store various configurations.
Note:
- We recommend you use the [.htaccess] file to modify the PHP configuration.
Configurations in the [.htaccess] file will be preserved during server upgrades or migrations. - Due to a technical limitation in CloudLinux, configurations set in the "Select PHP Version" interface may not be carried over during server upgrades or migrations.
Modify PHP Configuration in PHP Selector
Use either the PHP Selector or the .htaccess file to modify the PHP configuration. Do not use both:
- Go to cPanel > Select PHP Version > Options.
On DirectAdmin: DirectAdmin > Select PHP Version > Options. - Type in the values as needed.
- Done!
If the desired value cannot be set or the directive is not present in the PHP Selector, use the .htaccess file to modify the PHP configuration.
Modify PHP Configuration in .Htaccess
No need to modify the .htaccess file if you changed the PHP configuration in the PHP Selector:
- Go to cPanel > File Manager > [public_html] (or to the directory where your website files are).
If you do not see the [.htaccess] file, enable "Show Hidden Files (dotfiles)" in "Settings" (on the top right of the window). - Select the [.htaccess] file and click Edit.
Or right-click the file and select Edit. - Add the following directives to the [.htaccess] file, one on each line. Add only the ones you need:
- Memory Limit
php_value memory_limit 512M
Replace 512 with the desired limit in megabytes. Larger values do not necessarily provide better performance. Consider assigning a value that is required for your website. - Maximum Upload File Size and/or Post Max Size
php_value upload_max_filesize 62Mphp_value post_max_size 63M
For file uploads to work correctly, the post_max_size directive should be slightly larger than the upload_max_filesize. For example, to set a file upload limit of 62 MB, you could set the upload_max_filesize directive to 62M and the post_max_size directive to 63M. - Maximum Execution Time and/or Maximum Input Time
php_value max_execution_time 180php_value max_input_time 180
Replace 180 with the value you want in seconds. - Maximum Input Variables
php_value max_input_vars 1000
Replace 1000 with the value you want. - Time Zone
php_value date.timezone 'Region/Zone'
Replace Region/Zone with your time zone to change the time zone that PHP uses for your scripts.
List of supported time zones in PHP:http://www.php.net/manual/en/timezones.phphttp://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone - Display PHP Error
php_flag display_errors On
Do not enable this directive unless you are debugging or troubleshooting, as it can expose vulnerable information about your website.
- Memory Limit
- Save the changes to the [.htaccess] file and exit the editor.
- Done!
Verify
To verify that the new setting is active:
- Create a PHP test file that contains the following code in the same directory where the [.htaccess] file is located:
<?php phpinfo(); ?> - Load the test file in your web browser and search for the directive's name. The Local Value column should display the new setting that you specified in the [.htaccess] file.
Troubleshooting
If you increased the memory_limit but WordPress does not see the new value, you likely have a limit in the wp-config.php file:
define('WP_MEMORY_LIMIT', '3072M');define('WP_MAX_MEMORY_LIMIT', '3072M');
WP_MEMORY_LIMIT: Limit for front-end site operations.
WP_MAX_MEMORY_LIMIT: Limit for admin dashboard for admin/backend tasks (e.g., plugin updates, image processing).
- Go to cPanel > File Manager > [public_html] (or to the directory where your website files are).
- Select the [wp-config.php] file and click Edit.
Or right-click the file and select Edit. - Modify the values of WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT as desired.
Or, comment out the lines to disable them:// define('WP_MEMORY_LIMIT', '3072M');// define('WP_MAX_MEMORY_LIMIT', '3072M'); - Done!
More Information
- Complete list of PHP directives
https://www.php.net/manual/en/ini.list.php. - memory_limit
https://www.php.net/manual/en/ini.core.php#ini.memory-limit.
upload_max_filesize.
https://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
post_max_size.
https://www.php.net/manual/en/ini.core.php#ini.post-max-size
display_errors.
http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors
max_execution_timehttp://www.php.net/manual/en/info.configuration.php#ini.max-execution-time.
date.timezonehttp://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone.
