Toggle the PHP version in Homestead v13.2.1 (only for a project)
1. Execute the Composer Update in Homestead and report an error: Your requirements could not be resolved to an installable set of packages. The reason is that the PHP version is 8.0 , and the version of the package depends on 7. as shown in Figure 1
vagrant@homestead:~/Code/laravel-8-shop$ composer update
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires laravel/nova ^3.14 -> satisfiable by laravel/nova[v3.14.0].
- laravel/nova v3.14.0 requires php ^7.2.5 -> your php version (8.0.1) does not satisfy that requirement.
Problem 2
- Root composer.json requires laravel/ui 3.0 -> satisfiable by laravel/ui[v3.0.0].
- laravel/ui v3.0.0 requires php ^7.3 -> your php version (8.0.1) does not satisfy that requirement.
2. Reference:https://learnku.com/docs/laravel/5.8/homestead/3882#multiple-php-versions. Homestead 6 introduced support for multiple PHP versions on the same virtual machine. You can specify the PHP version for a given site in your homestead.yaml file.
sites:
- map: laravel-8-shop-homestead.test
to: /home/vagrant/Code/laravel-8-shop/public
php: "7.4"
3. After exiting vagrant, execute the command: cd ~/homestead && vagrant provision && vagrant up.
vagrant@homestead:~/Code/laravel-8-shop$ ls /etc/php
5.6 7.0 7.1 7.2 7.3 7.4 8.0
4. After re-entering, it is found that the shared folder is empty. as shown in Figure 2
5. Decide to restore the changes made in the second step. still empty. Doubt is related to opening NFS, decide to remove: type: “NFS”.
folders:
- map: E:/wwwroot/vagrant
to: /home/vagrant/Code
type: "nfs"
6. Restart and apply the virtual machine, execute the command: vagrant reload –provision
Lenovo@DESKTOP-QLPK8QM MINGW64 ~/Homestead (v12.1.0)
$ vagrant reload --provision
==> homestead: Attempting graceful shutdown of VM...
homestead: Guest communication could not be established! This is usually because
homestead: SSH is not running, the authentication information was changed,
homestead: or some other networking issue. Vagrant will force halt, if
homestead: capable.
==> homestead: Forcing shutdown of VM...
==> homestead: Checking if box 'lc/homestead' version '11.0.0' is up to date...
==> homestead: Clearing any previously set forwarded ports...
==> homestead: Clearing any previously set network interfaces...
==> homestead: Preparing network interfaces based on configuration...
homestead: Adapter 1: nat
homestead: Adapter 2: hostonly
==> homestead: Forwarding ports...
homestead: 80 (guest) => 8000 (host) (adapter 1)
homestead: 443 (guest) => 44300 (host) (adapter 1)
homestead: 3306 (guest) => 33060 (host) (adapter 1)
homestead: 4040 (guest) => 4040 (host) (adapter 1)
homestead: 5432 (guest) => 54320 (host) (adapter 1)
homestead: 8025 (guest) => 8025 (host) (adapter 1)
homestead: 9600 (guest) => 9600 (host) (adapter 1)
homestead: 27017 (guest) => 27017 (host) (adapter 1)
homestead: 22 (guest) => 2222 (host) (adapter 1)
==> homestead: Running 'pre-boot' VM customizations...
==> homestead: Booting VM...
==> homestead: Waiting for machine to boot. This may take a few minutes...
homestead: SSH address: 127.0.0.1:2222
homestead: SSH username: vagrant
homestead: SSH auth method: private key
homestead: Warning: Connection aborted. Retrying...
homestead: Warning: Connection reset. Retrying...
homestead:
homestead: Vagrant insecure key detected. Vagrant will automatically replace
homestead: this with a newly generated keypair for better security.
homestead:
homestead: Inserting generated public key within guest...
homestead: Removing insecure key from the guest if it's present...
homestead: Key inserted! Disconnecting and reconnecting using new SSH key...
==> homestead: Machine booted and ready!
==> homestead: Checking for guest additions in VM...
==> homestead: Setting hostname...
==> homestead: Configuring and enabling network interfaces...
==> homestead: Mounting shared folders...
homestead: /vagrant => C:/Users/Lenovo/Homestead
homestead: /home/vagrant/Code => E:/wwwroot/vagrant
==> homestead: Detected mount owner ID within mount options. (uid: 1000 guestpath: /home/vagrant/Code)
==> homestead: Detected mount group ID within mount options. (gid: 1000 guestpath: /home/vagrant/Code)
==> homestead: Running provisioner: file...
homestead: C:/Users/Lenovo/Homestead/aliases => /tmp/bash_aliases
==> homestead: Running provisioner: shell...
homestead: Running: inline script
==> homestead: Running provisioner: shell...
homestead: Running: inline script
homestead:
homestead: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDYbShMjEO5Jw9GNXNh7Nh7kqXtzuMRsj6EzOkaYY8u7niE/kd4M+YuVIuoImY2U1Huo1bQgsqIiHuyKobRLCFv/56W+rAD1d9wR2BNW1mjejwSLzKRVbr8HYnLpkqSJYom8UoZ4zkbuUz6wPvauCm/hKTLKYkCmWxt8LZjC7Y25JHAQflZFmhBI5jjcNQ4150yPobR+PmnJxrOmKDiAbLZVz5R+TfBF7cTO+KQbjDi4Ce1tzJM8u/ZTSMS6ESQN9FYMZUnhAqNS1STRex06l91Y+Tu496C/wC2CGWf1Ymqet6rmX8i0HnR/VEPa6ICTbsNfrbOGba98YVpnzJmGI4KFFiMc9DFwtkDR2th4+IdgBzW/FDGQFbzNll9jJR9bG2KfZpeUQiRC4BEgJxck4neXyEB5CdpR6X1Ej8jfyfynQrwrW4SPrgTwx+jMEiiG/8zhGigNqAWLyn0CUawlB4OHo8lLsiHCpq5WxWQkc42yPQD926FPFGxXxujVuWq2ps= wangqiang@fanxiapp.com
homestead:
==> homestead: Running provisioner: shell...
homestead: Running: inline script
==> homestead: Running provisioner: shell...
homestead: Running: inline script
==> homestead: Running provisioner: shell...
homestead: Running: inline script
==> homestead: Running provisioner: shell...
homestead: Running: inline script
==> homestead: Running provisioner: shell...
homestead: Running: inline script
homestead: Invalid feature: mysql
==> homestead: Running provisioner: shell...
homestead: Running: inline script
homestead: Ignoring feature: mariadb because it is set to false
==> homestead: Running provisioner: shell...
homestead: Running: inline script
homestead: Ignoring feature: postgresql because it is set to false
==> homestead: Running provisioner: shell...
homestead: Running: inline script
homestead: Ignoring feature: ohmyzsh because it is set to false
==> homestead: Running provisioner: shell...
homestead: Running: inline script
homestead: Ignoring feature: webdriver because it is set to false
==> homestead: Running provisioner: shell...
homestead: Running: C:/Users/Lenovo/AppData/Local/Temp/vagrant-shell20220829-23008-14upnya.sh
==> homestead: Running provisioner: shell...
homestead: Running: C:/Users/Lenovo/AppData/Local/Temp/vagrant-shell20220829-23008-1iuztyd.sh
==> homestead: Running provisioner: Creating Certificate: laravel-8-shop-homestead.test (shell)...
homestead: Running: script: Creating Certificate: laravel-8-shop-homestead.test
homestead: Updating certificates in /etc/ssl/certs...
homestead: rehash: warning: skipping duplicate certificate in ca.homestead.homestead.pem
homestead: 1 added, 0 removed; done.
homestead: Running hooks in /etc/ca-certificates/update.d...
homestead:
homestead: Adding debian:ca.homestead.homestead.pem
homestead: done.
homestead: done.
==> homestead: Running provisioner: Creating Site: laravel-8-shop-homestead.test (shell)...
homestead: Running: script: Creating Site: laravel-8-shop-homestead.test
==> homestead: Running provisioner: shell...
homestead: Running: inline script
==> homestead: Running provisioner: shell...
homestead: Running: C:/Users/Lenovo/AppData/Local/Temp/vagrant-shell20220829-23008-540zib.sh
==> homestead: Running provisioner: Checking for old Schedule (shell)...
homestead: Running: script: Checking for old Schedule
==> homestead: Running provisioner: Clear Variables (shell)...
homestead: Running: script: Clear Variables
==> homestead: Running provisioner: Restarting Cron (shell)...
homestead: Running: script: Restarting Cron
==> homestead: Running provisioner: Restart Webserver (shell)...
homestead: Running: script: Restart Webserver
==> homestead: Running provisioner: Creating MySQL / MariaDB Database: laravel-8-shop-homestead (shell)...
homestead: Running: script: Creating MySQL / MariaDB Database: laravel-8-shop-homestead
homestead: We didn't find a PID for mariadb, skipping $DB creation
==> homestead: Running provisioner: shell...
homestead: Running: C:/Users/Lenovo/AppData/Local/Temp/vagrant-shell20220829-23008-1q1lw98.sh
==> homestead: Running provisioner: Update motd (shell)...
homestead: Running: script: Update motd
==> homestead: Running provisioner: shell...
homestead: Running: C:/Users/Lenovo/AppData/Local/Temp/vagrant-shell20220829-23008-1006a48.sh
7. Check the current PHP version, the default is 8.0, then composer execution will still use 8.0, download composer.phar. Reference:https://getcomposer.org/download/. Enter the project root directory, copy the command and paste, and press Enter. as shown in Figure 3
vagrant@homestead:~/Code/laravel-8-shop$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ed'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
vagrant@homestead:~/Code/laravel-8-shop$ php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified
vagrant@homestead:~/Code/laravel-8-shop$ php composer-setup.php
All settings correct for using Composer
Downloading...
Composer (version 2.4.1) successfully installed to: /home/vagrant/Code/laravel-8-shop/composer.phar
Use it: php composer.phar
vagrant@homestead:~/Code/laravel-8-shop$ php -r "unlink('composer-setup.php');"
vagrant@homestead:~/Code/laravel-8-shop$ ls
app composer.lock package-lock.json routes webpack.mix.js
artisan composer.phar phpunit.xml server.php yarn.lock
auth.json config public storage
bootstrap database README.md tests
composer.json package.json resources vendor
vagrant@homestead:~/Code/laravel-8-shop$ ls -l
total 3762
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 app
-rwxrwxrwx 1 vagrant vagrant 1739 Aug 29 02:30 artisan
-rwxrwxrwx 1 vagrant vagrant 124 Aug 29 02:30 auth.json
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 bootstrap
-rwxrwxrwx 1 vagrant vagrant 2280 Aug 29 02:30 composer.json
-rwxrwxrwx 1 vagrant vagrant 392484 Aug 29 02:30 composer.lock
-rwxrwxrwx 1 vagrant vagrant 2799637 Aug 29 07:21 composer.phar
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 config
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 database
-rwxrwxrwx 1 vagrant vagrant 943 Aug 29 02:30 package.json
-rwxrwxrwx 1 vagrant vagrant 358262 Aug 29 02:30 package-lock.json
-rwxrwxrwx 1 vagrant vagrant 1233 Aug 29 02:30 phpunit.xml
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 public
-rwxrwxrwx 1 vagrant vagrant 4022 Aug 29 02:30 README.md
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 resources
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 routes
-rwxrwxrwx 1 vagrant vagrant 590 Aug 29 02:30 server.php
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 storage
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 tests
drwxrwxrwx 1 vagrant vagrant 8192 Aug 29 02:30 vendor
-rwxrwxrwx 1 vagrant vagrant 581 Aug 29 02:30 webpack.mix.js
-rwxrwxrwx 1 vagrant vagrant 271440 Aug 29 02:30 yarn.lock
vagrant@homestead:~/Code/laravel-8-shop$
8. Execution: php7.4 composer.phar update, no more errors are reported. as shown in Figure 4
vagrant@homestead:~/Code/laravel-8-shop$ php7.4 composer.phar update
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/nova
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-lang
Discovered Package: srmklive/paypal
Package manifest generated successfully.
86 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
No security vulnerability advisories found
vagrant@homestead:~/Code/laravel-8-shop$
9. The .env file is not automatically generated, manually copy the php artisan-related commands, and execute manually.
vagrant@homestead:~/Code/laravel-8-shop$ php7.4 -r "file_exists('.env') || copy('.env.example', '.env');"
vagrant@homestead:~/Code/laravel-8-shop$ ls -la
total 3763
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 07:57 .
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:29 ..
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 app
-rwxrwxrwx 1 vagrant vagrant 1739 Aug 29 02:30 artisan
-rwxrwxrwx 1 vagrant vagrant 124 Aug 29 02:30 auth.json
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 bootstrap
-rwxrwxrwx 1 vagrant vagrant 2202 Aug 29 07:51 composer.json
-rwxrwxrwx 1 vagrant vagrant 382659 Aug 29 07:27 composer.lock
-rwxrwxrwx 1 vagrant vagrant 2799637 Aug 29 07:21 composer.phar
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 config
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 database
-rwxrwxrwx 1 vagrant vagrant 276 Aug 29 02:30 .editorconfig
-rwxrwxrwx 1 vagrant vagrant 3381 Aug 29 07:57 .env
-rwxrwxrwx 1 vagrant vagrant 3381 Aug 29 02:30 .env.example
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 05:37 .git
-rwxrwxrwx 1 vagrant vagrant 162 Aug 29 02:30 .gitattributes
-rwxrwxrwx 1 vagrant vagrant 213 Aug 29 02:30 .gitignore
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 07:56 .idea
-rwxrwxrwx 1 vagrant vagrant 943 Aug 29 02:30 package.json
-rwxrwxrwx 1 vagrant vagrant 358262 Aug 29 02:30 package-lock.json
-rwxrwxrwx 1 vagrant vagrant 1233 Aug 29 02:30 phpunit.xml
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 public
-rwxrwxrwx 1 vagrant vagrant 4022 Aug 29 02:30 README.md
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 resources
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 routes
-rwxrwxrwx 1 vagrant vagrant 590 Aug 29 02:30 server.php
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 storage
-rwxrwxrwx 1 vagrant vagrant 208 Aug 29 02:30 .styleci.yml
drwxrwxrwx 1 vagrant vagrant 0 Aug 29 02:30 tests
drwxrwxrwx 1 vagrant vagrant 8192 Aug 29 07:27 vendor
-rwxrwxrwx 1 vagrant vagrant 581 Aug 29 02:30 webpack.mix.js
-rwxrwxrwx 1 vagrant vagrant 271440 Aug 29 02:30 yarn.lock
vagrant@homestead:~/Code/laravel-8-shop$
10. Visit the homepage, report an error, check the context, php version is 7.4.14. in line with expectations. as shown in Figure 5




