Php Memory Limit Increase Ram

"PHP Memory Limit" — How to Increase Your RAM

Written by: Ryan Frankel

Ryan Frankel

Ryan began developing websites in the late '90s and has personally tested just about every web host and cloud platform worth trying on the market today. With a masters degree in electrical and computer engineering from the University of Florida, he leverages his extensive knowledge of hardware, software, and their engineering relationship to inform HostingAdvice readers of the technical implications of their hosting choices. Ryan's subject matter expertise includes, but is not limited to, WordPress, cloud infrastructure management, product UI/UX design, and popular web development languages such as JavaScript and PHP.

See full bio »

Edited by: Lillian Castro

Lillian Castro

Lillian brings more than 30 years of editing and journalism experience to our team. She has written and edited for major news organizations, including The Atlanta Journal-Constitution and the New York Times, and she previously served as an adjunct instructor at the University of Florida. Today, she edits HostingAdvice content for clarity, accuracy, and reader engagement.

See full bio »

Sometimes while in development or production, we find that our software uses more memory than we ever expected. To keep things under control, PHP has default memory limits to avoid some runaway program from crashing your box.

Luckily, it is extremely easy to change how much RAM we allocate toward a single PHP script. We can even let PHP use an infinite (or all that’s available, to be more precise) amount of memory.

Really, there are only two simple steps to getting this done so you can move on with your life.

1. Find Your php.ini

The first thing to remember is that there are usually two versions of php.ini on Linux. This is because you can have a different version for command line scripts and for web servers. Convenient, huh?

For example, in Ubuntu:

On different versions of Linux or BSD, these files may be in different locations but are generally easy to find. Thanks, Google!

Note: On shared hosts, you may not have access to these files. Sorry, folks. You can try to get in touch with your host, but they usually don’t want someone eating up all the RAM on the server because it is shared with other folks.

2. Edit Your “memory_limit”

Once you find the php.ini file, you want to open it in your favorite text editor (vim/nano/etc.).

The line you are looking to edit is called the memory_limit. It will look similar to the following:

memory_limit = 64M

In this example, the memory limit is set to 64MB. If you wanted to change it to 128MB or 32MB or whatever, you just need to change this line. Once you have this line set appropriately, save and exit your php.ini file.

For web servers (!): If you’re changing a web server’s php.ini you must restart the web server. For example on Ubuntu with Apache, you would need to run:

sudo service apache2 restart

After that, your memory limit should change accordingly.

Bonus Step: Setting the PHP “memory_limit -1”

If you are feeling extra frisky and know what you are doing, you can set the memory limit to use all available RAM. This is “dangerous” in that, if your script runs out of control, it will crash your machine. Generally, this wouldn’t be recommended for a production environment, but, hey, it’s your life. Don’t let the man hold you down.

To accomplish this just set the memory limit to -1 like this:

memory_limit = -1

It’s Been Real…But Goodbye

Well, there you have it: You are now a PHP memory changing expert. It’s worth noting that you should poke around your php.ini file to see what’s in there. At some point, you will probably want to change the maximum file size for uploads (upload_max_filesize & post_max_size), but you get the idea. See ya!

Advertiser Disclosure

HostingAdvice.com is a free online resource that offers valuable content and comparison services to users. To keep this resource 100% free, we receive compensation from many of the offers listed on the site. Along with key review factors, this compensation may impact how and where products appear across the site (including, for example, the order in which they appear). HostingAdvice.com does not include the entire universe of available offers. Editorial opinions expressed on the site are strictly our own and are not provided, endorsed, or approved by advertisers.

Our Editorial Review Policy

Our site is committed to publishing independent, accurate content guided by strict editorial guidelines. Before articles and reviews are published on our site, they undergo a thorough review process performed by a team of independent editors and subject-matter experts to ensure the content’s accuracy, timeliness, and impartiality. Our editorial team is separate and independent of our site’s advertisers, and the opinions they express on our site are their own. To read more about our team members and their editorial backgrounds, please visit our site’s About page.

ABOUT THE AUTHOR

Ryan Frankel has been a professional in the tech industry for more than 20 years and has been developing websites for more than 25. With a master's degree in electrical and computer engineering from the University of Florida, he has a fundamental understanding of hardware systems and the software that runs them. Ryan now sits as the CTO of Digital Brands Inc. and manages all of the server infrastructure of their websites, as well as their development team. In addition, Ryan has a passion for guitars, good coffee, and puppies.

« BACK TO: HOW-TO
Follow the Experts
We Know Hosting

$

4

8

,

2

8

3

spent annually on web hosting!