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_value_last — and that it’s also the fastest PHP to date being about 9 – 10% faster as compared to the PHP7.2.
Read Also: 10 PHP Frameworks For Developers – Best of
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.
To begin with, you’ll have to check the PHP version that’s currently installed in your system by typing the following command line:
As we can see below, we are currently using PHP 7.2.7 on our macOS.
To install PHP 7.3, run the following command line in terminal.
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
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.
brew upgrade php
The process may take a bit long, however, once it’s done you can run the
php -v command again. You should now see that the version is updated:
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.
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.
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
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.
sudo apt-get install php7.3 php7.3-common php7.3-cli
That’s all. Your Ubuntu machine will successfully be running PHP7.3.
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.
docker pull php:7.3-fpm-alpine
Once downloaded, we could run it as standalone container with this command below:
docker run --rm -i -t php:7.3-fpm-alpine sh
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.
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.