Are You Still Using Old PHP Version? Time to Upgrade Now!

This year is an exciting time for PHP as the core development is accelerating in a good direction. At the time of this writing, PHP7.3 has just been released with a handful of new features, functions — like array_key_firstarray_key_lastarray_value_first, and array_value_last — and that it’s also the fastest PHP to date being about 9 – 10% faster as compared to the PHP7.2.

So if you’re thinking to update PHP on your machine, take a look at the following post in which I’ll show you how to do so in several ways.

Upgrading PHP in macOS

To begin with, you’ll have to check the PHP version that’s currently installed in your system by typing the following command line:

To install PHP 7.3, run the following command line in terminal.

Another way to install and update PHP on your macOS machine is by using Homebrew. Homebrew is a kind of package manager for macOS, which it is now available in Linux and Windows too. With Homebrew, you can type the following command.

Upgrading PHP in Windows

If you’re using Windows, you’ll likely be running your PHP application on a pre-packaged localhost environments such as WAMP and MAMP which comes with PHP pre-installed and configured. You will just need to update them to their latest version or install it using the built-in tool to get the latest PHP version.

In addition to that, both WAMP and MAMP provide an option within the application to switch PHP easily.

Upgrading PHP in Ubuntu

As mentioned previously, you should first check the PHP version that’s in your Ubuntu machine.

As you can see above, currently I have PHP7.2 installed. In Ubuntu, the PHP package can be installed from the ondrej/php respository. First, run the following command to tap the repository.

Then, we can run the following commands to install PHP7.3. Please note that this command will install the PHP7.3 core, some command extensions and packages, and the PHP CLI.

That’s all. Your Ubuntu machine will successfully be running PHP7.3.

Upgrading PHP in Docker

The latest PHP version is also available as an official Docker image. Docker is compatible in several different platforms including macOS, Windows, and Linux so you should be able to follow the same procedure for all these operating systems.

To do so, first I’d like to see if I have the Docker image for PHP7.3 in my machine.

It looks like that I don’t have it yet. Let’s type the following command to download the image. This command will download the Docker image for PHP7.3 in the Alpine Linux flavour which smaller than the Debian-based image thus also faster to download. You can find the full list of the Docker image available in Docker Hub.

Once downloaded, we could run it as standalone container with this command below:

The container should be up and running in a second and immediately creates a Shell session inside the container. If we run the php -v, we should be seeing that it is the PHP7.3 within the Docker container.

Wrapping Up

That’s all how to install and update PHP version to the latest. It’s not as complicated as you’d expected, isn’t it? Finally, PHP core development is progressing at fast rate with PHP7.4 and PHP8 currently being discussed. It’s an exciting time to be a PHP developer.

Latest posts by Steve (see all)