How to increase memory size for phpmyadmin

How to increase memory size for phpmyadmin

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to increase memory size for phpmyadmin

Running a large database import through phpMyAdmin on localhost often hits a hard wall: a fatal error regarding exhausted memory limits. The scenario is common when migrating a production environment, such as a Magento instance, from a remote server to a local development box. In the specific case of importing a 383-table Magento database, phpMyAdmin might successfully process the first 18 tables before crashing with a Fatal error: Allowed memory size of 16777216 bytes exhausted. This indicates that the default PHP memory limit, set to 16MB (16,777,216 bytes), has been breached while attempting to allocate roughly 2MB for a single operation.

When this error appears in /usr/share/phpmyadmin/libraries/import.lib.php, it is not merely a suggestion to "add more RAM." It is a hard ceiling enforced by the PHP runtime configuration. The import process reads the SQL file into memory or processes it row-by-row, and if the buffer exceeds the configured memory_limit, the script terminates abruptly. To resolve this, you must explicitly modify the PHP configuration directives that govern resource usage.

The primary mechanism to adjust this limit is editing the php.ini file. You need to locate the memory_limit directive within the file and increase its value. For a database of this size, setting it to something like 256M or 512M is often prudent during the import phase.

memory_limit = 256M

However, simply editing the file isn't always enough if Apache or Nginx manages the PHP process. You must ensure the configuration takes effect for the web server in use. If you are using Apache with mod_php, a restart is required. For setups using FastCGI wrappers (like php-fpm), you might need to adjust settings in a specific pool configuration file rather than the global php.ini.

If you encounter issues finding or editing the global php.ini, or if your server uses multiple PHP versions, consider running phpMyAdmin with a custom configuration file. This approach allows you to override specific directives without touching the global installation files. You can define these overrides directly within the config.inc.php file located in the phpMyAdmin root directory. Adding the following line here is often cleaner and more targeted:

$cfg['MemoryLimit'] = '256M';

It is crucial to understand that increasing this limit does not automatically solve the underlying cause if the database schema itself is inefficient or if the import contains massive text fields loaded entirely into memory at once. While raising the limit allows the process to continue, it also increases the risk of swapping on systems with limited physical RAM. If your localhost machine only has 4GB or less of total RAM, allocating 512MB to a single PHP process could starve other applications, potentially causing system-wide slowdowns during the import. A balanced approach is often to start with 256M and only escalate if the error persists.

Another consideration is how you are running phpMyAdmin. If this is a temporary migration task, switching from a browser-based interface to a command-line tool like mysql or mysqldump might be more robust. Command-line tools often handle large imports differently regarding memory buffering and can be scripted to handle failures gracefully without the overhead of the web server's request lifecycle.

Finally, if you are managing a shared hosting environment where you cannot modify php.ini or upload a custom config file, your options are strictly limited to contacting support or using alternative tools provided by the host. In such cases, attempting to force a higher memory limit from within the application code is impossible because the server-enforced limit overrides any local configuration changes.

Our network