Skip to content

PHP 8.3 Commands

PHP-FPM (FastCGI Process Manager) handles all PHP processing for Zal Ultra. These commands help you manage the PHP service.

🟠 MEDIUM RISK

Restarting PHP-FPM will briefly interrupt all web requests. Users may see errors for 1-2 seconds during restart.


Table of Contents

  1. Service Management
  2. Configuration
  3. Performance Tuning
  4. Log Management
  5. Troubleshooting

Service Management

Check PHP-FPM Status

bash
sudo systemctl status php8.3-fpm

Purpose: Shows if PHP-FPM is running and recent activity.


Start PHP-FPM

bash
sudo systemctl start php8.3-fpm

Stop PHP-FPM

🔴 SERVICE OUTAGE

Stopping PHP-FPM will make Zal Ultra completely non-functional. All pages will show 502 errors.

bash
sudo systemctl stop php8.3-fpm

Restart PHP-FPM

🟠 BRIEF INTERRUPTION

Restart causes 1-2 seconds of 502 errors for active users.

bash
sudo systemctl restart php8.3-fpm

When to use:

  • After php.ini changes
  • After installing PHP extensions
  • Memory issues

Reload PHP-FPM (Graceful)

bash
sudo systemctl reload php8.3-fpm

Purpose: Gracefully reloads configuration. Preferred over restart.


Enable on Boot

bash
sudo systemctl enable php8.3-fpm

Configuration

PHP Version Check

bash
php -v

Show PHP Info

bash
php -i

Show Loaded Modules

bash
php -m

Check Specific Module

bash
php -m | grep -i mysql
php -m | grep -i redis
php -m | grep -i gd

Configuration Files

bash
# Main PHP CLI config
sudo nano /etc/php/8.3/cli/php.ini

# PHP-FPM config
sudo nano /etc/php/8.3/fpm/php.ini

# FPM pool config (important!)
sudo nano /etc/php/8.3/fpm/pool.d/www.conf

Important php.ini Settings

bash
# View current settings
php -i | grep memory_limit
php -i | grep max_execution_time
php -i | grep upload_max_filesize
php -i | grep post_max_size

Common Settings to Adjust

ini
; /etc/php/8.3/fpm/php.ini

memory_limit = 512M
max_execution_time = 300
upload_max_filesize = 100M
post_max_size = 100M
max_input_vars = 5000

After changing php.ini:

bash
sudo systemctl restart php8.3-fpm

Performance Tuning

Check FPM Pool Status

bash
# If status page is enabled
curl http://localhost/status

# Or check processes
ps aux | grep php-fpm

Count PHP-FPM Workers

bash
ps aux | grep "php-fpm: pool" | wc -l

Check Memory Usage per Worker

bash
ps -ylC php-fpm8.3 --sort:rss

Pool Configuration (www.conf)

bash
sudo nano /etc/php/8.3/fpm/pool.d/www.conf

Key settings:

ini
; Process manager type
pm = dynamic

; Maximum children (adjust based on RAM)
pm.max_children = 50

; Start servers
pm.start_servers = 10

; Min/Max spare servers
pm.min_spare_servers = 5
pm.max_spare_servers = 20

; Max requests before respawn (prevents memory leaks)
pm.max_requests = 500

Memory calculation:

  • Each PHP-FPM worker uses ~50-100MB
  • pm.max_children = Available RAM / 100MB
  • Example: 8GB RAM → max_children = 50-60

Log Management

View PHP-FPM Logs

bash
sudo tail -f /var/log/php8.3-fpm.log

View PHP Error Log

bash
# Check where errors go
php -i | grep error_log

# Common location
sudo tail -f /var/log/php_errors.log

View Slow Log (if enabled)

bash
sudo tail -f /var/log/php8.3-fpm.slow.log

Enable Slow Log

bash
# In /etc/php/8.3/fpm/pool.d/www.conf
slowlog = /var/log/php8.3-fpm.slow.log
request_slowlog_timeout = 5s

Clear PHP Logs

🟠 CAUTION

This removes log history.

bash
sudo truncate -s 0 /var/log/php8.3-fpm.log
sudo truncate -s 0 /var/log/php_errors.log

Troubleshooting

Common Issues

502 Bad Gateway

bash
# Check if PHP-FPM is running
sudo systemctl status php8.3-fpm

# Check socket exists
ls -la /run/php/php8.3-fpm.sock

# Restart PHP-FPM
sudo systemctl restart php8.3-fpm

Memory Exhausted

bash
# Increase memory limit
sudo nano /etc/php/8.3/fpm/php.ini
# Set: memory_limit = 512M

sudo systemctl restart php8.3-fpm

Max Execution Time

bash
# Increase timeout
sudo nano /etc/php/8.3/fpm/php.ini
# Set: max_execution_time = 300

sudo systemctl restart php8.3-fpm

Socket Permission Issues

bash
# Check socket permissions
ls -la /run/php/php8.3-fpm.sock

# Fix in www.conf
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

Check PHP Extensions

bash
# Required for Zal Ultra
php -m | grep -E "mysql|redis|gd|curl|mbstring|xml|zip|bcmath"

Install Missing Extension

bash
sudo apt install php8.3-mysql php8.3-redis php8.3-gd php8.3-curl php8.3-mbstring php8.3-xml php8.3-zip php8.3-bcmath
sudo systemctl restart php8.3-fpm

Clear OPcache

bash
# From command line
php -r "opcache_reset();"

# Or restart PHP-FPM
sudo systemctl restart php8.3-fpm

Quick Reference Card

ActionCommand
Check statussudo systemctl status php8.3-fpm
Startsudo systemctl start php8.3-fpm
Stopsudo systemctl stop php8.3-fpm
Restartsudo systemctl restart php8.3-fpm
Reloadsudo systemctl reload php8.3-fpm
PHP versionphp -v
PHP modulesphp -m
View logssudo tail -f /var/log/php8.3-fpm.log
Config (FPM)/etc/php/8.3/fpm/php.ini
Pool config/etc/php/8.3/fpm/pool.d/www.conf

www.onezeroart.com