PHP Fatal error: Allowed Memory Size of 20971520 Bytes exhausted (tried to allocate 131072 bytes) Error and Solution

I‘ve brand new Ubuntu Linux server (Apache + PHP5 FastCGI + Lighttpd image only server) installed for my wordpress, mediawiki and vBullietin software. I can load forntpage of all software but user cannot edit any wiki pages or post anything and I get the following error in log file:

ADVERTISEMENTS

PHP Fatal error: Allowed Memory Size of 20971520 Bytes exhausted (tried to allocate 131072 bytes) in /usr/share/mediawiki/includes/OutputHandler.php on line 81

How do I fix this problem?

Ubuntu / Debian PHP5 comes with 16MB php memory limit. Edit /etc/php5/cgi/php.ini,/etc/php5/apache2/php.ini and /etc/php5/cli/php.ini files, run:
sudo vi /etc/php5/cgi/php.ini
sudo vi /etc/php5/cli/php.ini
sudo vi /etc/php5/apache2/php.ini

Set maximum amount of memory (e.g., 128M) a script may consume:

memory_limit = 128M

Save and close the file. However, real enforcer is suhosin security patch applied to PHP5. Edit /etc/php5/conf.d/suhosin.ini, run:
sudo vi /etc/php5/conf.d/suhosin.ini
Set allowed memory size (128M):

suhosin.memory_limit = 128

Save and close the file. Note if /etc/php5/conf.d/suhosin.ini file not found, type the following command to install the same, enter:
sudo apt-get install php5-suhosin
Finally, restart the web server:
sudo /etc/init.d/apache2 restart
OR
sudo /etc/init.d/lighttpd restart

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • Elixon Nov 23, 2009 @ 16:49

    I happened to hit the same problem. But as you noted Ubuntu comes with 16MB but the error message says it exceeded 20MB…

    For the real reason look at the LocaleSettings.php and comment out following line:
    ini_set( 'memory_limit', '20M' );

  • fivechimera Jan 1, 2010 @ 22:52

    This seemed to fix the problem, which was also causing PhpMyAdmin to error. Thanks so much!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.