In this tutorial, we will show you how to increase the PHP memory limit on a Linux server. For those of you who didn’t know, PHP is a popular open-source programming language that is widely used to develop dynamic web applications. In some cases, PHP scripts may require more memory than the default memory limit set in the PHP configuration. This can cause errors and affect the performance of the website. Increasing the PHP memory limit is a simple process that can help to avoid memory-related errors and improve the performance of your website
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges.
Prerequisites
- A server running one of the following operating systems: Debian-based or RHEL-based.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Increase PHP Memory Limit
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf clean all sudo dnf update
Step 2. Increasing the PHP Memory Limit.
To increase the PHP memory limit, you can modify the php.ini
file. This file is the main configuration file for PHP. First, locate the php.ini
file on your system. You can do this by running the following command in the terminal:
php -i | grep php.ini
After you have found the php.ini file, you can edit it with your favorite text editor and look for the following line:
memory_limit = 128M
Change the value to the desired limit. For example, to increase the limit to 512 MB, use:
memory_limit = 512M
Save and close the file, then restart the Apache web server to make the change effect:
sudo systemctl restart apache2
Replace apache2
with the name of your web server if you are using a different one.
For additional resources on installing PHP, read the post below:
Step 3. Checking the Current PHP Memory Limit.
To verify that the PHP memory limit has been increased, you can create a PHP script that outputs the current memory limit. You can check by creating a file called info.php
in /var/www/html/
with the following content:
<?php phpinfo(); ?>
Save and close the file, then visit the following URL in your web browser:
http://your-IP-server/info.php
Congratulations! You have successfully increased the PHP memory. Thanks for using this tutorial to change the PHP memory limit Linux system. For additional help or useful information, we recommend you check the official PHP website.