{"id":716,"date":"2024-10-28T12:00:38","date_gmt":"2024-10-28T13:00:38","guid":{"rendered":"https:\/\/upprofits.net\/?p=716"},"modified":"2024-11-06T19:09:52","modified_gmt":"2024-11-06T19:09:52","slug":"5-ways-to-manage-multiple-versions-of-php","status":"publish","type":"post","link":"https:\/\/upprofits.net\/index.php\/2024\/10\/28\/5-ways-to-manage-multiple-versions-of-php\/","title":{"rendered":"5 Ways to Manage Multiple Versions of PHP"},"content":{"rendered":"
Managing multiple PHP versions is a common challenge when developing PHP applications, where applications often require different versions due to varying framework dependencies and compatibility requirements. While switching between PHP versions can be daunting, especially at the system level, several tools can streamline this process.<\/p>\n In this article, we\u2019ll explore effective solutions for managing multiple PHP versions, helping you choose the right tool to simplify your development workflow. So, without further ado, let\u2019s get started.<\/p>\n .no-js #ref-block-post-47222 .ref-block__thumbnail { background-image: url(“https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250×160\/how-to-upgrade-php.jpg”); }<\/p><\/div>\n \n\t\t\t\t\t\tPHP7.4 has been released with a handful of new features \u2014 like the arrow function array_map(fn (Foo $foo)…\t\t\t\t\t\tRead more<\/span><\/p>\n<\/div>\n<\/div>\n Homebrew<\/a>, the popular package manager for macOS and Linux, simplifies PHP version management. After installing Homebrew from their official website, follow these steps to set up and switch between PHP versions:<\/p>\n To manage multiple PHP versions with Homebrew, we\u2019ll first tap into Shivam Mathur\u2019s widely-used PHP repository<\/a>. This repository provides access to various PHP versions that you can install:<\/p>\n Once the repository is tapped, you can install your desired PHP versions. Here\u2019s how to install PHP 7.4, 8.2, and the latest version (currently 8.3):<\/p>\n Feel free to install any combination of versions that your projects require. Each version will be stored separately on your system.<\/p>\n While Homebrew allows you to install multiple PHP versions simultaneously, your system can only use one version at a time through its Let\u2019s assume you are currently running PHP 8.3, but now you need to switch to PHP 7.4. First, unlink the current version to \u201cdisconnect\u201d the currently active PHP version from After unlinking the current version, you can link the other version using the Now, when you run Homebrew makes it easy to use multiple PHP versions on macOS and Linux through the CLI. But it also comes with its own set of pros and cons. So consider the following when deciding if Homebrew is the right choice for you.<\/p>\n PHP Monitor<\/a><\/strong> is a lightweight macOS application designed to help developers manage and switch between different PHP versions easily. It offers a familiar and intuitive UI that appears at the top of your screen, allowing you to switch between PHP versions with a single click. This app integrates with Homebrew, making it easier to manage your PHP setup without using the terminal.<\/p>\n As we can see above, you can view which PHP versions are installed on your machine, the current version active globally, access the PHP configuration file, view the memory limit, and more.<\/p>\n The app also provides a simple way to install and update PHP versions from the Manage PHP Installations\u2026<\/strong> menu.<\/p>\n PHPCTL<\/a><\/strong> is a tool designed to help developers easily switch between different PHP versions by leveraging Docker containers<\/a>. This makes PHPCTL portable and platform-independent, allowing you to manage PHP versions on any operating system that supports Docker. It also provides additional CLI tools, such as Before getting started, you\u2019ll need Docker installed on your system. Docker Desktop<\/a> works great, or if you\u2019re on macOS, you might prefer OrbStack<\/a>.<\/p>\n Once you have Docker installed, you can install PHPCTL using the following command:<\/p>\n Or, if you have Homebrew installed, you can run:<\/p>\n This will download the PHPCTL binary to your system and make it executable, allowing you to use the tool right away. The script automatically installs PHPCTL and sets up the necessary paths, so no manual configuration is required.<\/p>\n After installation, you can check if it was successfully installed by running:<\/p>\n This command will list all the subcommands and other information about the current PHP installation, as you can see below.<\/p>\n You can also run the These two commands will actually run inside a Docker container. PHPCTL will automatically mount the current directory to the container, so you can work on your project as if you were working on your local machine.<\/p>\n Unlike with Homebrew or PHP Monitor, where you need to run a command or click on the UI to switch to the PHP version, with PHPCTL, you will need to create a file When you run That\u2019s all. It\u2019s very convenient and provides a seamless development experience once it is fully configured. However, it also comes with its own set of pros and cons.<\/p>\n PVM simplifies PHP version management on Windows. Similar to Node Version Manager (nvm)<\/a> but specifically for PHP, PVM eliminates common Windows Download the latest PVM release from the official Github repository<\/a>. Then, create a folder at Lastly, add the Once installed, you can use PVM to switch between PHP versions quickly and easily. Since it is heavily inspired by nvm, the commands are similar. Here are some commands to get you started:<\/p>\n PVM makes it easier to install multiple PHP versions on Windows. If you need a version that\u2019s not currently installed on your computer, you can use the install command:<\/p>\n \u2026which will download and install PHP 8.2 on your computer.<\/p>\n If you want to switch to a specific PHP version, use the use command. You must specify at least the major and minor version, and PVM will choose the latest available patch version if it\u2019s not provided.<\/p>\n If you want to switch to a specific patch version, include the patch number as well:<\/p>\n That\u2019s all. PVM is a great tool for managing PHP versions on Windows, but it also comes with its own set of pros and cons.<\/p>\n Laravel Valet<\/a> is a lightweight development environment designed specifically for macOS that makes PHP development a breeze. What makes Valet particularly convenient is its built-in PHP version management that allows you to switch between PHP versions for different projects without complex configurations.<\/p>\n To get started, install Valet using Composer as a global package:<\/p>\n After installation, run the Valet installation command:<\/p>\n Valet makes PHP version switching simple with the It automatically installs the version via Homebrew if it\u2019s currently missing.<\/p>\n For project-specific PHP versions, you can create a \u2026and Valet will automatically switch to the PHP version specified in the With the right tools, managing multiple PHP versions becomes effortless across macOS, Linux, or Windows. Hopefully, this article helps you pick the solution that matches your workflow.<\/p>\n The post 5 Ways to Manage Multiple Versions of PHP<\/a> appeared first on Hongkiat<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" Managing multiple PHP versions is a common challenge when developing PHP applications, where applications often require different versions due to varying framework dependencies and compatibility requirements. While switching between PHP versions can be daunting, especially at the system level, several tools can streamline this process. In this article, we\u2019ll explore effective solutions for managing multiple […]<\/p>\n","protected":false},"author":1,"featured_media":718,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-716","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-social-commerce"],"_links":{"self":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/716"}],"collection":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/comments?post=716"}],"version-history":[{"count":3,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/716\/revisions"}],"predecessor-version":[{"id":728,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/posts\/716\/revisions\/728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/media\/718"}],"wp:attachment":[{"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/media?parent=716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/categories?post=716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/upprofits.net\/index.php\/wp-json\/wp\/v2\/tags?post=716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<\/figure>\n
How to Upgrade PHP to Latest Version<\/h4>\n
1. Using Homebrew<\/h4>\n
<\/figure>\n
\n
\n
Installing Different PHP Versions<\/h5>\n
\r\nbrew tap shivammathur\/php\r\n<\/pre>\n
\r\nbrew install shivammathur\/php\/php@7.4\r\nbrew install shivammathur\/php\/php@8.2\r\nbrew install shivammathur\/php\/php\r\n<\/pre>\n
Switching Between PHP Versions<\/h5>\n
PATH<\/code>. Think of it like having multiple PHP versions installed in your toolbox, but only one can be your active tool.<\/p>\n
PATH<\/code>.<\/p>\n
\r\nbrew unlink php\r\n<\/pre>\n
brew link<\/code> command:<\/p>\n
\r\nbrew link php@7.4\r\n<\/pre>\n
php -v<\/code>, it will show the active PHP version as 7.4<\/strong>, as you can see below.<\/p>\n
<\/figure>\n
2. Using PHP Monitor<\/h4>\n
<\/figure>\n
\n
\n
<\/figure>\n
<\/figure>\n
3. Using PHPCTL<\/h4>\n
<\/figure>\n
\n
\n
.phpctlrc<\/code> file to switch between PHP versions.<\/li>\n
phpctl create<\/code> for new projects,
phpctl repl<\/code> for interactive shells, and
phpctl init<\/code> for configuration setup, among other handy features.<\/p>\n
Install PHPCTL<\/h5>\n
\r\n\/bin\/bash -c \"$(curl -fsSL https:\/\/phpctl.dev\/install.sh)\"\r\n<\/pre>\n
\r\nbrew install opencodeco\/phpctl\/phpctl\r\n<\/pre>\n
\r\nphpctl list\r\n<\/pre>\n
<\/figure>\n
php<\/code> and
composer<\/code> commands directly.<\/p>\n
\r\nphp -v\r\ncomposer -v\r\n<\/pre>\n
Switching Between PHP Versions<\/h5>\n
.phpctlrc<\/code> and specify which PHP version you\u2019d like to run within the given directory.<\/p>\n
\r\nPHP_VERSION=83\r\n<\/pre>\n
php<\/code> or
composer<\/code> in the directory, PHPCTL will automatically switch to the PHP version specified in the
.phpctlrc<\/code> file.<\/p>\n
4. Using PVM<\/h4>\n
\n
\n
PATH<\/code> variable headaches and streamlines switching between different PHP versions.<\/p>\n
Install PVM<\/h5>\n
C:UsersYourUsername.pvmbin<\/code> and place the downloaded
pvm.exe<\/code> in this folder.<\/p>\n
.pvmbin<\/code> folder to your system\u2019s
PATH<\/code> variable through System Properties > Environment Variables<\/strong>.<\/p>\n
Installing PHP with PVM<\/h5>\n
\r\npvm install 8.2\r\n<\/pre>\n
Switching PHP Versions with PVM<\/h5>\n
pvm use 8.2<\/pre>\n
pvm use 8.2.3<\/pre>\n
5. Using Valet<\/h4>\n
<\/figure>\n
\n
\n
Install Valet<\/h5>\n
\r\ncomposer global require laravel\/valet\r\n<\/pre>\n
\r\nvalet install\r\n<\/pre>\n
Switching PHP Versions with Valet<\/h5>\n
valet use php@version<\/code> command. For example:<\/p>\n
\r\nvalet use php@8.2\r\n<\/pre>\n
.valetrc<\/code> file in your project\u2019s root directory with the line
php=php@8.2<\/code>. Then, simply run:<\/p>\n
\r\nvalet use\r\n<\/pre>\n
.valetrc<\/code> file.<\/p>\n
Wrapping Up<\/h4>\n