5 Techniques to Set up More than one Variations of PHP

by | Oct 28, 2024 | Etcetera | 0 comments

Managing a few PHP permutations is a not unusual drawback when developing PHP applications, where applications often require different permutations on account of more than a few framework dependencies and compatibility prerequisites. While switching between PHP permutations can be daunting, specifically at the instrument degree, quite a lot of apparatus can streamline this process.

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

In this article, we’ll uncover environment friendly solutions for managing a few PHP permutations, helping you choose the proper instrument to simplify your construction workflow. So, without further ado, let’s get started.

The way to Improve PHP to Newest Model

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

1. Using Homebrew

Homebrew for managing PHP versionsHomebrew for managing PHP versions
Professionals:
  • Easy arrange and keep watch over of a few PHP permutations.
  • Rapid switching between permutations with simple directions.
  • Continuously up-to-the-minute and well-maintained.
  • Works seamlessly on macOS and Linux.
Cons:
  • Perfect available on macOS and Linux.
  • Updating can be sluggish and moderately sophisticated should you occur to’re no longer aware of operating with the CLI.

Homebrew, the most popular package manager for macOS and Linux, simplifies PHP type keep watch over. After setting up Homebrew from their respectable internet web page, follow the ones steps to organize and switch between PHP permutations:

Setting up Different PHP Diversifications

To keep watch over a few PHP permutations with Homebrew, we’ll first tap into Shivam Mathur’s widely-used PHP repository. This repository provides get admission to to moderately numerous PHP permutations that you just’ll have the ability to arrange:

brew tap shivammathur/php

As quickly because the repository is tapped, you’ll have the ability to arrange your desired PHP permutations. Proper right here’s how one can arrange PHP 7.4, 8.2, and the most recent type (nowadays 8.3):

brew arrange shivammathur/php/php@7.4
brew arrange shivammathur/php/php@8.2
brew arrange shivammathur/php/php

Feel free to place in any mix of permutations that your projects require. Each type might be stored one after the other on your instrument.

Switching Between PHP Diversifications

While Homebrew signifies that you’ll arrange a few PHP permutations similtaneously, your instrument can most straightforward use one type at a time through its PATH. Bring to mind it like having a few PHP permutations installed in your toolbox, alternatively only one can be your vigorous instrument.

Let’s assume you could be nowadays operating PHP 8.3, alternatively now you need to change to PHP 7.4. First, unlink the existing type to “disconnect” the nowadays vigorous PHP type from PATH.

brew unlink php

After unlinking the existing type, you’ll have the ability to link the other type the usage of the brew link command:

brew link php@7.4

Now, whilst you run php -v, it’s going to show the vigorous PHP type as 7.4, as you’ll have the ability to see beneath.

See also  Find out how to Simply Upload Sensible App Banners in WordPress
Checking PHP version using HomebrewChecking PHP version using Homebrew

Homebrew makes it easy to use a few PHP permutations on macOS and Linux all over the CLI. Then again it moreover comes with its private set of execs and cons. So imagine the following when deciding if Homebrew is the proper variety for you.

2. Using PHP Monitor

PHP Monitor for managing PHP versions on macOSPHP Monitor for managing PHP versions on macOS
Professionals:
  • Intuitive and user-friendly interface.
  • Easy arrange and keep watch over of PHP permutations with only some clicks.
  • Rapid switching between permutations with a single click on on.
Cons:
  • Perfect available on macOS.
  • Requires and depends upon Homebrew to keep watch over PHP installations.
  • Requires Laravel Valet to take care of the PHP type consistent with process.

PHP Track is a lightweight macOS tool designed to help developers arrange and switch between different PHP permutations merely. It provides a well known and intuitive UI that appears at the top of your computer screen, allowing you to change between PHP permutations with a single click on on. This app integrates with Homebrew, making it easier to keep watch over your PHP setup without the usage of the terminal.

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

As we will be able to see above, you’ll have the ability to view which PHP permutations are installed on your machine, the existing type vigorous globally, get admission to the PHP configuration file, view the memory restrict, and additional.

The app moreover provides a simple method to arrange and substitute PHP permutations from the Arrange PHP Installations… menu.

Managing PHP installations in PHP MonitorManaging PHP installations in PHP Monitor

3. Using PHPCTL

PHPCTL tool for managing PHP versions with DockerPHPCTL tool for managing PHP versions with Docker
Professionals:
  • Platform-independent and transportable.
  • Provides additional CLI apparatus for new projects, interactive shells, and other not unusual apparatus in PHP like PHPCS, PHPUnit, RectorPHP, and plenty of others.
Cons:
  • Requires Docker to be installed on your instrument.
  • Requires information configuration of the .phpctlrc file to change between PHP permutations.
  • Docker would perhaps eat further property than other solutions.

PHPCTL is a tool designed to help developers merely switch between different PHP permutations by the use of leveraging Docker bins. This makes PHPCTL moveable and platform-independent, allowing you to keep watch over PHP permutations on any operating instrument that is helping Docker. It moreover provides additional CLI apparatus, harking back to phpctl create for new projects, phpctl repl for interactive shells, and phpctl init for configuration setup, among other to hand choices.

Arrange PHPCTL

Previous than getting started, you’ll need Docker installed on your instrument. Docker Desktop works great, or should you occur to’re on macOS, likelihood is that you’ll choose OrbStack.

See also  7 Will have to-Have Pages Each and every Web site Wishes (+ 11 Not obligatory Ones)

Once you have Docker installed, you’ll have the ability to arrange PHPCTL the usage of the following command:

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

Or, while you’ve were given Homebrew installed, you’ll have the ability to run:

brew arrange opencodeco/phpctl/phpctl

This may occasionally download the PHPCTL binary in your instrument and make it executable, allowing you to use the instrument right away. The script robotically installs PHPCTL and gadgets up the essential paths, so no information configuration is wanted.

After arrange, you’ll have the ability to check if it was once successfully installed by the use of operating:

phpctl tick list

This command will tick list all the subcommands and other information about the existing PHP arrange, as you’ll have the ability to see beneath.

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

You’ll have the ability to moreover run the php and composer directions directly.

php -v
composer -v

The ones two directions will in truth run inside a Docker container. PHPCTL will robotically mount the existing list to the container, so that you’ll have the ability to artwork on your process as should you occur to have been operating on your local machine.

Switching Between PHP Diversifications

By contrast to with Homebrew or PHP Monitor, where you need to run a command or click on on on the UI to change to the PHP type, with PHPCTL, you will need to create a file .phpctlrc and specify which PHP type you’d like to run all through the given list.

PHP_VERSION=83

When you run php or composer throughout the list, PHPCTL will robotically switch to the PHP type specified throughout the .phpctlrc file.

That’s all. It’s very to hand and provides a unbroken construction revel in as quickly because it’s completely configured. Then again, it moreover comes with its private set of execs and cons.

4. Using PVM

Professionals:
  • Easy arrange and keep watch over of PHP permutations on House home windows.
  • Very similar to nvm, making it rapid and easy to get aware of.
Cons:
  • Perfect available on House home windows.
  • Arrange is just a bit of a information process.

PVM simplifies PHP type keep watch over on House home windows. Similar to Node Model Supervisor (nvm) alternatively specifically for PHP, PVM gets rid of not unusual House home windows PATH variable headaches and streamlines switching between different PHP permutations.

Arrange PVM

Download the most recent PVM unlock from the legitimate Github repository. Then, create a folder at C:UsersYourUsername.pvmbin and place the downloaded pvm.exe in this folder.

After all, add the .pvmbin folder in your instrument’s PATH variable through System Properties > Surroundings Variables.

Once installed, you’ll have the ability to use PVM to change between PHP permutations quickly and easily. Because it’s carefully inspired by the use of nvm, the directions are equivalent. Listed below are some directions to get you started:

Setting up PHP with PVM

PVM makes it easier to place in a few PHP permutations on House home windows. If you want to have a type that’s no longer nowadays installed on your computer, you’ll have the ability to use the arrange command:

pvm arrange 8.2

…which is in a position to download and arrange PHP 8.2 on your computer.

See also  Get a Free Bake Shop Layout Pack for Divi
Switching PHP Diversifications with PVM

If you want to switch to a specific PHP type, use the use command. You must specify at least the important thing and minor type, and PVM will choose the most recent available patch type if it’s no longer equipped.

pvm use 8.2

If you want to switch to a specific patch type, include the patch amount as correctly:

pvm use 8.2.3

That’s all. PVM is a handy gizmo for managing PHP permutations on House home windows, however it certainly moreover comes with its private set of execs and cons.

5. Using Valet

Laravel ValetLaravel Valet
Professionals:
  • Easy arrange and keep watch over of PHP permutations on macOS.
  • Rapid switching between PHP permutations for more than a few projects.
  • Works seamlessly with Laravel projects and is helping other sorts of projects like WordPress, Symfony, and plenty of others.
Cons:
  • Perfect available on macOS.
  • Requires and depends upon Homebrew to keep watch over PHP installations.

Laravel Valet is a lightweight construction atmosphere designed specifically for macOS that makes PHP construction a breeze. What makes Valet in particular to hand is its built-in PHP type keep watch over that allows you to switch between PHP permutations for more than a few projects without complex configurations.

Arrange Valet

To get started, arrange Valet the usage of Composer as a global package:

composer international require laravel/valet

After arrange, run the Valet arrange command:

valet arrange
Switching PHP Diversifications with Valet

Valet makes PHP type switching simple with the valet use php@type command. For example:

valet use php@8.2

It robotically installs the type by the use of Homebrew if it’s nowadays missing.

For project-specific PHP permutations, you’ll have the ability to create a .valetrc file in your process’s root list with the street php=php@8.2. Then, simply run:

valet use

…and Valet will robotically switch to the PHP type specified throughout the .valetrc file.

Wrapping Up

With the proper apparatus, managing a few PHP permutations becomes simple all through macOS, Linux, or House home windows. Hopefully, this newsletter helps you choose the solution that matches your workflow.

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

WordPress Website Development

Supply: https://www.hongkiat.com/blog/manage-multiple-php-versions/

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!