skip to Main Content

I am trying to make a vagrant homestead server for Laravel 5.4.36. So that I can practice upgrading my main website to the latest laravel version locally.

The server starts up correctly, but I am expecting/need PHP version 7.0. Instead I get version 7.2.3 when I type “php –version” in the SSH terminal. The documentation says that homestead 5.2.0 SHOULD install PHP version 7.0, but it’s not. (https://laravel.com/docs/5.2/homestead)

Typing “php artisan –version” returns the expected 5.4.36 laravel version…

Thoughts on how I can fix this? Is it possible to downgrade php versions and specify 7.0?

Here is my Homestead.yaml file…

ip: 192.168.10.10
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
version: 5.2.0
keys:
    - ~/.ssh/id_rsa
folders:
    -
        map: 'C:UsersRickDesktopMyWebsite'
        to: /home/vagrant/code
sites:
    -
        map: mywebsite.test
        to: /home/vagrant/code/public
    -
        map: sub.mywebsite.test
        to: /home/vagrant/code/public
databases:
    - homestead
    - mywebsite
features:
    -
        mariadb: false
    -
        ohmyzsh: false
    -
        webdriver: false
name: mywebsite
hostname: www.mywebsite.test

2

Answers


  1. Homestead has several versions of PHP. If you view ~/.bash_aliases, you should see several lines like this:

    function php70() {
        sudo update-alternatives --set php /usr/bin/php7.0
        sudo update-alternatives --set php-config /usr/bin/php-config7.0
        sudo update-alternatives --set phpize /usr/bin/phpize7.0
    }
    
    function php71() {
        sudo update-alternatives --set php /usr/bin/php7.1
        sudo update-alternatives --set php-config /usr/bin/php-config7.1
        sudo update-alternatives --set phpize /usr/bin/phpize7.1
    }
    
    function php72() {
        sudo update-alternatives --set php /usr/bin/php7.2
        sudo update-alternatives --set php-config /usr/bin/php-config7.2
        sudo update-alternatives --set phpize /usr/bin/phpize7.2
    }
    
    function php73() {
        sudo update-alternatives --set php /usr/bin/php7.3
        sudo update-alternatives --set php-config /usr/bin/php-config7.3
        sudo update-alternatives --set phpize /usr/bin/phpize7.3
    }
    

    Type php70 on the command line, and it will switch the command-line versions.

    For the web versions, you’ll need to either update the nginx config file manually or add the PHP version to the mapping:

     map: mywebsite.test
     to: /home/vagrant/code/public
     php: "7.0"
    

    You’ll have to destroy the box and restart it to get it to reload the Homestead file.

    Login or Signup to reply.
  2. Using the latest Homestead, you may do the following:

    In your Homestead.yaml, you may specify a PHP version to each site.

      sites:
        -
            map: mywebsite.test
            to: /home/vagrant/code/public
            php: "7.1"
        -
            map: sub.mywebsite.test
            to: /home/vagrant/code/public
            php: "8.0"
    

    If that doesn’t work, you may also change the default version of PHP used by the CLI by issuing any of the following commands from within your Homestead virtual machine:

    php56
    php70
    php71
    php72
    php73
    php74
    php80
    

    Eg. Type php71 in your command line to change the Homestead PHP version to PHP 7.1

    This will change your Homestead environment according to the PHP version you specify.
    You may refer to the Official Documentation for more information.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search