Prerequisites
Before changing PHP memory limit, make sure you have:
- SSH access to your VPS
- Root or sudo privileges
What is PHP Memory Limit?
Memory limit controls the maximum amount of RAM a PHP script can use. When exceeded, the script stops with "Allowed memory size exhausted" error.
Method 1: Edit php.ini
For PHP 8.2 FPM:
nano /etc/php/8.2/fpm/php.ini
Change:
memory_limit = 256M
Also update CLI:
nano /etc/php/8.2/cli/php.ini
Method 2: Change via .htaccess (Apache)
php_value memory_limit 256M
Method 3: Change via .user.ini (Nginx/FPM)
nano /home/admin/web/example.com/public_html/.user.ini
Add:
memory_limit = 256M
Method 4: Change per Script
ini_set('memory_limit', '256M');
Restart PHP-FPM
systemctl restart php8.2-fpm
Recommended Memory Limits
| Use Case | Memory Limit | Basic WordPress/Drupal | 128M-256M |
|---|---|
| WooCommerce | 256M-512M |
| Laravel, Symfony | 256M |
| Magento | 512M-1G |
| Data processing | 512M-2G |
✅ PHP memory limit has been increased!