Work environment

REMARKS

  • We choose to (continue to) teach Laravel 7 (and PHP 7) in academy year 2021-2022, because
    • new Laravel (and PHP) versions are released rather frequently and it is infeasible to update our course(s) every year
    • the basic concepts of the framework/language do not differ that much (between Laravel 7 and Laravel 8 and PHP 7 and PHP 8)
  • An updated course is foreseen for academy year 2022-2023 (after the release of the long-term-support version Laravel 9 in January 2022)

WARNINGS

0: PhpStorm

  • Ensure that you have an up-to-date version of PhpStorm on your machine

PhpStorm

  • Installation instructions
    • If you do not have a JetBrains account yet
      1. Make an account at https://www.jetbrains.com/. Use your Thomas More email address!
      2. You receive a mail with subject "Complete your account registration" to confirm your registration
      3. Go to https://www.jetbrains.com/student/ and click "Apply Now". Use your Thomas More email address (that you used for your registration).
      4. You receive a second mail "JetBrains Educational Pack Confirmation" to confirm your application for the educational pack
      5. You receive a third mail "JetBrains Student License Confirmation" to activate your student license. Now, you can install all software packages that are included in the educational pack/student license.
    • We recommend to install the Toolbox App, as it is a handy tool to manage and update all JetBrains software

1: Git Bash & Node.js

  • Ensure that Node.js, NPM and a terminal (we prefer Git Bash) are installed on your machine
  • Install the latest version of Git for Windows with the default installation settings
    • Open a new terminal window ("Git Bash Here") and check your configuration
$ git --version
git version 2.33.0.windows.2
1
2
  • Install a recent version (>= 14.x.x) of Node.js with the default installation settings

WARNING

If you also follow the Cordova course, you shouldn't install the current/latest Node.js version, but stick to version 14.x.x Node version with Cordova

REMARKS

  • Choose the default installation settings. As such, the "necessary tools" (including Chocolatey) don't need to be installed. Node installation setting
  • In the rapidly evolving IT landscape it might occur that the latest versions of Git, Node.js (and npm) differ from the ones we installed when we wrote/updated this course (september 2021)
  • Open a new terminal window and check your configuration
  • $ node -v && npm -v
    v16.9.1
    7.21.1
    
    1
    2
    3

    2: PHP 7.4.x

    Download PHP for Windows

    • Extract the zip-file in the root of your C-drive and rename the folder to: C:\PHP74
    • Open Omgevingsvariabelen van het systeem bewerken (Edit the system environment variables)
      • Click Omgevingsvariabelen... (Environment Variables...)
      • Choose under Systeemvariabelen (System variables) the variable Path, and click on Bewerken... (Edit...)
      • Click on Nieuw (New) and add C:\PHP74

    Install PHP

    • Close the Omgevingsvariabelen (Environment Variables) panel entirely!
    • Open a new terminal window and check your configuration
    $ php -v
    PHP 7.4.23 (cli) (built: Aug 25 2021 09:37:03) ( ZTS Visual C++ 2017 x64 )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    
    1
    2
    3
    4
    • Duplicate the file C:\PHP74\php.ini-development and rename the file to php.ini
    • Open php.ini in an editor and remove the ; (semicolon) in front of the most common extensions
      • extension_dir = "ext"
      • extension=curl
      • extension=fileinfo
      • extension=gd2
      • extension=mbstring
      • extension=odbc
      • extension=openssl
      • extension=pdo_mysql
      • extension=sockets
    • Increase the memory limit (from 128M) to -1 (unlimited)
      • memory_limit = -1
    • On the desktop, create a new folder phptest containing a new file index.php with the following content
    <?php
    phpinfo();
    
    1
    2
    • Open a new terminal window inside the phptest folder and start PHP's local test server
     $ php -S localhost:8008
    
    1

    phpinfo on test server

    3: Homestead

    • Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment
    • Homestead lets you run PHP, a web server, and other server software inside VirtualBox

    Install VirtualBox & Vagrant

    WARNINGS

    • Be sure to install version 6.1.24 of VirtualBox, because otherwise Homestead will not work!
      (At the time of writing, the latest version 6.1.26 contains a bug in conjunction with Vagrant)
      Virtualbox 6.1.24
    • Disable Check for Updates in VirtualBox's preferences
      Disable auto update
    • Open Omgevingsvariabelen van het systeem bewerken (Edit the system environment variables)
      • Click Omgevingsvariabelen... (Environment Variables...)
      • Click under Systeemvariabelen (System variables) on Nieuw... (New...)
        • Naam van de variabele (Variable name): VAGRANT_HOME
        • Waarde van de variabel (Variable value): C:\VagrantHome

    Vagrant system variable

    • Install Vagrant and restart your laptop
    • Create, at the root of your C-drive, two new folders
      • C:\vagrant (where you save the configuration files of the Vagrant box; the box itself will be stored in C:\VagrantHome\boxes)
      • C:\sites_laravel (where you store your websites)

    Install Homestead

    • Open Git Bash in the C:\vagrant folder and execute the following command
    $ vagrant box add laravel/homestead --box-version 9.7.2
    
    1

    WARNING

    Be sure to add version 9.7.2 of the Homestead Vagrant box, because other/newer boxes cause problems in combination with Laravel 7/PHP 7

    Choose VirtualBox

    • Choose option 3 (virtualbox) and wait for the box to be downloaded/added
    • Next, execute the following commands in the current Git Bash window
    $ git clone https://github.com/laravel/homestead.git homestead
    $ cd homestead
    $ git checkout 18.04
    $ bash init.sh
    $ vagrant up
    
    1
    2
    3
    4
    5

    WARNING

    Again, it is crucial to checkout branch 18.04 to avoid erratic behavior

    REMARK

    After the command vagrant up, give the necessary permissions to VirtualBox if asked for

    • The Vagrant homestead box now appears inside VirtualBox

    VirtualBox with Homestead

    • In the C:\vagrant\homestead folder, open the Homestead.yaml file and adjust the configuration (use a slash instead of a backslash!)





     







     


     
     

     






     





    ---
    ip: "192.168.10.10"
    memory: 2048
    cpus: 2
    provider: virtualbox
    backup: true                    # add this line
    
    authorize: ~/.ssh/id_rsa.pub
    
    keys:
        - ~/.ssh/id_rsa
    
    folders:
        - map: C:/sites_laravel     # change this line
          to: /home/vagrant/code
          
    # Don't forget to add all your .test domains to the host file C:\Windows\System32\drivers\etc\hosts
    # For example:     192.168.10.10   xxxxxx.test
    sites:
        - map: homestead.test
          to: /home/vagrant/code    # change this line (remove /public)
        
    databases:
        - homestead
        
    features:
        - mysql: true               # change from false to true
        - mariadb: false
        - postgresql: false
        - ohmyzsh: false
        - webdriver: false
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31

    REMARKS/EXPLANATION

    • Line 6: Homestead automatically backups all your databases (listed under databases: on line 23) when your Vagrant box is destroyed
      The backup files can be found in the folder C:\vagrant\homestead\.backup\mysql_backup
    • Line 14: the base folder for all your Laravel sites
    • Line 17-18: just a reminder that you don't forget to add every new test domain to the Windows hosts file 😉
    • Line 20: homestead.test is now mapped to C:/sites_laravel
    • Line 27: we use mysql for all our databases
    • Open (as administrator!) the file C:\Windows\System32\drivers\etc\hosts and add a new domain
      192.168.10.10 homestead.test
    • Create inside the C:\sites_laravel folder a file index.php with the content <?php echo phpinfo();
    • Restart the server
    vagrant halt
    vagrant up --provision
    
    1
    2

    PHP info

    COMMON ERROR MESSAGES AND SOLUTIONS

    • Check your Homestead.yaml (or Homestead.json) file, the path to your private key does not exist.
      • Go to %UserProfile% or C:\Users\user_name (in File Explorer) and open Git Bash
      • Execute the command mkdir -p .ssh && touch .ssh/id_rsa, which creates the folder C:\Users\user_name.ssh (if it does not exist) and creates an empty private key file in this folder
    • If the command vagrant up or vagrant up --provision hangs (and eventually times out) AND you have a port collision, it is advisable to stop the process causing this conflict
      • Use the netstat -a -b command or TCPView to check the active processes and their corresponding ports
      • In the example below, MySQL was running on port 3306. After stopping this service, the homestead server could be started without any problem.
        SSH and port conflict

    Homestead.bat

    • From this batch file you can easily perform the most frequently used actions
      • Create a new file homestead.bat (on your desktop)
      • Open the file and paste the code below
      • Double click the file to run the script
    @echo off
    title Vagrant - Homestead
    
    C:
    cd C:\vagrant\homestead
    :: uncomment (remove ::) the two lines below if the folder is on a different drive. e.g. D-drive
    :: D:
    :: cd D:\vagrant\homestead
    
    :home
    cls
    echo.
    echo Select a task:
    echo =============
    echo.
    echo 1) vagrant up               (Homestead.yaml hasn't been changed)
    echo 2) vagrant up --provision   (Homestead.yaml has changed)
    echo 3) vagrant halt             (shut down Homestead)
    echo 4) vagrant port             (list of guest ports mapped to the host machine ports)
    echo 5) vagrant destroy          (destroy Homestead and remove it from VirtualBox)
    echo 6) vagrant ssh              (type 'exit' or Ctrl+d to exit, default password: vagrant)
    echo 0) Exit
    echo.
    
    set /p action=Type option:
    
    if "%action%"=="1" goto up
    if "%action%"=="2" goto provision
    if "%action%"=="3" goto halt
    if "%action%"=="4" goto port
    if "%action%"=="5" goto confirmDestroy
    if "%action%"=="6" goto ssh
    if "%action%"=="0" exit
    goto home
    
    :up
    @echo on
    vagrant up
    @echo off
    pause
    goto home
    
    :provision
    @echo on
    vagrant halt & vagrant up --provision
    @echo off
    pause
    goto home
    
    :halt
    @echo on
    vagrant halt
    @echo off
    pause
    goto home
    
    :port
    @echo on
    vagrant port homestead
    @echo off
    pause
    goto home
    
    :confirmDestroy
    cls
    echo.
    echo This action destroys Homestead and remove it from VirtualBox!
    echo =============================================================
    echo.
    echo Before you execute this command, it is best to make a backup 
    echo of all your databases with phpMyAdmin.
    echo - http://homestead.test/phpMyAdmin
    echo - http://phpMyAdmin.test
    echo.
    set /P kill=Are you sure you want to destroy Homestead [Y/N]?
    if /I "%kill%"=="Y" ( goto destroy ) else ( goto home)
    
    :destroy
    @echo on
    vagrant up & vagrant destroy -f
    @echo off
    pause
    goto home
    
    :ssh
    @echo on
    vagrant ssh
    @echo off
    pause
    goto home
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90

    4: Composer

    $ composer -v
       ______
      / ____/___  ____ ___  ____  ____  ________  _____
     / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
    / /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
    \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                        /_/
    Composer version 2.1.8 2021-09-15 13:55:14
    
    1
    2
    3
    4
    5
    6
    7
    8

    5: PhpStorm plugin

    • Laravel support is provided by means of the Laravel plugin (and the Laravel IDE helper)
    • Open PhpStorm (you do not need any PHP/Laravel project at this time) and go to menu File -> Settings -> Plugins, or choose Plugins at the left of the splash welcome screen
    • Search for and install the Laravel plugin

    Laravel Plugins

    6: PhpMyAdmin

    • phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the Web

    Installation

    Download PhpMyAdmin

    • Unzip the file at the root of C:\sites_laravel and rename the folder to phpMyAdmin (C:\sites_laravel\phpMyAdmin)
    • phpMyAdmin is now available at http://homestead.test/phpMyAdmin/
    • Login with name homestead and password secret

    Set hostname

    • Open C:\vagrant\homestead\Homestead.yaml and add, under sites, a new path to phpMyAdmin



     
     

    sites:
        - map: homestead.test
          to: /home/vagrant/code
        - map: phpmyadmin.test
          to: /home/vagrant/code/phpMyAdmin
    
    1
    2
    3
    4
    5
    • Open the file C:\Windows\System32\drivers\etc\hosts (as administrator!) and add a new domain
      192.168.10.10 phpmyadmin.test
    • Next, execute the following commands in the current Git Bash window (or run option 2 from homestead.bat)
    $ vagrant halt
    $ vagrant up --provision
    
    1
    2

    Auto login

    • If you want, you can make sure that you are automatically logged in
    • Open the folder C:\sites_laravel\phpMyAdmin
    • Rename (or duplicate and rename) config.sample.inc.php to config.inc.php
    • Open config.inc.php
    • Find the variable $cfg['Servers'][$i]['auth_type'] and change the variable value from 'cookie' to 'config'
    • Add three extra lines of code
     

     
     
     

    $cfg['Servers'][$i]['auth_type'] = 'config';    // Change from 'cookie' to 'config'
    
    $cfg['Servers'][$i]['user'] = 'homestead';
    $cfg['Servers'][$i]['password'] = 'secret';
    $cfg['CheckConfigurationPermissions'] = false;
    
    1
    2
    3
    4
    5
    Last Updated: 9/18/2021, 6:31:59 AM