PHP7.4 has been released with a handful of new features — like the arrow function array_map(fn (Foo $foo) => $foo->id, $foo)
, typed properties and array spread operator ['foo', ...$foo, ...$bar];
— and that it’s also faster compared to PHP7.3.
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.
10 PHP Frameworks For Developers – Best of
PHP, known as the most popular server-side scripting language in the world, has evolved a lot since the... Read more
Shortcuts to:
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:
php -v
As we can see below, we are currently using PHP 7.3.7 on our macOS.
Arguably the easiest way to install and update PHP on your macOS machine is by using Homebrew. Homebrew is a package manager for macOS though it is now also 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:
Upgrading PHP in Windows
If you’re using Windows, it’s much easier to run your PHP application on a pre-packaged localhost environments such as WAMP or MAMP. These applications 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.3 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 which will install PHP7.4, some PHP extensions and packages, and the PHP CLI.
sudo apt-get install php7.4 php7.4-common php7.4-cli
That’s all. Your Ubuntu machine will successfully be running PHP7.4 and you can confirm by running the php -v
command again.
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.4 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.4 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.4-fpm-alpine
Once downloaded, we could run it as standalone container with this command below:
docker run --rm -i -t php:7.4-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.4 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 a rapidly with PHP8 aimed for the next release by the end of this year with, of course, some interesting features and improvements. It’s an exciting time to be a PHP developer.
The post How to Upgrade PHP to Latest Version appeared first on Hongkiat.
https://goo.gl/hYDEHJ
No comments:
Post a Comment