How to set up custom php.ini files

Domain - Web - VPS - Hosting - Apache - NginX - Tomcat ...
Post Reply
User avatar
Posts: 19
Joined: 08 May 2018 22:28
Location: Vietnam

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

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:

Log in to your VPS account using SSH.
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.

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:

Code: Select all

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

Code: Select all

    cd /home/username/public_html
    chmod 640 php.ini
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:

Code: Select all

<?php phpinfo(); ?>
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.

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 A2 Hosting username:

Code: Select all

    SuPHP_ConfigPath /home/username/public_html/
Post Reply