How to edit php.ini file to increase memory limit

Published at April 27, 2007   Filed Under Blogging, Tweaks    

feedIf you're new here, you may want to subscribe to my RSS feed or Email alerts. Thanks for visiting!

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.

If you liked this post, feel free to subscribe to my RSS feed

19 Responses to “How to edit php.ini file to increase memory limit”


  1. MyAvatars 0.2 kynan
    May 14th, 2007 8:41 pm
    This totally solved my problem uploading large files from to my wordpress blog… thanks for the great info, super helpful.
  2. MyAvatars 0.2 ram
    May 15th, 2007 5:55 am
    @kanyan
    glad that it helped you. Thanx for commenting
  3. MyAvatars 0.2 arian
    June 24th, 2007 1:14 pm
    hi that is great:

    but i am having problem, i have shared account so i dont have full root accesess abut i do have ssh accesess, but anyway i followed ur producers i can get accesess to the php.ini file, and i did some chnages in post_max_size and post_time too but when i hit escape and than wq I didnt work, cuz it did save and quite it. so if u please can help me.

  4. MyAvatars 0.2 ram
    June 24th, 2007 1:38 pm
    If you are in a shared account i guess you can not edit php.ini file because the changes will be effected to all the accounts on the shared server. If this is the case you should contact your host.
    Try to add the values to .htaccess file and see if that helps
  5. MyAvatars 0.2 LAS Design.net (Leon)
    July 25th, 2007 3:07 am
    Thanks for this tutorial!
    This was a great help and like you i’m not too familiar with SSH commands, i managed to update my PHP ini file and now my upload limit has been increased.
    Many thanks..!
  6. MyAvatars 0.2 ram
    August 3rd, 2007 10:50 pm
    @lasdesign
    glad that it worked for you
  7. MyAvatars 0.2 Dragos
    September 15th, 2007 6:03 pm
    Can u please tell me how do i locate the php.ini file in the server ?

    I have a shared hosting on HostGator and they are using cpanel ! I aksed them to help me but they said they dont support 3rdpart scripts :(

  8. MyAvatars 0.2 suraj
    January 5th, 2008 1:01 am
    how to serch php.ini file in linux os
  9. MyAvatars 0.2 Ms. Latina Renee
    January 25th, 2008 8:52 am
    The following command searches the file too:

    php -i | grep php.ini

  10. MyAvatars 0.2 Ram
    January 25th, 2008 3:40 pm
    @Latina
    Thanks for the headsup
  11. MyAvatars 0.2 Anonymous Proxy Server
    February 13th, 2008 7:03 am
    I’m trying to access php.ini for improving my proxies but not being able to access it coz im using shared hosting! :(
  12. MyAvatars 0.2 uday
    February 27th, 2008 12:30 am
    i’ve tried to send mail from my website but it is giving me this error

    Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\mailto.php

    m really stuck here and would really appreciate your guidance

    thank you in advance

  13. MyAvatars 0.2 IT Outsourcing
    April 11th, 2008 5:11 am
    This article is great I love to read it and very helpful for my project
    thanks
  14. MyAvatars 0.2 ashok
    April 29th, 2008 7:34 pm
    hi
    i got error in image uploading
  15. MyAvatars 0.2 Ram
    May 1st, 2008 7:07 pm
    @Ashok
    What kind of error ?, is the error after editing the file or before.

Trackbacks/Pingbacks

  1. How to upgrade PHP version from WHM at Technology Bites
  2. May 5th, 2007 2:50 pm
  3. memory_limit i nasýl yükseltebilirim ? - Webmaster Forum
  4. May 8th, 2007 12:27 pm
  5. Import Large MySQL dumps with bigdump | Technology Bites
  6. September 17th, 2007 6:30 am
  7. MoneyGirls Blogging On The Internet » Blog Archive » Upgrading A Topsite to A New Server - You probably tried to upload too large file
  8. May 6th, 2008 7:30 pm

Leave a Reply