Today my blog was down for some time due to a memory issue in php.ini file in my server. I have never seen this error before and i don’t know what went wrong. I quickly searched on Google and found that this error is caused by insufficient memory allocation in php.ini file. A standard server (linux box) setup comes with 8M memory and we need to increase this to avoid these types of errors.
Error:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 8192 bytes) in /home/teknobit/public_html/wp-includes/theme.php on line 59
I managed to increase the memory in php.ini to overcome this, i will write here how i did it hoping that it may be useful for somebody.
For those of you who use shared hosting the quick solution would be to add a line in .htaccess file located at your root folder.
php_value memory_limit 24M
here 24M is an example and most of the times this is enough to get your site back, contact your host support if this doesnt work.
First step for this is to locate your php.ini file in the server and to see what is the memory limit (this is shown in the error message). Create a file with the below code and name it something like “test.php”
<?php phpinfo(); ?>
Upload this file to your site root and point your browser to this file, now it will show the phpinfo of the server, in this you will find “Configuration File (php.ini) Path: /usr/local/lib/php.ini”, this is your php.ini location. You can find the memory limit also in this page “memory_limit: 8M”
If you know shell then you can use putty, SSH client, login to putty and locate the file php.ini and edit the memory limit, below commands may be useful; found here
Log in as root.
Type the following and hit enter: vi /usr/local/lib/php.ini
Now that you’re in vi, hit escape a few times then type the following
and hit enter: /memory_limit
That basically does a “find” in the file you’re editing.
Press the “i” key. This puts you in “insert” mode, which basically
allows you to edit things.
Change the current setting (probably 8M) to 16M.
Press escape, then type :wq and hit enter. That says “save the file
and quit.”
I dont know shell commands so the easiest way for me to do this is using penguiNet, (Update: Use WinSCP, this is free tool) its a windows SSH client, you can use shell commands or use the ftp like interface to navigate to the php.ini file. Login to server with root account and download the file, edit it and upload it again. Remember to backup the original file, if you make a mess you can use the original file.

In php.ini search for this line “memory_limit = 8M”, replace the 8M with your desired value like 16M, 24M etc. Save the file and upload it to the server. Now you need to restart Apache for the changes to effect, this can be done through WHM, if you dont have WHM installed use these command
/etc/rc.d/init.d/httpd restart
Refresh the browser, your site should work normally.
By using the same procedure you can also increase the file upload limit size, in this case search for the line “upload_max_filesize = 2M” in php.ini and change the value to your desired value. The dafault upload limit in php is 2MB.






Pingback: memory_limit i nasýl yükseltebilirim ? - Webmaster Forum
Pingback: Import Large MySQL dumps with bigdump | Technology Bites
Pingback: MoneyGirls Blogging On The Internet » Blog Archive » Upgrading A Topsite to A New Server - You probably tried to upload too large file
Pingback: Oh. Oops! - Starryskye.org
Pingback: PHP Memory, Zenphoto and Bluehost limits | Tongfamily Website
Pingback: How to upgrade PHP version from WHM
Pingback: Problemas generando Sitemap.xml - Página 2
Pingback: Useful .htaccess tips and tricks • Technology Bites