Adjust PHP setting memory_limit

Preface

The PHP setting memory_limit defines the maximum available RAM in bytes (or alternatively in kibibytes [K], mebibytes [M] or gibibytes [G]) for PHP scripts. By limiting the working memory, it can be ensured that PHP does not use too much RAM, which would exceed the available RAM or block other processes.


A high RAM limit can lead to the instability of your web applications. If you want to adjust the value due to background processes, you can alternatively use our Cronjobs in the Customer Center to execute the tasks via SSH. We recommend a maximum value of 1 G. (GiB)


To adjust the PHP setting memory_limit, first log in to our customer center at account.creoline.com with your access data.


Use the navigation to select your server under Server for which you want to change the PHP settings. Then open the Plesk Control Panel via the Plesk Control Panel menu item.


If the menu item is not displayed on your server, you will find further options for logging in in the article Logging in to the Plesk Control Panel.



Customization for a single domain

Once you are logged into Plesk, you can select the domain via the global search or the Subscriptions menu item.

Plesk - PHP-Einstellungen

You can use the PHP settings button to adjust the general PHP settings:


Plesk - memory_limit

The value memory_limit defines the maximum amount of memory allowed for PHP scripts. This value is freely definable and is specified in bytes.


After the settings have been saved, the web server automatically reloads the configuration using a graceful restart so that existing requests are not aborted but paused.



Customization for all domains

To adjust the PHP settings for all domains of a PHP version, the PHP configuration file php.ini must be adjusted. To do this, select PHP settings from the Tools & settings in the left sidebar.

Plesk - PHP Einstellungen

Then click on the PHP version for which you want to adjust the setting globally.

You can access the PHP configuration file via the php.ini tab:


Plesk - php.ini

In the text field, search for the term memory_limit and replace the specified value with the desired new value. The default setting in Plesk is 128M .


Then click on the OK button to save the changes. The changes will take effect immediately for all subscriptions that have the selected PHP version configured and have not been overridden using the custom PHP setting.



Error message: Allowed memory size exhausted


PHP Fatal error:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 24576 bytes)


The Allowed memory size exhausted error message is generated as soon as the defined PHP memory limit is exceeded. Please note that there are different PHP runtime configurations for the web and CLI environment.


Customization for a single call

If you want to adjust the memory limit for the CLI area at short notice, you can add runtime configurations using the -d parameter.


Example with PHP 8.2:

/opt/plesk/php/8.2/bin/php -d memory_limit=1G command.php


Customization for all calls

You can globally customize the PHP runtime configuration for the CLI environment so that all future calls of PHP in the CLI environment work with the customized configuration.


Paths for the PHP runtime configurations in the CLI environment:

# PHP 7.4
/opt/plesk/php/7.4/etc/php.ini

# PHP 8.0
/opt/plesk/php/8.0/etc/php.ini

# PHP 8.1
/opt/plesk/php/8.1/etc/php.ini

# PHP 8.2
/opt/plesk/php/8.2/etc/php.ini

# PHP 8.3
/opt/plesk/php/8.3/etc/php.ini


Search for the following position in the respective php.ini and adjust it according to your requirements:

[...]

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


A restart of PHP is not necessary for the CLI environment. Changes take effect immediately.