Increase php memory limit centos 7

In this article, I have tried to explain how you can increase the default memory limit to run your PHP application. The default PHP memory limit in cPanel will be 64 MB. Users may receive the below errors in running PHP applications that require more PHP memory than the default 64 MB.

There are many ways you can increase this limit. For example, you can increase it from WHM, .htaccess file, and php.ini file.

How to change the PHP memory limit from WHM (version 11.24.x)?

You can increase the default PHP memory limit value from the “PHP Configuration Editor” option of WHM. You will find the “memory_limit” directive in the core section. Just increase the limit from 64 MB to 256 MB (or any value in MB you wish). Then, click on the Save button to submit the changes.

How to change from .htaccess file?

.htaccess is a hidden file (dot file) of Linux. You will find it inside every domain’s public_html folder. You can create it if you do not find it anyhow. You need to enter the below the line of code in this file:

php_value memory_limit 256MB

How to change it from php.ini file?

Php.ini is a default configuration file for PHP. In a Linux environment, you will find this file in /usr/local/lib/. However, it may be different since the administrator changed it. You can find the exact path by placing phpinfo.php file in your domain. Then, use the below code in phpinfo.php file and save.

phpinfo();

?>


It will display your php.ini path in the “Configuration File (php.ini) Path” value. In addition, it will also display some other PHP loaded modules (Only if enabled) like GD library, MySQLi, Zend Optimizer, Ioncube, etc.

Once you get the exact path, open it with any file editor tool like vi, pico, or nano. I am using vi editor and find it more comfortable. So type the below command once you are in the/usr/local/lib directory:

Note:  I would recommend backup the existing php.ini file before you make any changes. Since if by mistake you will mess it up, it may lead to stop your PHP functioning. So simply copy the existing php.ini file somewhere and then start editing the existing one.

vi php.ini

You will find “memory_limit” directive inside the “Resource Limit” section. Just modify this value to the limit you wish to set and save the existing php.ini file. In vi editor Press Esc -> colon (:) -> wq to save the file.

You will need to restart your apache server to make the changes effective. You can restart it by executing the following command through SSH:

apachectl -k restart

Check phpinfo.php file and make sure the changes are reflected properly.


Click here to Check out the Best web hosting plans! 
Thanks!

PHP sets a limit on how much memory PHP scripts are allowed to use so that a memory-intensive script won't bring down a system. PHP will exit and throw the following error once the limit is reached;

PHP Fatal error: Allowed memory size of xxxx bytes exhausted (tried to allocate yyyy) in yourscript.php

Increase php memory limit centos 7

You can increase the memory limit if your PHP scripts require to avoid the error. Some methods to increase the memory limit in PHP are configuring php.ini or .htaccess file and using ini_set() function. cPanel provides the option to configure PHP memory limit from the web interface.

Methods to increase PHP memory limit:

Increase PHP memory limit via file (php.ini)

This method will apply to all the PHP scripts that run in the system. It is a good method to follow if you're not hosting multiple systems in a single host.

  1. Open PHP configuration file using your preferred text editor.

    $ sudo vi /etc/php/7.2/apache2/php.ini

  2. Search for memory_limit directive within the configuration file.

    ; Maximum amount of memory a script may consume (128MB)
    ; http://php.net/memory-limit
    memory_limit = 128MB

  3. Set the memory limit value with appropriate unit.

    ; Maximum amount of memory a script may consume (128MB)
    ; http://php.net/memory-limit
    memory_limit = 512MB

  4. Restart your web server for the changes to take effect.

Increase PHP memory limit via .htaccess

To make the setting effective only to a certain folder (or project), you can use the .htaccess file to do the trick. To do this, locate (or create) .htaccess file in your PHP scripts folder and add the following line;

php_value memory_limit 512MB

Increase PHP memory limit via ini_set() function

It is probably the best method as the setting applies only to the particular script and would not allow other poorly written scripts to consume and waste the system's memory.

To do this, add the following line in your PHP script;

ini_set('memory_limit', '512MB');

Increase PHP memory limit for cPanel

You don't have access to PHP's configuration file if you're hosting your system in cPanel, but cPanel do provide the option to change the setting from its admin dashboard.

Increase php memory limit centos 7

Discuss the article:

Comment anonymously. Login not required.

How do I increase the PHP memory limit?

To increase the PHP memory limit setting, edit your PHP. ini file. Increase the default value (example: Maximum amount of memory a script may consume = 128MB) of the PHP memory limit line in php. ini.

How set PHP memory limit in Linux?

Edit Your “memory_limit” Once you find the php. ini file, you want to open it in your favorite text editor (vim/nano/etc.). In this example, the memory limit is set to 64MB. If you wanted to change it to 128MB or 32MB or whatever, you just need to change this line.

What is the max memory limit for PHP?

Increasing the PHP memory limit The default memory limit is 256M and this is usually more than sufficient for most needs. If you need to raise this limit, you must create a phprc file.

How do I increase server memory limit?

You can increase your host memory limit by following any of the five methods mentioned below..
Most Recommended: Just Contact Your Host. ... .
Increasing Memory Limit via PHP.ini file. ... .
Alternative to editing PHP.ini through wp-config.php. ... .
Changing memory Limit in wp-config.php. ... .
Modifying the .htaccess file..