Installing PHP and Managing Versions
Install PHP on Ubuntu/Debian
Ubuntu's default repos may not have the latest PHP. Use the Ondrej PPA for more recent versions:
apt install software-properties-common -y
add-apt-repository ppa:ondrej/php -y
apt update
apt install php8.2 php8.2-fpm php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip -y
Install PHP on CentOS/AlmaLinux (Remi Repository)
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
dnf module enable php:remi-8.2 -y
dnf install php php-fpm php-mysqlnd php-curl php-gd php-mbstring php-xml -y
Check Active PHP Version
php -v
Switch Between PHP Versions (Ubuntu with multiple installed)
# For CLI:
update-alternatives --config php
# For Apache:
a2dismod php8.1
a2enmod php8.2
systemctl restart apache2
# For Nginx (PHP-FPM), update the socket path in your server block:
# fastcgi_pass unix:/run/php/php8.2-fpm.sock;
List Installed PHP Extensions
php -m
Install Additional Extensions
apt install php8.2-redis php8.2-imagick php8.2-intl -y
PHP Configuration File Location
php --ini # Shows which php.ini is loaded
Common tweaks in php.ini: increase upload_max_filesize, post_max_size, memory_limit, and max_execution_time.