Skip to content
Help Center

How to increase the PHP memory limit in DirectAdmin

Learn how to adjust PHP memory limits on a VPS or dedicated server managed with DirectAdmin.

PHP scripts are fast to develop and widely used, but they also have an important downside: a badly written script can consume a huge amount of server memory and affect other services running on the same machine.

That is why PHP defines a memory limit for each script through the memory_limit setting.

What is PHP's memory_limit setting?

The memory_limit value is applied per script. In other words, it is the maximum amount of server memory that a single PHP script can consume.

The official PHP documentation describes it this way: it sets the maximum amount of memory in bytes that a script may consume and helps prevent poorly written scripts from exhausting all available server memory.

For example, if the limit is set to 128M, seven scripts can each use 80M without violating the limit, even though together they consume much more than 128 MB. But if one script suddenly needs 130M, it will fail with an error such as:

Fatal error: Allowed memory size of x bytes exhausted (tried to allocate x bytes)

or:

PHP Fatal error: Out of memory (allocated x) (tried to allocate x bytes)

How to increase the PHP memory limit in DirectAdmin

The first question should always be whether the memory use is reasonable. If it is not, the smartest fix may be correcting the script itself instead of simply raising limits. If you are confident that the workload is legitimate, then you can adjust the VPS or server configuration.

Follow these basic steps:

Step 1: locate the PHP configuration file in use. A simple way to check is:

/usr/local/bin/php --ini | grep 'Loaded Configuration File'

If you are using the default PHP CLI version, the file is often located at:

/usr/local/lib/php.ini

Step 2: edit the memory_limit line and set the desired value. If it does not exist, add it:

memory_limit = 128M

Adjust the value to what your application really needs and save the file. You can use an editor such as nano from an SSH session.

Step 3: restart Apache or the relevant PHP service so the change takes effect.

Other related PHP settings

If you also need to increase POST size, review:

post_max_size = 8M

If you need to allow larger uploaded files, review:

upload_max_filesize = 2M

Conclusion

The PHP memory limit exists for a good reason. Without it, a badly written script could consume all server resources and cause major problems. But if your environment is stronger and your application genuinely needs more memory, you can increase the maximum amount per script by editing the appropriate configuration file carefully.