Aller au contenu

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.

Ruachost servers run LiteSpeed, which reads PHP settings from .htaccess files.

  1. 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.
  2. Edit .htaccess (create it if it doesn’t exist) and add the settings you need at the end:
php_value memory_limit 1024M
php_value upload_max_filesize 256M
php_value post_max_size 256M
php_value max_execution_time 300
php_value max_input_vars 20000
php_value date.timezone Africa/Lagos
php_flag display_errors Off
php_value output_buffering 4096

Some 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.

You can also create a file called .user.ini in the folder, with settings written like this:

memory_limit = 1024M
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 300
date.timezone = "Africa/Lagos"

PHP checks .user.ini files every few minutes, so changes may take up to 5 minutes to apply.

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().

  • 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_limit won’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.

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é ?