If you have seen an error like “Fatal Error: PHP Allowed Memory Size Exhausted” in webserver logs or in your browser, this means that PHP has exhausted the maximum memory limit. There are several techniques to increase the PHP memory limit and you only need to use one of them.
Changing memory limit globally from php.ini
To find locate the php.ini file used by your web server. You can use the phpinfo() PHP function to find it. After, type the following command to edit php.ini file:
[root@lifelinux ~]# vi /etc/usr/local/etc/php.ini
Edit the memory_limit parameter in the php.ini file
memory_limit = 32M
You will require root access to make changes to php.ini on the system. This change is global and will be used by all php scripts running on the system. Once you change this value, you will need to restart the web server in order for it to become active.
Changing memory limit using .htaccess
Edit the .htaccess file in the web root directory. Look for the section:
php_value memory_limit 32M
This method will only work if PHP is running as an Apache module.
Changing memory limit inside a single php script
Set this directive inside a single php script:
- How To Install ionCube Loader
- What is the role of this variables in php.ini file (expose_php – allow_url_fopen – register_globals) ?
- How To Install Lighttpd And PHP (PHP-FPM) On CentOS 6
- How To Install Nginx And PHP-FPM On CentOS 6 Via Yum
- How To Install Nginx And PHP (PHP-FPM) On CentOS 6
- How To Limit File Upload Size On Apache
- How To Increase The Number Of PTY (Pseudo-Terminal Driver)
- How To Enable IP Forwarding On CentOS / RedHat
- MySQL Slow Query Log File
- How to disable ICMP echo responses in Linux