Managing a couple of PHP variations is a commonplace problem when creating PHP packages, the place packages incessantly require other variations because of various framework dependencies and compatibility necessities. Whilst switching between PHP variations can also be daunting, particularly on the device stage, a number of equipment can streamline this procedure.

Managing multiple PHP versions for web developmentManaging multiple PHP versions for web development

On this article, we’ll discover efficient answers for managing a couple of PHP variations, serving to you select the precise device to simplify your building workflow. So, with out additional ado, let’s get began.

The way to Improve PHP to Newest Model

.no-js #ref-block-post-47222 .ref-block__thumbnail { background-image: url(“https://property.hongkiat.com/uploads/thumbs/250×160/how-to-upgrade-php.jpg”); }

The way to Improve PHP to Newest Model

PHP7.4 has been launched with a handful of recent options — just like the arrow serve as array_map(fn (Foo $foo)… Learn extra

1. The use of Homebrew

Homebrew for managing PHP versionsHomebrew for managing PHP versions
Execs:
  • Simple set up and control of a couple of PHP variations.
  • Fast switching between variations with easy instructions.
  • Steadily up to date and well-maintained.
  • Works seamlessly on macOS and Linux.
Cons:
  • Best to be had on macOS and Linux.
  • Updating can also be gradual and somewhat complicated if you happen to’re now not accustomed to running with the CLI.

Homebrew, the preferred bundle supervisor for macOS and Linux, simplifies PHP model control. After putting in Homebrew from their legitimate web page, observe those steps to arrange and turn between PHP variations:

Putting in Other PHP Variations

To control a couple of PHP variations with Homebrew, we’ll first faucet into Shivam Mathur’s widely-used PHP repository. This repository supplies get entry to to quite a lot of PHP variations that you’ll be able to set up:

brew faucet shivammathur/php

As soon as the repository is tapped, you’ll be able to set up your required PHP variations. Right here’s the right way to set up PHP 7.4, 8.2, and the newest model (these days 8.3):

brew set up shivammathur/php/php@7.4
brew set up shivammathur/php/php@8.2
brew set up shivammathur/php/php

Be happy to put in any mixture of variations that your initiatives require. Every model will likely be saved one by one in your device.

Switching Between PHP Variations

Whilst Homebrew means that you can set up a couple of PHP variations concurrently, your device can simplest use one model at a time thru its PATH. Recall to mind it like having a couple of PHP variations put in on your toolbox, however just one can also be your lively device.

Let’s think you might be these days working PHP 8.3, however now you wish to have to modify to PHP 7.4. First, unlink the present model to “disconnect” the these days lively PHP model from PATH.

brew unlink php

After unlinking the present model, you’ll be able to hyperlink the opposite model the use of the brew hyperlink command:

brew hyperlink php@7.4

Now, while you run php -v, it is going to display the lively PHP model as 7.4, as you’ll be able to see underneath.

Checking PHP version using HomebrewChecking PHP version using Homebrew

Homebrew makes it simple to make use of a couple of PHP variations on macOS and Linux during the CLI. However it additionally comes with its personal set of professionals and cons. So believe the next when deciding if Homebrew is the precise selection for you.

2. The use of PHP Track

PHP Monitor for managing PHP versions on macOSPHP Monitor for managing PHP versions on macOS
Execs:
  • Intuitive and user-friendly interface.
  • Simple set up and control of PHP variations with just a few clicks.
  • Fast switching between variations with a unmarried click on.
Cons:
  • Best to be had on macOS.
  • Calls for and is dependent upon Homebrew to regulate PHP installations.
  • Calls for Laravel Valet to maintain the PHP model in line with task.

PHP Track is a light-weight macOS software designed to assist builders set up and turn between other PHP variations simply. It gives a well-known and intuitive UI that looks on the most sensible of your display screen, permitting you to modify between PHP variations with a unmarried click on. This app integrates with Homebrew, making it more straightforward to regulate your PHP setup with out the use of the terminal.

PHP Monitor UI showing available PHP versionsPHP Monitor UI showing available PHP versions

As we will see above, you’ll be able to view which PHP variations are put in in your system, the present model lively globally, get entry to the PHP configuration document, view the reminiscence prohibit, and extra.

The app additionally supplies a easy strategy to set up and replace PHP variations from the Set up PHP Installations… menu.

Managing PHP installations in PHP MonitorManaging PHP installations in PHP Monitor

3. The use of PHPCTL

PHPCTL tool for managing PHP versions with DockerPHPCTL tool for managing PHP versions with Docker
Execs:
  • Platform-independent and conveyable.
  • Supplies further CLI equipment for brand new initiatives, interactive shells, and different common equipment in PHP like PHPCS, PHPUnit, RectorPHP, and many others.
Cons:
  • Calls for Docker to be put in in your device.
  • Calls for guide configuration of the .phpctlrc document to modify between PHP variations.
  • Docker would possibly devour extra assets than different answers.

PHPCTL is a device designed to assist builders simply transfer between other PHP variations by way of leveraging Docker bins. This makes PHPCTL transportable and platform-independent, permitting you to regulate PHP variations on any running device that helps Docker. It additionally supplies further CLI equipment, reminiscent of phpctl create for brand new initiatives, phpctl repl for interactive shells, and phpctl init for configuration setup, amongst different at hand options.

Set up PHPCTL

Earlier than getting began, you’ll want Docker put in in your device. Docker Desktop works nice, or if you happen to’re on macOS, chances are you’ll favor OrbStack.

After getting Docker put in, you’ll be able to set up PHPCTL the use of the next command:

/bin/bash -c "$(curl -fsSL https://phpctl.dev/set up.sh)"

Or, when you’ve got Homebrew put in, you’ll be able to run:

brew set up opencodeco/phpctl/phpctl

This may obtain the PHPCTL binary for your device and make it executable, permitting you to make use of the device in an instant. The script routinely installs PHPCTL and units up the vital paths, so no guide configuration is needed.

After set up, you’ll be able to test if it used to be effectively put in by way of working:

phpctl checklist

This command will checklist the entire subcommands and different details about the present PHP set up, as you’ll be able to see underneath.

PHPCTL command listing available subcommands and PHP infoPHPCTL command listing available subcommands and PHP info

You’ll be able to additionally run the php and composer instructions without delay.

php -v
composer -v

Those two instructions will in reality run within a Docker container. PHPCTL will routinely mount the present listing to the container, so you’ll be able to paintings in your task as if you happen to had been running in your native system.

Switching Between PHP Variations

In contrast to with Homebrew or PHP Track, the place you wish to have to run a command or click on at the UI to modify to the PHP model, with PHPCTL, it is very important create a document .phpctlrc and specify which PHP model you’d love to run throughout the given listing.

PHP_VERSION=83

While you run php or composer within the listing, PHPCTL will routinely transfer to the PHP model specified within the .phpctlrc document.

That’s all. It’s very handy and offers a continuing building enjoy as soon as it’s absolutely configured. On the other hand, it additionally comes with its personal set of professionals and cons.

4. The use of PVM

Execs:
  • Simple set up and control of PHP variations on Home windows.
  • Similar to nvm, making it fast and simple to get accustomed to.
Cons:
  • Best to be had on Home windows.
  • Set up is just a little of a guide procedure.

PVM simplifies PHP model control on Home windows. Very similar to Node Model Supervisor (nvm) however in particular for PHP, PVM removes commonplace Home windows PATH variable complications and streamlines switching between other PHP variations.

Set up PVM

Obtain the newest PVM free up from the legitimate Github repository. Then, create a folder at C:UsersYourUsername.pvmbin and position the downloaded pvm.exe on this folder.

Finally, upload the .pvmbin folder for your device’s PATH variable thru Gadget Houses > Setting Variables.

As soon as put in, you’ll be able to use PVM to modify between PHP variations temporarily and simply. Since it’s closely impressed by way of nvm, the instructions are identical. Listed here are some instructions to get you began:

Putting in PHP with PVM

PVM makes it more straightforward to put in a couple of PHP variations on Home windows. If you wish to have a model that’s now not these days put in in your pc, you’ll be able to use the set up command:

pvm set up 8.2

…which is able to obtain and set up PHP 8.2 in your pc.

Switching PHP Variations with PVM

If you wish to transfer to a particular PHP model, use the use command. You should specify a minimum of the key and minor model, and PVM will make a choice the newest to be had patch model if it’s now not supplied.

pvm use 8.2

If you wish to transfer to a particular patch model, come with the patch quantity as properly:

pvm use 8.2.3

That’s all. PVM is a useful gizmo for managing PHP variations on Home windows, but it surely additionally comes with its personal set of professionals and cons.

5. The use of Valet

Laravel ValetLaravel Valet
Execs:
  • Simple set up and control of PHP variations on macOS.
  • Fast switching between PHP variations for various initiatives.
  • Works seamlessly with Laravel initiatives and helps different forms of initiatives like WordPress, Symfony, and many others.
Cons:
  • Best to be had on macOS.
  • Calls for and is dependent upon Homebrew to regulate PHP installations.

Laravel Valet is a light-weight building surroundings designed in particular for macOS that makes PHP building a breeze. What makes Valet specifically handy is its integrated PHP model control that lets you transfer between PHP variations for various initiatives with out advanced configurations.

Set up Valet

To get began, set up Valet the use of Composer as an international bundle:

composer world require laravel/valet

After set up, run the Valet set up command:

valet set up
Switching PHP Variations with Valet

Valet makes PHP model switching easy with the valet use php@model command. For instance:

valet use php@8.2

It routinely installs the model by way of Homebrew if it’s these days lacking.

For project-specific PHP variations, you’ll be able to create a .valetrc document on your task’s root listing with the road php=php@8.2. Then, merely run:

valet use

…and Valet will routinely transfer to the PHP model specified within the .valetrc document.

Wrapping Up

With the precise equipment, managing a couple of PHP variations turns into easy throughout macOS, Linux, or Home windows. Confidently, this text is helping you select the answer that fits your workflow.

The publish 5 Techniques to Set up More than one Variations of PHP seemed first on Hongkiat.

WordPress Website Development Source: https://www.hongkiat.com/blog/manage-multiple-php-versions/

[ continue ]