How to Increase Memory_Limit php Ubuntu

Through this tutorial, you will learn how to increase or change the memory limit in a PHP Apache Ubuntu server.

By default, PHP has limitations for max post file upload, upload max filesize, max input vars, memory limit, etc. If you would like to increase the size of post_max_size, upload_max_filesize, max_input_vars, memory_limit, and max_file_uploads, then you will learn in a few steps to change the value of php.ini file.

How to Increase memory limit php Ubuntu

Edit your PHP.ini file, and change default value of the PHP memory limit line (eg: maximum amount of memory that can be used by a script = 128MB).

Run the following command to get the currently loaded php.ini file in your ubuntu system:

php -i | grep php.ini

You will find the following output and copy the loaded php.ini file path:

Configuration File (php.ini) Path => /etc/php/8.1/cliLoaded
Configuration File => /etc/php/8.1/cli/php.ini

Now, run the following command on the terminal to set or change max input vars in php.ini Ubuntu by editing the php.ini; as follows:

sudo nano /etc/php/8.1/cli/php.ini

Then find and set the following two values; as follows:

post_max_size = 100M
upload_max_filesize = 100M
max_file_uploads = 20

max_input_vars = 200
memory_limit = -1

Save and close the file. Where,

  1. post_max_size = 100M :
  2. upload_max_filesize = 100M : Maximum allowed size for uploaded files.

Restart Apache server

Now, execute the following command into terminal to restart apache web server; as follows:

$ sudo service apache2 restart
OR
$ systemctl restart apache2.service

Recommended Ubuntu Apache Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *