Two Ways to Modify your WHM PHP.INI Memory Limit

Posted on Updated on

Your php.ini file contains most of the settings that determine the environment within which your applications will run. If you’re a user running on a shared web hosting environment, you will most likely have your own local php.ini file with specific settings that override the global ones. However, if you are a WHM administrator and wish to change your php.ini file, it’s important that you know exactly where the master file is located as well as how to go about it. In addition, you need to have the proper permissions as well as restart Apache afterwards.

In this article, I’m going to look at a test example of changing the amount of memory that PHP uses for its applications. This prevents a poorly written or a rogue script from consuming all of the memory on your server. The variable in the php.ini file is called “memory_limit”. The two ways to modify this are:

  1. Via SSH;
  2. Using the GUI within WHM.

According to the WHM documentation, the second one is preferred since it’s safe and there’s no danger of messing things up. But in case you’re confident about what you want and wish to make the changes directly, we can do that as well. Let’s look at each of these methods in detail:

Changing php.ini with SSH

To change this file via SSH, you need to login with the requisite permissions. This usually means having the access of the root user. Without this, you might be able to read the php.ini file, but you won’t be able to save any modifications you make to it. If you’ve done the smart thing and disabled direct root logins into SSH and added your own username to the Wheeler group, you need to first login as yourself and then switch over to root.

The main php.ini file is located in the following directory:


We can open it up simply by typing in:

vi /usr/local/lib/php.ini

edit php ini command line

Once php.ini is ready for editing, we search for the “memory_limit” variable by first typing in a “:” to enter command mode and then write:


You can see the screenshot below that this locates the line containing the parameter we want. Hit the “Insert” button and this will allow you to change the memory limit. In this example, I’m modifying it from 128 MB to 256 MB.

change memory limit

Exit the insert mode by pressing “Esc” and then once again enter the command mode via the “:” , simply type “x” and hit “Enter”. this will save everything and return you to the command prompt. Now that php.ini has been modified, we need to restart Apache via the following command:

service httpd restart

Do that, and you’re all set. The PHP configuration has been changed. When done quickly, the whole process doesn’t take more than a few seconds and is faster than the GUI. But if you’re just starting off, or don’t want to use the SSH command line, here’s how to do the same thing via the WHM interface.

Changing php.ini Through the GUI

To make the php.ini changes via the WHM dashboard, login and select “PHP Configuration Editor” from the menu on the left-hand side.

php configuration editor

In the resulting page, scroll down till you find the “memory_limit” variable and change the number to something else. In this example, I want to modify it back from 256MB to 128 MB (reversing the change I made in the last step).

change memory from GUI

Then simply scroll all the way down and save your changes. When this succeeds, the system will then display your PHP.ini file to you in the text box so you can verify that the settings have indeed been modified:

php file written

Making these changes via the GUI ensures that you don’t mess anything up accidentally. But you can use either one depending on which makes you feel more comfortable.

Leave a Reply

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