Home » cPanel » Set up custom php.ini file for your website

Set up custom php.ini file for your website

In this article, we will see how to set up a custom php.ini file for your website.

It’s easy to change some of the PHP directives to match our script requirements.

First, we should know some facts about PHP directives. We have 3 levels of php.ini file:

  1. Server global php.ini (this file resides in the server configuration and it cannot be edited by the users in a shared hosting environment).
  2. User global php.ini (this file usually resides in the main folder for a user website, like public_html and this serves all the PHP scripts that hosted under the user account).
  3. User local php.ini file (this file is not limited to a specific path and can be created by the user wherever he feels he needs to change some parameters for some script).

How does this php.ini work?

PHP interpreter looks for the php.ini files from down upwards, meaning first it looks for a user local file, if the file is not there, it looks in the folder above and then above until it reaches the main folder of the user account. If it fails to find any custom/local user php.ini file, the interpreter uses the global php.ini file for directives.

You can have the global file to serve all your PHP directive needs. If you need a certain directive overwritten, you just need to create a php.ini file in the folder where your script resides and add that directive. The changes will only affect script files running on this folder and its subfolders. Parent folders will look for the php.ini file in their respective folder or their parent folder.

Now, let’s see how to create a php.ini file.

  1. Login into your control panel, open file manager

File Manager

  2. Navigate to the folder you wish to add php.ini file, click on “new file”, enter the name of the file which is php.ini

public_html

 

php.ini

3. Open the file in the editor by clicking on the edit button. And add the parameters you wish to change in the following order:

[PHP]
variable = value;
variabl2 = value2;

eg.

[PHP]

max_execution_time = 60;
memory_limit = 256M;

text_php.ini

– Save the file and exit.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*