Skip to content

Instantly share code, notes, and snippets.

@huenisys
Last active March 10, 2020 03:18
Show Gist options
  • Save huenisys/ccd9898c18eee46fb5a2dfb50e1578a4 to your computer and use it in GitHub Desktop.
Save huenisys/ccd9898c18eee46fb5a2dfb50e1578a4 to your computer and use it in GitHub Desktop.
Working with Laravel on Windows

If you're a newcomer and needs to get started fast, with as little knowledge as possible, follow these steps.

  • Setup .editorconfig

  • Setup .gitignore_global

    /.idea
    /.vscode
    /.vagrant
    /auth.json
    
    # Editor directories and files
    .idea
    .vscode
    *.suo
    *.ntvs*
    *.njsproj
    *.sln
    *.sw*
    
    # python
    /.venv
    
    # php
    /vendor
    
    # node
    /node_modules
    
  • Install XAMPP (https://www.apachefriends.org/index.html). This saves you the hassle of installing PHP in your OS. Volume H.

  • Install Vagrant. Volume H.

    # install vagrant plugin for host manager
    vagrant plugin install vagrant-hostmanager
    # update the Nginx configuration on the virtual machine
    vagrant reload --provision
    # always do halt then up to make sure windows host is up-to-date
    vagrant halt
    vagrant up
    
  • Install Composer (https://getcomposer.org/doc/00-intro.md#using-the-installer). Use php.exe from XAMPP when asked for the executable.

  • Using Hyper-V Manager, create a Virtual switch for homestead (suggested name: Homestead-EXT). Make sure it's External type, using the physical network adapter.

  • Use Git for Windows and add these aliases

    alias v="vagrant"
    alias vs="vagrant ssh"
    
  • Use Homestead (https://laravel.com/docs/7.x/homestead) as your local VM for development.

    # go to H drive
    git clone https://github.com/laravel/homestead.git
    # run init.bat using powershell (admin) > cmd
    vagrant up
    
  • Share work folder using SMB for a Windows vagrant user, with password vagrant declared in your yaml.

    folders:
      - map: ~/code
        to: /home/vagrant/code
        smb_username: vagrant
        smb_password: vagrant
    
  • Start laravel projects.

    composer global require laravel/installer
    cd /g/projects
    laravel new laravel-project
    
  • Use as reference the below Homestead.yml

    ---
    ip: "192.168.10.10"
    # ip above gets ignored in hyperv
    memory: 2048
    cpus: 2
    provider: hyperv
    
    authorize: ~/.ssh/id_rsa.pub
    
    keys:
        - ~/.ssh/id_rsa
    
    folders:
        - map: G:\\projects
          to: /home/vagrant/projects
          smb_username: vagrant
          smb_password: vagrant
    
    sites:
        - map: homestead.test
          to: /home/vagrant/projects/laravel7/public
    
    databases:
        - homestead
    
    features:
        - mariadb: false
        - ohmyzsh: false
        - webdriver: false
    
    # ports:
    #     - send: 50000
    #       to: 5000
    #     - send: 7777
    #       to: 777
    #       protocol: udp
    
    

Suggested Lynda courses

Credit

https://dev.to/nicolus/getting-homestead-to-play-nice-with-hyper-v-4202

Add as alias in VM

function xphp() {
    (php -m | grep -q xdebug)
    if [[ $? -eq 0 ]]
    then
        XDEBUG_ENABLED=true
    else
        XDEBUG_ENABLED=false
    fi

    if ! $XDEBUG_ENABLED; then xon; fi

    #Find the IP of the latest ssh connection :
    HOST_IP=$(last --limit=1 | grep -oP '\d+(\.\d+){3}')

    php \
        -dxdebug.remote_host=${HOST_IP} \
        -dxdebug.remote_autostart=1 \
        "$@"

    if ! $XDEBUG_ENABLED; then xoff; fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment