Custom PHP settings for one folder (.htaccess and .user.ini)
Ce contenu n’est pas encore disponible dans votre langue.
Most people should change PHP settings in cPanel’s Select PHP Version → Options. Those settings apply to your whole account. See Changing your PHP version and settings.
Use the methods below only when one folder or app needs different settings from the rest of your account. They change settings only, not the PHP version. Your PHP version is always the one chosen in Select PHP Version.
Method 1: .htaccess (recommended)
Section titled “Method 1: .htaccess (recommended)”Ruachost servers run LiteSpeed, which reads PHP settings from .htaccess files.
- In cPanel’s File Manager, open the folder, for example
public_html/shop. Click Settings and tick Show Hidden Files so you can see.htaccess. - Edit
.htaccess(create it if it doesn’t exist) and add the settings you need at the end:
php_value memory_limit 1024Mphp_value upload_max_filesize 256Mphp_value post_max_size 256Mphp_value max_execution_time 300php_value max_input_vars 20000php_value date.timezone Africa/Lagosphp_flag display_errors Offphp_value output_buffering 4096Some settings, such as output_buffering, aren’t in Select PHP Version and can only be changed this way. Use php_value for numbers and text, and php_flag for settings that are On or Off. The settings apply to the folder and every folder inside it.
Method 2: .user.ini
Section titled “Method 2: .user.ini”You can also create a file called .user.ini in the folder, with settings written like this:
memory_limit = 1024Mupload_max_filesize = 256Mpost_max_size = 256Mmax_execution_time = 300date.timezone = "Africa/Lagos"PHP checks .user.ini files every few minutes, so changes may take up to 5 minutes to apply.
Check that it worked
Section titled “Check that it worked”Create a file called info.php in the same folder containing <?php phpinfo();, open it in your browser, and look for the setting. The Local Value column shows the value for that folder. Delete info.php when you’re done. See Viewing PHP settings with phpinfo().
What you can’t change
Section titled “What you can’t change”- The PHP version per folder. One PHP version applies to your whole account.
- Limits above your plan’s resources. For example, a 2 GB
memory_limitwon’t help if your plan has less RAM. See PHP memory limit vs your plan’s RAM. - Some server-wide security settings, which are locked for all accounts.
Cron jobs and the command line
Section titled “Cron jobs and the command line”Settings in .htaccess don’t apply to cron jobs or scripts run over SSH. See Using a custom php.ini file for cron jobs.
Cette page vous a-t-elle aidé ?
Merci pour votre retour.