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 carried over when we upgrade or migrate servers. - Due to a technical limitation in CloudLinux, configurations set in the "Select PHP Version" interface might not be carried over when we upgrade or migrate servers.
Modify PHP Configuration
Using the PHP Selector:
- Go to cPanel > Select PHP Version > Options.
On DirectAdmin: DirectAdmin > Select PHP Version > Options. - Type in the values as needed.
- Done!
Using the [.htaccess] File:
- 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 on the file and click Edit. - Add the following directives to the [.htaccess] file, one in each line. Add only the ones you need:
- Memory Limit
php_value memory_limit 512M
Replace 512 with the limit you want in megabyte. 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 62M
php_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 180
php_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.php
http://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.
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
.