Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

How to Increase the PHP Memory Limit on Ubuntu (CLI, Apache, and PHP-FPM)

Set the right PHP memory_limit on Ubuntu by identifying the active SAPI first. Follow separate steps for CLI, Apache, CGI, and PHP-FPM, then verify the web value and check pool or systemd limits when changes do not stick.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Increase PHP’s limit in the configuration file used by the PHP SAPI that runs the failing code, set a value such as memory_limit = 256M, then restart the service that loads that configuration. The command-line interpreter, Apache, CGI, and PHP-FPM can use different php.ini files, so changing the CLI file will not necessarily change a website.

Start by identifying the SAPI, change only its active configuration, and verify the result through that same SAPI. This guide covers Ubuntu servers running PHP from the shell, Apache, or PHP-FPM behind Apache or Nginx, including pool-level overrides, service limits, and safe troubleshooting.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What PHP’s memory limit controls

memory_limit is PHP’s per-script ceiling. The PHP Documentation Group defines it as “the maximum amount of memory in bytes that a script is allowed to allocate.” It limits PHP allocations; it does not reserve that amount of RAM for every request and it does not increase the memory available to Ubuntu.

The current PHP manual documents a default of 128M. PHP accepts shorthand units such as M and G. A setting of -1 removes PHP’s own limit, but that is rarely a safe production choice because worker processes can then consume all memory available to the host or service.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

When a script reaches the ceiling, PHP commonly reports an error such as “Allowed memory size exhausted.” The correct fix depends on whether the failing workload is a command-line job, an Apache request, a CGI process, or a PHP-FPM worker.

Identify the PHP SAPI before editing anything

A SAPI (Server Application Programming Interface) is the way PHP is being run. Each SAPI can load a different configuration file and can have a different override hierarchy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Workload Where to inspect first Typical scope Reload needed after a server configuration change
CLI scripts, Composer tasks, cron jobs php --ini and php -i CLI php.ini No persistent daemon; run the command again
Apache PHP module A diagnostic request through the affected virtual host Apache-loaded PHP configuration Restart or reload Apache
CGI under Apache A diagnostic request through the affected virtual host CGI PHP configuration Restart Apache after changing startup configuration
PHP-FPM behind Apache or Nginx A diagnostic request plus the FPM configuration tree FPM php.ini and possibly a pool file Restart or reload the matching FPM service

Do not infer the web value from a shell command. The website may be using another installed PHP version, another SAPI, or a pool-specific setting.

Check the current CLI value

Run these commands as the user who normally runs the script:

php --ini
php -i | grep -E '^memory_limit'
php -r 'echo ini_get("memory_limit"), PHP_EOL;'

php --ini prints the loaded configuration file and any additional scanned directory. The two value checks show the effective setting seen by the CLI interpreter, not by a web request.

If several PHP versions are installed, make sure the php command is the one used by the job. A cron entry can call an absolute binary path, and a deployment script can select a different version than your interactive shell.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Increase the limit for CLI scripts

1. Locate the active CLI file

Read the “Loaded Configuration File” line from php --ini. Ubuntu commonly stores versioned files under a path such as /etc/php/8.3/cli/php.ini, but use the path printed on your machine rather than assuming a version.

Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

2. Edit the directive

Open the file with an editor that has permission to write system configuration and find the existing memory_limit line. Set one value, for example:

memory_limit = 256M

Remove a leading semicolon if the directive is commented out. Keep the unit attached to the number. Use a larger value only when the script genuinely needs it and the host has capacity for concurrent jobs.

3. Run the same checks again

php -i | grep -E '^memory_limit'
php -r 'echo ini_get("memory_limit"), PHP_EOL;'

The output should show 256M (or the value you selected). If it does not, you edited a file that this CLI binary does not load, or another configuration file is overriding it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Handle one-off jobs without changing global policy

For a single command, PHP can receive a command-line override:

php -d memory_limit=512M path/to/script.php

This affects that invocation only. It is useful for a controlled import or maintenance task, but it does not change a website or a separate cron command.

Increase the limit for Apache PHP or CGI

Confirm the web SAPI

Create a temporary file in the document root of the affected virtual host containing:

<?php echo ini_get('memory_limit'); ?>

Request it through the same hostname and protocol used by the application. The returned value is the web SAPI’s effective limit. Delete the file immediately after checking; exposing configuration diagnostics on a public site can reveal implementation details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

A temporary phpinfo() page can show the SAPI and both local and master values, but it is even more revealing. Protect it from public access while testing and remove it as soon as the result is recorded.

Edit the configuration associated with that SAPI

Ubuntu documents Apache-module PHP and CGI as separate deployment choices. Locate the version and SAPI directory used by the web server, then edit that SAPI’s php.ini. A typical versioned Apache path resembles /etc/php/8.3/apache2/php.ini; the actual version and path must match the installation reported by the server.

Set the directive, for example:

memory_limit = 256M

Restart Apache

The PHP manual states that php.ini is read when PHP starts. For Apache-module PHP, PHP starts with the web server, so restart or reload Apache after changing the file. A reload may be sufficient for the installed module, while a full restart is the clearest way to ensure every worker has reopened the file. Confirm the service name and status on the host before choosing the command.

Verify through the virtual host

Request the temporary diagnostic page again and compare its value with the CLI output. Different results are expected when CLI and Apache use different SAPIs or PHP versions. Remove the diagnostic file once verification is complete.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Increase the limit for PHP-FPM

PHP-FPM has a master process and pools of workers. It is commonly connected to Nginx or Apache through FastCGI. FPM uses PHP-style configuration syntax in its main configuration and pool files, as documented by the PHP-FPM manual.

1. Find the FPM version and service

Look at the FastCGI socket or upstream configured for the affected virtual host and identify the matching PHP version. On Ubuntu, the service name commonly contains that version and ends in -fpm. Do not restart a different version’s service: the website will continue using the unchanged pool.

2. Edit the FPM php.ini

Use the FPM SAPI directory for the installed version, commonly resembling /etc/php/8.3/fpm/php.ini. Set:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
memory_limit = 256M

Save the file and inspect the pool configuration before assuming the global value is authoritative.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Check pool-level directives

Pool files can contain either of these forms:

php_value[memory_limit] = 256M
php_admin_value[memory_limit] = 256M

php_admin_value[memory_limit] is authoritative for that pool and cannot be overridden by ini_set() in application code. A pool setting can therefore make the website’s value differ from the global FPM php.ini. Apply the smallest-scope change that solves the problem: a single pool for one application, or the global file only when all FPM applications should receive the new limit.

4. Restart or reload the matching FPM service

FPM reads its master and pool configuration when its processes start. Restart or reload the exact PHP-FPM service serving the virtual host. Existing workers may retain the old value until they are replaced, so verify after the service operation completes and check the service status if it fails to start.

5. Verify through the real application path

Use the temporary ini_get('memory_limit') page through the affected virtual host, or log the value from a protected administrative route. Testing through Nginx, Apache, the correct hostname, and the correct PHP-FPM socket matters: a different virtual host can point to another pool.

Per-directory and application-level settings

Some SAPIs permit a per-directory mechanism such as a .user.ini file, and some applications can call ini_set('memory_limit', '256M'). These methods are appropriate only when the SAPI and hosting control plane allow them.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use a per-directory or application setting when only one site or directory needs more memory.
  • Do not expect ini_set() to defeat an FPM php_admin_value[memory_limit] setting.
  • Application changes affect requests after the setting is read; they do not change CLI jobs or other pools.
  • After changing a per-directory file, verify through the same virtual host and account that runs the application.

If the host is managed, a control panel or service policy may rewrite the value. In that case, the panel’s PHP settings or the provider’s documented mechanism is the authoritative place to change it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a value without exhausting the server

A higher per-process ceiling can increase total memory pressure when several workers run concurrently. PHP’s setting is not a reservation, but a workload that approaches the ceiling can consume that much memory. Account for PHP-FPM children, Apache workers, the database, queues, caches, the operating system, and any other services before raising the limit.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Situation Reasonable approach Risk to check
A single CLI import fails near the default Use a command-line -d memory_limit=... override or raise only the CLI file Scheduled jobs may run concurrently and multiply usage
One web application needs larger uploads or image processing Raise the application or FPM pool value rather than every PHP site More simultaneous workers can consume the host’s available memory
Several applications routinely need large allocations Review worker counts and host capacity before making a global increase System-wide contention can slow or terminate unrelated services
You are considering -1 Use it only for tightly controlled diagnostics or jobs with an independent cap A runaway request can consume all memory available to the service

Raising the directive does not create RAM or swap. If the workload genuinely requires more concurrent memory, increase the host’s available capacity or reduce concurrency as well as adjusting PHP.

When Ubuntu or systemd stops the process anyway

Even when PHP accepts a larger memory_limit, the service can be constrained by systemd or another cgroup. Ubuntu documents MemoryHigh as a throttling control and MemoryMax as an absolute unit limit. If a unit cannot contain its memory use below MemoryMax, the unit’s out-of-memory killer can be invoked.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the service-level policy when FPM, Apache, or a worker is killed despite a PHP value that appears correct. A systemd limit is outside php.ini; changing PHP cannot override it. Conversely, raising MemoryMax without reserving capacity for the rest of the host can move the failure to another service.

Why changing php.ini appears not to work

You edited the wrong SAPI file

This is the most common cause. php --ini reports the CLI file only. A browser request may use Apache-module PHP, CGI, or FPM with another version and another directory. Compare a CLI check with a diagnostic request made through the real virtual host.

The service was not restarted or reloaded

The PHP manual says configuration is read when PHP starts. Restart or reload Apache after an Apache-side change, and restart or reload the matching FPM service after an FPM or pool change. Confirm that the operation succeeded rather than assuming the command completed.

An FPM pool overrides the global value

Search the pool configuration for php_admin_value[memory_limit] and php_value[memory_limit]. The pool value is the one the request receives; an administrative value cannot be replaced from application code.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A different virtual host or PHP version is serving the request

Test through the exact hostname, URL scheme, and site that fails. Check the FastCGI socket or Apache module selected for that site. A successful test on a default virtual host does not prove that the production site uses the same SAPI.

The operating system or cgroup is the real limit

Inspect systemd and container limits when the process is killed rather than reporting a PHP memory error. MemoryHigh can throttle a unit; MemoryMax can terminate it through the unit’s out-of-memory handling.

The requested value exceeds practical capacity

A syntactically accepted value can still be unsafe. If multiple workers each approach the new ceiling, available RAM can disappear quickly. Reduce concurrency, process data in smaller batches, or add capacity instead of repeatedly increasing the directive.

A repeatable verification checklist

  1. Identify the failing path: shell, cron, Apache, CGI, or PHP-FPM.
  2. For CLI, run php --ini and record the loaded file.
  3. Read the effective CLI value with php -i | grep -E '^memory_limit' or php -r 'echo ini_get("memory_limit"), PHP_EOL;'.
  4. For web traffic, create a temporary protected page that prints ini_get('memory_limit'), request it through the affected virtual host, and remove it immediately.
  5. Edit the configuration belonging to that SAPI and set a qualified value such as 256M.
  6. Inspect FPM pool files for php_value and php_admin_value overrides.
  7. Restart or reload the owning Apache or PHP-FPM service.
  8. Repeat the check through the same path that originally failed.
  9. Check host and systemd/cgroup memory limits if PHP still fails or the process is killed.

Practical decision guide

Question Action
Does only a terminal command fail? Change the CLI configuration or use a one-command -d override.
Does a site served directly by Apache fail? Inspect the web SAPI, edit its Apache/CGI configuration, and restart Apache.
Does a site behind Nginx or Apache use FastCGI? Edit the matching FPM configuration, inspect its pool, and reload the matching FPM service.
Does one application need more memory than its neighbors? Prefer an application or pool-level setting when the SAPI permits it.
Does the value look correct but the service still die? Investigate systemd/cgroup limits and total host capacity.

Security and maintenance notes

  • Delete temporary phpinfo() and diagnostic pages immediately after testing.
  • Record which PHP version, SAPI, virtual host, and configuration file were changed; this prevents later edits to the wrong file.
  • Keep the value as low as the workload permits and revisit it after application updates.
  • When several jobs run together, measure peak service memory rather than judging safety from one successful request.
  • Do not use -1 as a substitute for diagnosing an oversized query, unbounded loop, image operation, or batch process.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.