Upgrading PHP in Ubuntu

Before doing this, I recommend backing up your system, in case things go wrong.

To upgrade to the latest version of PHP in Ubuntu, first, update the system:

sudo apt-get update && sudo apt-get upgrade

Then add the third-party repository:

sudo apt-get install software-properties-common && sudo add-apt-repository ppa:ondrej/php && sudo apt-get update

Finally, upgrade PHP to the latest version:

sudo apt-get install php7.4

If upgrading PHP for WordPress, you’ll need a few more modules:

sudo apt-get install php7.4-mysql php7.4-curl php7.4-dom php7.4-imagick php7.4-mbstring php7.4-zip php7.4-gd

If using Apache, you’ll need to set the correct PHP version:

# list modules
sudo apache2ctl -M

# deactivate old PHP
sudo a2dismod php7.2

#activate new PHP
sudo a2enmod php7.4

#restart apache
sudo systemctl restart apache2

Leave a Reply

Your email address will not be published. Required fields are marked *