How to update PHP version

Since the release of version 7, PHP has seen steady improvements with a new version released each year.

A PHP version usually gets active support for 2 years and security fixes for one year, which means a version is supported for three years since its initial release.

You can view the versions supported by PHP maintainer in php.net.

This tutorial shows how you can update the PHP version installed on your computer.

Update PHP using Homebrew (Mac)

For Mac computers, you can update the PHP version installed on your computer using Homebrew.

Run the brew upgrade command from the terminal as shown below:

brew upgrade php

Once the upgrade is completed, check your PHP version using php -v command:

php -v

You should see the latest PHP version shown in the terminal.

Update PHP for Linux Ubuntu

If you’re using an Ubuntu computer, you can update the installed PHP by running the following commands:

sudo apt-get update
sudo apt-get install php

Once the installation is finished, you can check the installed PHP version using php -v command:

$ php -v
PHP 8.1.2 (cli) (built: Apr  7 2022 17:46:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

If that doesn’t work, then you need to add the PPA repository created by Ondřej Surý to install the latest PHP version.

To install PPA easily, you need to get software-properties-common installed on your computer:

# 👇 install software-properties-common
sudo apt -y install software-properties-common

# 👇 use add-apt-repository command to install the PPA
sudo add-apt-repository ppa:ondrej/php

# 👇 refresh the package manager
sudo apt-get update

# 👇 install latest PHP version
sudo apt -y install php8.1

At the time of this writing, php8.1 is the latest PHP version. You should update the version to match the latest available PHP version when you follow this guide.

Once the installation is finished, check your PHP version again. You should have the latest PHP version printed on the terminal.

Update PHP for Windows

When you use a Windows computer, you can download a PHP distribution from windows.php.net and install it manually on your computer.

Download and extract the zip file from the website, then replace your existing PHP installation with the one you just downloaded.

Don’t change the folder name because Windows won’t be able to find the PHP folder if you do.

Run php -v from the command line to check your PHP version.

If you don’t want to update PHP manually, you can use the Chocolatey package manager to install and update PHP version for you.

Chocolatey is a package manager for Windows computers, it works like Homebrew for Mac computers.

Install Chocolatey on your computer, then install the PHP package with the following command:

# 👇 install php with Chocolatey
choco install php

# 👇 update php with Chocolatey
choco upgrade php

Once the update process is finished, you should have the latest PHP version available from Chocolatey.

Update PHP version in cPanel

To update the PHP version in cPanel, you need to log into the cPanel system first.

Inside the cPanel, you need to find the Select PHP version menu located in the Software tab:

Click on the menu, then change the Current PHP version option as shown below:

Once you change the PHP version, click the Set as current link that appears beside the version number.

cPanel will work to switch the PHP version and restart your website server.

Please keep in mind that not all web hosting provider provides you with a cPanel.

If you use BlueHost or SiteGround as your web host, you can visit the Update PHP for WordPress guide that I’ve written previously.

There are also several other hosting provider guides that you can find here.

Now you’ve learned how to update PHP version installed on your computer with this tutorial. Good work! 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.