PHP 8.x
Install and manage PHP 8.x on Linux VPS, php-fpm, multiple versions, configuration and optimization
PHP 8.x is the modern standard for web applications. This guide covers installation, configuration, and optimization on Ubuntu/Debian and CentOS/AlmaLinux systems.
Installation
Ubuntu / Debian
Add the official Ondrej PHP PPA for latest versions:
apt update
apt install -y software-properties-common
add-apt-repository ppa:ondrej/php
apt update
apt install php8.2 php8.2-fpm php8.2-cliFor PHP 8.3:
apt install php8.3 php8.3-fpm php8.3-cliCentOS / AlmaLinux
Use the Remi repository:
dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf module enable php:remi-8.2
dnf install php php-fpmCommon Extensions
Install essential PHP modules:
apt install php8.2-curl php8.2-mbstring php8.2-xml php8.2-zip php8.2-gd php8.2-mysql php8.2-redis php8.2-opcache php8.2-intlVerify installed extensions:
php -m
php -i | grep "extension_dir"Configuration
php.ini Settings
Edit /etc/php/8.2/fpm/php.ini:
memory_limit = 512M
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 300
max_input_time = 300Opcache Optimization
In the same php.ini file:
opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 60
opcache.fast_shutdown = 1
opcache.enable_cli = 1Verify opcache is loaded:
php -i | grep -i opcachePHP-FPM Management
Pool Configuration
Edit /etc/php/8.2/fpm/pool.d/www.conf:
[www]
user = www-data
group = www-data
listen = /run/php/php8.2-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 10
pm.max_requests = 1000Process management modes:
static- Fixed number of processesdynamic- Adjusts based on loadondemand- Creates processes only when needed
Service Management
# Start and enable
systemctl start php8.2-fpm
systemctl enable php8.2-fpm
# Check status
systemctl status php8.2-fpm
# Restart after config changes
systemctl reload php8.2-fpmMultiple PHP Versions
Run PHP 7.4 and 8.2 simultaneously with different sockets:
Install both versions:
apt install php7.4 php7.4-fpm
apt install php8.2 php8.2-fpmConfigure separate pools in /etc/php/7.4/fpm/pool.d/www.conf:
listen = /run/php/php7.4-fpm.sockAnd in /etc/php/8.2/fpm/pool.d/www.conf:
listen = /run/php/php8.2-fpm.sockStart both:
systemctl start php7.4-fpm php8.2-fpmNginx + PHP-FPM
Configure Nginx to use PHP-FPM:
server {
listen 80;
server_name example.com;
root /var/www/example.com;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}Test and reload:
nginx -t
systemctl reload nginxUseful Commands
# Check PHP version
php -v
# List loaded modules
php -m
# Show php.ini location
php --ini
# Get phpinfo() output
php -i
# Test specific extension
php -r "echo extension_loaded('curl') ? 'Loaded' : 'Not loaded';"Verification
Create /var/www/example.com/info.php:
<?php
phpinfo();
?>Access via browser at http://example.com/info.php to verify everything is running.
PHP 7.x reached end-of-life and is no longer supported. Never use PHP 7.x in production. Migrate to PHP 8.2+ for security, performance, and modern features.
Common Issues
If PHP files are downloaded instead of executed, check that the Nginx location block matches .php$ and fastcgi_pass points to the correct socket path.
For "Connection refused" errors, verify PHP-FPM is running:
systemctl status php8.2-fpm
ps aux | grep php-fpmCheck socket exists:
ls -la /run/php/php8.2-fpm.sock