Knowledge Base

How to set up custom php.ini files

This article describes how to use custom php.ini files to control PHP settings for your web site.

The information in this article only applies to certain types of hosting accounts. To determine whether or not the information below applies to your account, please see this article.

To watch a video that demonstrates the following procedures, please click below:

Setting up a custom php.ini file

A php.ini file contains directives for controlling many PHP settings. You can set up one or multiple custom php.ini files to define how your web site functions. For example, you might have a custom file in your /home/username/public_html directory for your web site's main pages, and a separate custom file in your /home/username/public_html/images directory for your web site's image files.

To set up a custom php.ini file, follow these steps:

  1. Log in to your Webhost.Berlin account using SSH.
  2. There are several php.ini sample files that you can use as a starting point for your own custom configuration:
    • There is a template php.ini file located at /usr/local/lib/php.ini.
    • There are php.ini files for multiple PHP versions located at /opt/php/php-version/lib/php.ini, where version represents the PHP version number.
  3. To copy one of these files to your web site's document root directory, type the following command, where path represents one of the paths listed above, and username represents your username:

    cp path/php.ini /home/username/public_html/php.ini
  4. To make the php.ini file accessible to the web server, but inaccessible to the public, type the following commands:

    cd /home/username/public_html
    chmod 640 php.ini
  5. After you copy the php.ini file and set its permissions, you can verify that the configuration is active. To do this, create a PHP test file that contains the following code in the same directory where the php.ini file is located:

    <?php phpinfo(); ?>
  6. Load the test file in your web browser, and locate the Loaded Configuration File heading. If the php.ini configuration is active, then the listed path and filename correspond to the php.ini file location.
  7. You can create custom php.ini files for each directory in your web site, but many people configure settings in one php.ini file and then apply it to the entire web site. To do this, add the following line to the .htaccess file in your web site's document root directory. Replace username with your Webhost.Berlin username:

    SuPHP_ConfigPath /home/username/public_html/
    The custom PHP file must be named php.ini. You cannot use an alternate filename (for example, php.ini-test).

More Information

To view a complete list of php.ini directives, please visit http://www.php.net/manual/en/ini.list.php.