If you’re like me and like to wait until all the bugs are sorted out with a new PHP version before upgrading, then you probably need to update your PHP version on your system. I should have done this since February last year but I got caught up with other stuff.
This guide works with Ubuntu 22.04, 20.04 and 18.04.
But have no fear, the process is not that difficult at all. Just follow these steps.
Update your system by typing the following code in a terminal window: sudo apt update
and press ENTER (the ENTER key on the keyboard).
Next, type sudo apt upgrade
and press ENTER. When prompted “Do you want to continue? [Y/n]” type “y” then press ENTER.
If you haven’t done so, add Ondrej Sury’s repository by typing:
sudo apt installsoftware-properties-common
then pressing “y” then ENTERsudo add-apt-repository ppa:ondrej/php
then press ENTERUpdate your system (Again) by typing: sudo apt update
and press ENTER.
Type sudo apt install php8.1
then press ENTER.
When prompted “Do you want to continue? [Y/n]” type “y” then press ENTER and wait for the installation to complete.
Type php --version
and press ENTER. You will see the PHP version below.
This is the last step. You will need extensions for you various PHP scripts to work. To install PHP 8.1 extensions, type the following command:sudo apt install php8.1-EXTENSION_NAME
where EXTENSION_NAME is the name of the extension (zip, mysql, gd, curl, etc.).
For example, if you wanted to install the mysql extension for use with WordPress, you would type sudo apt install php8.1-mysql
then press ENTER.
To install multiple extensions at once, you would type sudo apt install php8.1-{xml,mysql,zip,gd}
for example. Replace the extensions in the curly braces with the actual names of the extensions you want to install.
Thanks to Computing for Geeks.com, here’s a command with commonly used PHP extensions:sudo apt install php8.1-{bcmath,xml,fpm,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi}
.
Now you’re all set and ready to use PHP 8.1. Happy coding guys and gals!