What does the error mean?
eAccelerator is an old PHP add-on that makes websites faster. It keeps ready-to-use copies of PHP code in memory. This memory is called shared memory, because many programs can use it at once.
The kernel is the core of the operating system. It sets a limit on the biggest piece of shared memory a program may ask for. The limit is called shmmax.
The error appears when eAccelerator asks for more memory than the kernel allows. The message looks like this:
eAccelerator: Could not allocate xxx bytes, the maximum size the kernel allows is xxx bytes
Tip: eAccelerator is old and newer PHP versions do not support it. Newer servers use OPcache. The fix below still helps for any program that needs shared memory.
Fix 1: Ask for less memory
- Log in to your server over SSH as root.
- Find the PHP settings file. Run
php --inito see where it is. The eAccelerator settings may also be in a file namedeaccelerator.ini. - Open the file with a text editor such as
nano. - Find this line:
The number is the size in megabytes.eaccelerator.shm_size="64" - Lower the number, for example to
32or16. - Save the file and restart your web server. For Apache run
systemctl restart httpdon AlmaLinux or CentOS, orsystemctl restart apache2on Ubuntu.
Fix 2: Raise the kernel limit
- Check the current limit:
It shows the number in bytes.sysctl kernel.shmmax - Set a bigger limit for now. This example is 128 MB:
sysctl -w kernel.shmmax=134217728 - To keep it after a reboot, add this line to
/etc/sysctl.conf:kernel.shmmax = 134217728 - Apply the file:
sysctl -p - Restart your web server.
Warning: make a copy of any file before you edit it. A wrong value can stop the web server from starting. Also, never set the limit above the RAM you really have.
Quick recap
- The error means eAccelerator asked for more shared memory than the kernel allows.
- Lower
eaccelerator.shm_sizeto fix it fast. - Or raise
kernel.shmmaxwithsysctl. - Restart the web server afterwards.
- Think about moving to OPcache.