How to Change PHP Memory Limit in cPanel

Increasing the PHP memory limit is often necessary to ensure that your website or application runs smoothly, especially if it requires significant resources. The PHP memory limit is the maximum amount of memory that a PHP script is allowed to allocate. By default, the PHP memory limit is usually set to 128MB, but this can vary depending on your server configuration. In some cases, you may need to increase the memory limit to accommodate larger scripts or applications that require more memory. This guide provides a detailed, step-by-step approach to changing the PHP memory limit using cPanel.

Why Increase the PHP Memory Limit?

  1. Avoiding Errors: Low memory limits can cause errors like Allowed memory size exhausted.

  2. Improving Performance: Increasing the limit can enhance performance for resource-intensive applications.

  3. Running Larger Scripts: Necessary for running larger scripts, such as backups or installations.

Factors to Consider

When determining the appropriate PHP memory limit for your application, there are a few factors to consider:

  1. Script Complexity: More complex scripts that perform intensive operations or work with large data sets will generally require a higher memory limit.

  2. Server Resources: The available memory on the server and the number of other applications running on the same server can also influence the optimal memory limit.

  3. PHP Version: Newer versions of PHP may have different default memory limit settings, so you may need to adjust the limit accordingly.

  4. Operating System: The operating system (e.g., Linux, Windows) can also impact the memory usage and the appropriate memory limit.

Step-by-Step Guide to Changing PHP Memory Limit

Method 1; using cpanel’s multiphp INI editor

Step 1: Log in to cPanel

  • Navigate to your cPanel account login page and enter your credentials.

Step 2: Access MultiPHP INI Editor

  • In the cPanel dashboard, scroll down to the Software section.

  • Click on MultiPHP INI Editor.

Step 3: Select a Location

  • Choose the domain or directory for which you want to change the PHP memory limit. You can select the home directory if you want the change to apply globally.

Step 4: Edit the Memory Limit

  • Find the memory_limit setting.

  • Enter the desired memory limit value (e.g., 256M for 256 megabytes).

  • Click Apply to save the changes.

Method 2; Editing the .htaccess file

Step 1: Log in to cPanel

  • Log in to your cPanel account.

Step 2: Access File Manager

  • In the cPanel dashboard, go to the Files section.

  • Click on File Manager.

Step 3: Locate the .htaccess File

  • Navigate to the root directory of your website (usually the public_html directory).

  • Look for the .htaccess file. If it doesn’t exist, you may need to create it.

Step 4: Edit the .htaccess File

  • Right-click on the .htaccess file and select Edit.

  • Add the following line to the file:

  • Save the changes and close the editor.

Method 3; Editing the php.ini file

Step 1: Log in to cPanel

  • Log in to your cPanel account.

Step 2: Access File Manager

  • In the cPanel dashboard, go to the Files section.

  • Click on File Manager.

Step 3: Locate or Create the php.ini File

  • Navigate to the root directory of your website.

  • Look for the php.ini file. If it doesn’t exist, you may need to create it.

Step 4: Edit the php.ini File

  • Right-click on the php.ini file and select Edit.

  • Add or modify the following line:

Save the changes and close the editor.

Method 4; Using the wp-config file (for wordpress sites)

Step 1: Log in to cPanel

  • Log in to your cPanel account.

Step 2: Access File Manager

  • In the cPanel dashboard, go to the Files section.

  • Click on File Manager.

Step 3: Locate the wp-config.php File

  • Navigate to the root directory of your WordPress installation.

  • Look for the wp-config.php file.

Step 4: Edit the wp-config.php File

  • Right-click on the wp-config.php file and select Edit.

  • Add the following line before the /* That’s all, stop editing! Happy blogging. */ comment:

  • Save the changes and close the editor.

Verifying the Changes

After changing the PHP memory limit, it’s essential to verify that the changes have taken effect:

  1. Create a PHP Info File:

    • Create a new file in your website’s root directory called phpinfo.php.

    • Add the following code to the file:

  1. Check the Memory Limit:

    • Look for the memory_limit setting in the output of the PHP info page to confirm the new value.

Troubleshooting

  1. Changes Not Taking Effect:

    • Ensure there are no conflicting settings in other configuration files.

    • Check with your hosting provider if there are server-level restrictions.

  2. Server Errors:

    • If you encounter server errors after making changes, revert to the previous settings and consult with your hosting provider for support.

Changing the PHP memory limit in cPanel is a straightforward process that can significantly enhance the performance of your web applications. By following the methods outlined above, you can easily increase the memory limit and ensure your website runs smoothly without encountering memory-related issues. Always remember to verify your changes and consult with your hosting provider if you face any difficulties.