The PHP memory limit defines the maximum amount of memory a single PHP script can use. This setting prevents poorly optimized or runaway scripts from consuming excessive resources and crashing your server.
By default, the memory limit is often set to 128M or 256M, which is usually sufficient for small or simple websites. However, if you’re running a larger application—such as WordPress, WooCommerce, Drupal, or Laravel—you may need to increase the PHP memory limit to ensure smooth performance and avoid errors.
Why Adjusting Memory Limit Matters
Setting the right memory limit directly affects:
- Website speed and responsiveness
- Ability to run large plugins or import data
- Stability during peak traffic
- Prevention of “Allowed memory size exhausted” fatal errors
Improving it means smoother performance and happier users.
Common Signs Your PHP Memory Limit Is Too Low
You might need to increase the limit if:
- You get “Allowed memory size exhausted” errors
- Plugins or themes fail to install or update
- Backup plugins time out or fail
- Large images or file imports crash
- Website slows down under traffic spikes
Pre-Check: Know Your Current PHP Memory Limit
Before you change anything, it’s important to find out your current PHP memory limit. This helps you understand if you actually need to increase it, and by how much.
The easiest way to check is by using a special PHP function called phpinfo(). This method works for any website, regardless of whether you’re using ServerAvatar, cPanel, or any other platform.
Step-by-Step: Use a phpinfo() Script
Step 1: Create the File
- Navigate to your file manager.
- Go to your root directory of WordPress application. This is usually the same folder that contains your wp-config file
- Create a new file and name it info.php.
- Paste the following code into the file:
<?php
phpinfo();
?>
his little script tells your server to display all current PHP settings.
Step 2: Upload the File
Upload the info.php file to the root directory of your website. This is usually the same folder that contains your:
- index.php
- wp-config.php (for WordPress sites)
- or public HTML folder (public_html, htdocs, etc.)
Step 3: Open the File in Your Browser
Now, in your browser’s address bar, visit:
Example:- https://yourdomain.com/info.php
(Replace yourdomain.com with your actual domain name.)
This will load a full PHP configuration page.
Step 5: Delete the File for Security
Important: Once you’ve checked your memory limit, delete the info.php file immediately.
Why? Because this page exposes sensitive information about your server, including version numbers, extensions, and configurations, which could be exploited by attackers.
Method to increase PHP Memory Limit | Edit the PHP.ini File
The php.ini file runs every time a PHP application is used. It controls important settings like how big a file you can upload, how much memory a script can use, how long a script can run before it stops, and more.
If you want to increase the memory limit or other limits, you can change the following settings in your php.ini file. Just remember:
- These settings are case sensitive, so type them exactly as shown.
- After making changes, restart your server to apply them.
Here are the settings you can update:
How to Find the php.ini File
Using Command Line (Linux Server)
If you have SSH access:
php --ini
Look for the line:
Loaded Configuration File: /etc/php/8.1/apache2/php.ini
Once you know the path, open it using a code editor or terminal.
Example (using nano in terminal):
sudo nano /etc/php/8.1/apache2/php.ini
(Make sure to replace the path with your actual PHP version and environment)
memory_limit = 256M
upload_max_filesize = 12M
post_max_size = 13M
file_uploads = On
max_execution_time = 180
Scroll/search in the file (Ctrl+W in nano) for the following lines and update & Save the File:
To apply the changes, restart your server:
For Apache:
sudo systemctl restart apache2
For Nginx + PHP-FPM:
sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx
(Replace php8.1-fpm with your PHP version)
The max_execution_time setting is the time limit for a script to run. If a script takes longer than this, it will stop automatically.