Search code examples
phplaravelhomestead

Homestead 7 yaml php 5.6 still running 7.3


I cannot get my updated Homestead to work with php 5.6 for one of my projects. I destroyed my old machine and deleted the ~/Homestead folder, recloned it and checked out on v7.3.0. I'm also using the latest version of the laravel/homestead box. However, I still get a php version mismatch related error when running my php 5.6 project code. Dumping phpinfo gives me PHP Version 7.2.3-1+ubuntu16.04.1+deb.sury.org+1.

At this point I'm really stuck, why is my php 5.6 project still using php 7.2?

Below you can find my Homestead.yaml file, as well as the terminal output after bringing up the homestead-7 machine.

---
ip: "192.168.10.10"
memory: 3072
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/coding/php56project
      to: /home/vagrant/php56project
      php: "5.6"
    - map: ~/coding/php72project
      to: /home/vagrant/php72project

sites:
    - map: php56project.test
      to: /home/vagrant/php56project/public
    - map: php72project.test
      to: /home/vagrant/php72project/public

databases:
    - homestead
    - php56project
    - php72project

myself@mypc:~/Homestead$ homestead up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Importing base box 'laravel/homestead'...
==> homestead-7: Matching MAC address for NAT networking...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
==> homestead-7: Setting the name of the VM: homestead-7
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
    homestead-7: Adapter 1: nat
    homestead-7: Adapter 2: hostonly
==> homestead-7: Forwarding ports...
    homestead-7: 80 (guest) => 8000 (host) (adapter 1)
    homestead-7: 443 (guest) => 44300 (host) (adapter 1)
    homestead-7: 3306 (guest) => 33060 (host) (adapter 1)
    homestead-7: 4040 (guest) => 4040 (host) (adapter 1)
    homestead-7: 5432 (guest) => 54320 (host) (adapter 1)
    homestead-7: 8025 (guest) => 8025 (host) (adapter 1)
    homestead-7: 27017 (guest) => 27017 (host) (adapter 1)
    homestead-7: 22 (guest) => 2222 (host) (adapter 1)
==> homestead-7: Running 'pre-boot' VM customizations...
==> homestead-7: Booting VM...
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
    homestead-7: SSH address: 127.0.0.1:2222
    homestead-7: SSH username: vagrant
    homestead-7: SSH auth method: private key
    homestead-7: Warning: Connection reset. Retrying...
    homestead-7: 
    homestead-7: Vagrant insecure key detected. Vagrant will automatically replace
    homestead-7: this with a newly generated keypair for better security.
    homestead-7: 
    homestead-7: Inserting generated public key within guest...
    homestead-7: Removing insecure key from the guest if it's present...
    homestead-7: Key inserted! Disconnecting and reconnecting using new SSH key...
==> homestead-7: Machine booted and ready!
==> homestead-7: Checking for guest additions in VM...
    homestead-7: The guest additions on this VM do not match the installed version of
    homestead-7: VirtualBox! In most cases this is fine, but in rare cases it can
    homestead-7: prevent things such as shared folders from working properly. If you see
    homestead-7: shared folder errors, please make sure the guest additions within the
    homestead-7: virtual machine match the version of VirtualBox you have installed on
    homestead-7: your host and reload your VM.
    homestead-7: 
    homestead-7: Guest Additions Version: 5.0.18_Ubuntu r106667
    homestead-7: VirtualBox Version: 5.2
==> homestead-7: Setting hostname...
==> homestead-7: Configuring and enabling network interfaces...
==> homestead-7: Mounting shared folders...
    homestead-7: /vagrant => /home/myself/Homestead
    homestead-7: /home/vagrant/php72project => /home/myself/coding/php72project
    homestead-7: /home/vagrant/php56project => /home/myself/coding/php56project
==> homestead-7: Running provisioner: file...
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
    homestead-7: 
    homestead-7: ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmyemail@provider.com
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: /tmp/vagrant-shell20180406-3138-1u0i9xy.sh
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Certificate: php56project.test
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Site: php56project.test
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Checking for old Schedule
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Certificate: php72project.test
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Site: php72project.test
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: inline script
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Checking for old Schedule
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Clear Variables
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Restarting Cron
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Restarting Nginx
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating MySQL Database: homestead
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Postgres Database: homestead
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating MySQL Database: php56project
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Postgres Database: php56project
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating MySQL Database: php72project
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Creating Postgres Database: php72project
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: script: Update Composer
    homestead-7: You are running composer as "root", while "/home/vagrant/.composer" is owned by "vagrant"
    homestead-7: You are already using composer version 1.6.3 (stable channel).
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: /tmp/vagrant-shell20180406-3138-t73ng.sh
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: /tmp/vagrant-shell20180406-3138-1q4bwqp.sh

Solution

  • There is a difference between the PHP version running globally in your Vagrant VM and the PHP version that runs for each of your sites, which is controlled at the nginx level.

    During the creation process of your VM, Homestead configures custom nginx settings for each of your Laravel sites, using the script serve-laravel.sh:

    location ~ \.php$ {
        ...
        # After compilation e.g.: fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_pass unix:/var/run/php/php$5-fpm.sock; // e.g. $5 = '5.6'
        ...
    }
    

    In the example above, $5 is the variable which stores the php version your site will use. e.g. '7.1' or '5.6'.

    In your original example, if you were to view the nginx settings at /etc/nginx/sites-enabled/php56project.test you could confirm that php5.6-fpm.sock is being used.