Home  >  Article  >  PHP Framework  >  Teach you to use the version management tool in Homestead to switch PHP versions

Teach you to use the version management tool in Homestead to switch PHP versions

青灯夜游
青灯夜游forward
2021-12-22 19:33:583020browse

How to install and switch PHP version in Homestead? The following article will introduce to you how to switch PHP versions under Homestead. I hope it will be helpful to you!

Teach you to use the version management tool in Homestead to switch PHP versions

Switch PHP version under Homestead

Laravel’s Homestead comes with PHP5.6, PHP7.0, and PHP7.1 and PHP7.2 these 4 versions. By default it runs up to version 7.2, but sometimes company needs have to switch to another version.

How to switch?

Homestead comes with a way to switch versions, as follows:

sites:
    - map: homestead.test
      to: /home/vagrant/code/Laravel/public
      php: "5.6"

However, when you execute composer in homestead, or use php -v When checking the php version, the highest version is still 7.2. As a result, when composer performs a version check or updates the package, it will be updated according to version 7.2.

How to do it?

homestead comes with version management toolsupdate-alternatives

The usage is as follows:

update-alternatives --display php 查看所有 php 版本和当前版本
update-alternatives --config php 执行后,会列出当前 php 所有版本和编号,输入编号,切换到执行的版本

I didn’t notice that there is a file in the Homestead directory before aliases file, this file defines some commands that can be used directly in the virtual machine. For example, if you want to switch to version 7.0, just execute

php70

!

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of Teach you to use the version management tool in Homestead to switch PHP versions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete