# Add Ondřej Surý's PPA for latest PHP versions
sudo add-apt-repository ppa:ondrej/php
sudo apt update
---------------------------------
sudo apt install php8.4 php8.4-cli php8.4-fpm php8.4-common php8.4-mysql php8.4-xml php8.4-xmlrpc php8.4-curl php8.4-gd php8.4-imagick php8.4-cli php8.4-dev php8.4-imap php8.4-mbstring php8.4-opcache php8.4-soap php8.4-zip php8.4-intl
---------------------------------
# Update alternatives to set PHP 8.4 as default
sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.4 84
sudo update-alternatives --install /usr/bin/php-config php-config /usr/bin/php-config8.4 84
sudo update-alternatives --install /usr/bin/phpize phpize /usr/bin/phpize8.4 84
# Configure the default PHP version
sudo update-alternatives --config php
------------------------------------
# Disable old PHP modules
sudo a2dismod php5.6 php7.4 php8.0 php8.1
# Enable PHP 8.4
sudo a2enmod php8.4
# Restart Apache
sudo systemctl restart apache2
-----------------------------------
php -v
----------------------------------
# Remove old PHP versions and their modules
sudo apt purge php5.6* php7.4* php8.0* php8.1*
# Clean up
sudo apt autoremove
sudo apt autoclean
------------------------------------
# Remove old configuration directories (backup first if needed)
sudo rm -rf /etc/php/5.6
sudo rm -rf /etc/php/7.4
sudo rm -rf /etc/php/8.0
sudo rm -rf /etc/php/8.1
# Remove old log files
sudo rm -rf /var/log/php5.6*
sudo rm -rf /var/log/php7.4*
sudo rm -rf /var/log/php8.0*
sudo rm -rf /var/log/php8.1*
-------------------------------------------