How to install PHP 7.4 / PHP 8 on Ubuntu 18.04

Assalamu aleykum

Update the repository index.
sudo apt-get update

Useful to do.
sudo apt -y install software-properties-common

Firstly, to be able to install a certain PHP version, in this case, 7.2 you’ll need to add a certain repository to your system
sudo add-apt-repository ppa:ondrej/php

Install PHP 7.4 with the below command.
sudo apt-get install php7.4

sudo apt-get install php7.4-mysql

For nginx use the following:
sudo apt install -y php7.4 php7.4-cli php7.4-common php7.4-fpm

Check to make sure PHP 7.4 is installed
php -v

These are the required extensions for your WordPRess installation.
sudo apt install -y php7.4-mysql php7.4-dom php7.4-simplexml php7.4-ssh2 php7.4-xml php7.4-xmlreader php7.4-curl php7.4-exif php7.4-ftp php7.4-gd php7.4-iconv php7.4-imagick php7.4-json php7.4-mbstring php7.4-posix php7.4-sockets php7.4-tokenizer

Having said that it’s good to have these extensions as well.
sudo apt install -y php7.4-mysqli php7.4-pdo php7.4-sqlite3 php7.4-ctype php7.4-fileinfo php7.4-zip php7.4-exif

For Apache2 in my case I also needed:
sudo apt install libapache2-mod-php7.4

Disable PHP 7.0
sudo a2dismod php7.0

Enable PHP 7.4
sudo a2enmod php7.4

Restart apache2!
sudo service apache2 restart

That’s it, you now have your PHP version installed.


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.