December 20, 2025

Essential PHP Commands for VPS (PHP-FPM, Debugging, Logs & php.ini)

This guide lists essential PHP commands for a VPS environment, focusing on PHP-FPM, php.ini configuration, error handling, and debugging.
Ideal for production servers using Nginx + PHP, where PHP is managed separately.


1. Check Installed PHP Version

Always verify which PHP version is running on your VPS.

php -v

List all installed PHP versions:

ls /etc/php/

2. Locate PHP Configuration Files (php.ini)

Find Active php.ini

php --ini

Common locations:

/etc/php/8.1/cli/php.ini
/etc/php/8.1/fpm/php.ini

⚠️ Important:

  • cli/php.ini → Used for terminal commands
  • fpm/php.ini → Used by websites (most important)

3. Edit php.ini (Most Important PHP Step)

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

Essential PHP Settings (Recommended)

; Error handling
display_errors = On
display_startup_errors = On
log_errors = On
error_reporting = E_ALL

; Performance
memory_limit = 256M
max_execution_time = 300
max_input_time = 300

; File uploads
upload_max_filesize = 64M
post_max_size = 64M

; Timezone
date.timezone = UTC

📌 Production Tip:
Set display_errors = Off on live servers.

4. PHP Error Log Configuration

Set PHP Error Log Path

Inside php.ini:

error_log = /var/log/php_errors.log

Create Log File & Permissions

sudo touch /var/log/php_errors.log
sudo chown www-data:www-data /var/log/php_errors.log

View PHP Errors Live

tail -f /var/log/php_errors.log

5. PHP-FPM Service Commands (Critical)

Start / Stop / Restart PHP-FPM

sudo systemctl start php8.1-fpm
sudo systemctl stop php8.1-fpm
sudo systemctl restart php8.1-fpm

Reload PHP (After php.ini Changes)

sudo systemctl reload php8.1-fpm

Check Status

sudo systemctl status php8.1-fpm

6. Test PHP Configuration (CLI)

Check loaded modules:

php -m

Check PHP settings:

php -i

Check specific value:

php -i | grep memory_limit

7. Enable PHP Debugging (Development Only)

Recommended Debug Settings

display_errors = On
display_startup_errors = On
error_reporting = E_ALL
log_errors = On

Restart PHP-FPM

sudo systemctl restart php8.1-fpm

⚠️ Disable debugging on production to prevent information leaks.

8. PHP-FPM Pool Configuration (Advanced but Essential)

Edit Pool File

sudo nano /etc/php/8.1/fpm/pool.d/www.conf

Important Pool Settings

user = www-data
group = www-data

pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 5

request_terminate_timeout = 300

Restart after changes:

sudo systemctl restart php8.1-fpm

9. PHP Socket Location (For Nginx Reference)

ls /run/php/

Typical socket:

/run/php/php8.1-fpm.sock

Useful when debugging 502 Bad Gateway errors.

10. Common PHP Debugging Commands

php -v
php --ini
php -m
php -i

Check PHP-FPM logs:

sudo journalctl -u php8.1-fpm -f

Check socket:

sudo ss -pl | grep php

11. Common PHP Errors & Quick Fixes

502 Bad Gateway

  • PHP-FPM not running
  • Wrong socket path
  • Permission issue

Fix:

sudo systemctl restart php8.1-fpm

Memory Limit Error

memory_limit = 512M

File Upload Errors

upload_max_filesize = 128M
post_max_size = 128M

12. Recommended Production PHP Settings

display_errors = Off
expose_php = Off
log_errors = On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

13. PHP Command Cheat Sheet (Quick Reference)

php -v
php --ini
php -m
php -i
sudo systemctl restart php8.1-fpm
sudo journalctl -u php8.1-fpm -f
tail -f /var/log/php_errors.log

Final Thoughts

These essential PHP commands for VPS cover everything needed for:

  • PHP configuration
  • Debugging & logging
  • PHP-FPM management
  • Performance tuning

Use this as a reference checklist alongside your Ubuntu and Nginx setup guides.