Appearance
Work environment
WARNINGS
- You must have administrator rights to successfully install all these tools for your working environment!
- Follow the instructions below carefully/exactly! Different/deviant choices (version numbers, installation folders, ...) are at your own risk and are likely to cause problems!
1: laravel.bat
- Download laravel.bat (on your desktop)
- From this batch file you can easily perform the most frequently used actions for this course
- Switch between PHP 8.1 and PHP 7.4
- Start, stop, update, ... VirtualBox with the Homestead image
- Some other useful commands
- Double-click the file to run the script (This script must be run as administrator!)
- Type
smbaccount
to create a new admin account for the SMB share (username:vagrant
, password:homestead
)
This account is used later to access the Homestead share from your host machine - Type
0
to exit and close the file
Enhance security
Change the default password!
While the initial setup with username vagrant
and password homestead
is convenient for getting started quickly, personalizing your environment is an important step for enhancing security. Here's how to optimize your setup:
- Switch to 'vagrant' User: Sign out of your current user and log back in as
vagrant
- Login with Default Credentials: Use the pre-configured password
homestead
- Update Windows Password: Head over to your Windows Settings to change the password. If you're unsure how to do this, consult this Windows password guide
- Sync with Homestead.yaml: After changing your Windows password, remember to also update this password in your
Homestead.yaml
file - Restart Your Environment: For the changes to take effect, restart your Vagrant/Homestead environment. You can do this by running option 2 in
laravel.bat
By following these steps, you're not only personalizing your development environment but also aligning it with security best practices
2: 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
Windows Terminal with Git Bash
- Starting from Windows 10 version 1903, you can install the Windows Terminal
- If Windows Terminal is installed, you can add Git Bash to the list of available terminals by mark the checkbox Add the Git Bash profile to Windows terminal in the installation wizard
- Open a new terminal window ("Git Bash Here") and check your configuration
bash
$ git --version
git version 2.42.0.windows.1
$ git --version
git version 2.42.0.windows.1
1
2
2
- Install a recent LTS version (>= 18.x.x) of Node.js with the default installation settings
REMARKS
- Choose the default installation settings. As such, the "necessary tools" (including Chocolatey) don't need to be installed.
- 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 2022)
bash
$ node -v && npm -v
v18.17.1
9.6.7
$ node -v && npm -v
v18.17.1
9.6.7
1
2
3
2
3
3: PHP 8.1 and 7.4
- Download the ZIP-file with different PHP versions we prepared for you in advance
- Extract the zip-file in the root of your C-drive
C:\PHP\current
: contains current running version (empty by default)C:\PHP\PHP8.1
: contains a pre-configured version of PHP 8.1.xx (required for Laravel 9)C:\PHP\PHP74
: contains a pre-configured version of PHP 7.4.xx (required for Laravel 7)
- 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:\PHP\current
- Close the Omgevingsvariabelen (Environment Variables) panel entirely!
- Open laravel.bat en type
php81
to set PHP 8.1.xx as the default PHP version - Open a new terminal window and check your configuration
- On the desktop, create a new folder phptest containing a new file index.php with the following content
php
<?php
phpinfo();
<?php
phpinfo();
1
2
2
- Open a new terminal window inside the phptest folder and start PHP's local test server
bash
$ php -S localhost:8008
$ php -S localhost:8008
1
- Open http://localhost:8008 in a browser
KEEP PHP 8.1 UPDATED WITH LAST PATCH VERSION (OPTIONAL)
- Patches often contain vital fixes for bugs and fixes to recently discovered security vulnerabilities
- Download the latest version of PHP 8.1.xx for Windows (VC16 x64 Thread Safe)
- Replace the content of C:\PHP\PHP81 with the content of this zip-file
- Duplicate the file C:\PHP\PHP81\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 extensionsextension_dir = "ext"
extension=curl
extension=fileinfo
extension=gd
extension=mbstring
extension=odbc
extension=openssl
extension=pdo_mysql
extension=sockets
- Increase the memory limit (from 128M) to -1 (unlimited)
memory_limit = -1
- Open laravel.bat en type
php81
to run to the updated version
4: Composer
- Composer is a dependency manager for PHP
- Download and install Composer: https://getcomposer.org/Composer-Setup.exe
- Open a new terminal window and check your configuration
bash
$ composer -v
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.5.8 2023-06-09 17:13:21
$ composer -v
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.5.8 2023-06-09 17:13:21
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
TIP
You can update Composer with: $ composer self-update
5: 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
- Install the latest version of VirtualBox 7.0.xx
WARNING
- If you are using Windows, you may need to enable hardware virtualization (VT-x). It can usually be enabled via your BIOS (https://www.youtube.com/watch?v=mFJYpT7L5ag)
- If you are using Hyper-V on a UEFI system you may additionally need to disable Hyper-V in order to access VT-x.
- 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
- Install Vagrant (Amd64 version) and restart your laptop
- Install the vagrant-hostmanager and vagrant-vbguest plug-ins with the following command
bash
$ vagrant plugin install vagrant-hostmanager vagrant-vbguest
$ vagrant plugin install vagrant-hostmanager vagrant-vbguest
1
IMPORTANT
vagrant-hostupdater is a Vagrant plugin that automatically updates the C:\Windows\System32\drivers\etc\hosts
file when local domains (e.g. homestead.test
) are added or removed from the Vagrantfile.
To prevent certain background processes from disabling the added hosts, it is important that you adjust the security settings on the hosts file!
- Right click on
C:\Windows\System32\drivers\etc\hosts
and select Eigenschappen (Properties) - Click on the Beveiliging (Security) tab
- Click on Bewerken (Edit)
- Set Schrijven -> Weigeren (Write -> Deny) for the System Group to keep the the added hosts "alive"
- 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)
Generate SSH key
- Homestead requires an SSH key, so first check if the key exists
- Open the file explorer and go to
%UserProfile%\.ssh\id_rsa
orC:\Users\user_name\.ssh\id_rsa
- If this file exists, you don't need to do anything
- If this file does not exist, open Git Bash in a random location and generate an SSH key with the command
ssh-keygen
and click a few times onenter
At the end, you get to see a random image like the one below
bash$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Patrick/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Patrick/.ssh/id_rsa Your public key has been saved in /c/Users/Patrick/.ssh/id_rsa.pub The key fingerprint is: SHA256:fzbs72AhwtQWQzIuUQAqur4KLppnhksUbC7ndl00JHE Patrick@LAPTOP-VIBLNDPK The key's randomart image is: +---[RSA 3072]----+ | ..oo+.+ | |. . o + o | |.+. . E o o | |+.. o + . | |oo. . o S . . | |o+ . + . o o . | |ooo o o . B | |Bo+. . = o | |OO. .oo | +----[SHA256]-----+
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Patrick/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Patrick/.ssh/id_rsa Your public key has been saved in /c/Users/Patrick/.ssh/id_rsa.pub The key fingerprint is: SHA256:fzbs72AhwtQWQzIuUQAqur4KLppnhksUbC7ndl00JHE Patrick@LAPTOP-VIBLNDPK The key's randomart image is: +---[RSA 3072]----+ | ..oo+.+ | |. . o + o | |.+. . E o o | |+.. o + . | |oo. . o S . . | |o+ . + . o o . | |ooo o o . B | |Bo+. . = o | |OO. .oo | +----[SHA256]-----+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Install Homestead
- Open Git Bash in the C:\vagrant folder and execute the following commands
bash
$ git clone https://github.com/laravel/homestead.git
$ cd homestead
$ git checkout release
$ bash init.sh
$ vagrant up
$ git clone https://github.com/laravel/homestead.git
$ cd homestead
$ git checkout release
$ bash init.sh
$ vagrant up
1
2
3
4
5
2
3
4
5
REMARK
- Vagrant must first download the Homestead Virtualbox (1.7GB) and this may take several minutes so be patient and have a cup of coffee...
- IMPORTANT: is you get an error that Vagrant can't download the Laravel/homestead box, you probably have to install the Microsoft Visual C++ Redistributable Package (x64) first
- After the command
vagrant up
, give the necessary permissions to VirtualBox if asked for
- The Vagrant homestead box now appears inside VirtualBox
Configure Homestead
- In the C:\vagrant\homestead folder, open the Homestead.yaml file and REPLACE the content with the following code
yaml
---
ip: "192.168.56.56"
memory: 2048
cpus: 2
provider: virtualbox
backup: true
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: C:\sites_laravel
to: /home/vagrant/code
smb_username: vagrant
smb_password: homestead
mount_options: ["username=vagrant","password=homestead","vers=3.02", "mfsymlinks"]
sites:
- map: homestead.test
to: /home/vagrant/code
php: "8.1"
databases:
- homestead
features:
- mysql: true
- mariadb: false
- postgresql: false
- ohmyzsh: false
- webdriver: false
services:
- enabled:
- "mysql"
# - disabled:
# - "postgresql@11-main"
ports:
- send: 2200 # MySQL/MariaDB
to: 3306
- send: 8025 # Mailhog
to: 8025
# to: 4040
# - send: 54320 # PostgreSQL
# to: 5432
# - send: 9600
# to: 9600
# - send: 27017
# to: 27017
---
ip: "192.168.56.56"
memory: 2048
cpus: 2
provider: virtualbox
backup: true
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: C:\sites_laravel
to: /home/vagrant/code
smb_username: vagrant
smb_password: homestead
mount_options: ["username=vagrant","password=homestead","vers=3.02", "mfsymlinks"]
sites:
- map: homestead.test
to: /home/vagrant/code
php: "8.1"
databases:
- homestead
features:
- mysql: true
- mariadb: false
- postgresql: false
- ohmyzsh: false
- webdriver: false
services:
- enabled:
- "mysql"
# - disabled:
# - "postgresql@11-main"
ports:
- send: 2200 # MySQL/MariaDB
to: 3306
- send: 8025 # Mailhog
to: 8025
# to: 4040
# - send: 54320 # PostgreSQL
# to: 5432
# - send: 9600
# to: 9600
# - send: 27017
# to: 27017
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
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
EXPLANATION
- Line 6: Homestead automatically backups all your databases (listed under databases: on line 25) 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 16-18: we use SMB (Samba) to share the folder with the Vagrant box because this is the fastest way to share files between the host and the guest
- Line 22-23: homestead.test is now mapped to C:/sites_laravel and runs with PHP 8.1.x
- Line 41: make additional ports accessible outside the box
- Line 42-43: we use MySQL for all our databases
- Line 44-45: we use Mailhog as a local SMTP server
Remarks about the yaml file
- A YAML file is a YAML Ain't Markup Language file and is used to store configuration data
- YAML files are indented with spaces (not tabs)
- YAML files are case sensitive
- Indentation is also very important in YAML files, so make sure you indent the lines correctly
- TIP: type
validate
in laravel.bat to check if the formatting of the Homestead.yaml file is correct
- Some examples of a valid and invalid YAML file:
yaml
folders:
- map: C:\sites_laravel
to: /home/vagrant/code
smb_username: vagrant
smb_password: homestead
mount_options: ["username=vagrant","password=homestead","vers=3.02", "mfsymlinks"]
folders:
- map: C:\sites_laravel
to: /home/vagrant/code
smb_username: vagrant
smb_password: homestead
mount_options: ["username=vagrant","password=homestead","vers=3.02", "mfsymlinks"]
1
2
3
4
5
6
2
3
4
5
6
- In the C:\vagrant\homestead folder, open the Vagrantfile file and add
config.ssh.insert_key = false
insideVagrant.configure
bash
...
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.insert_key = false
if File.exist? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "/tmp/bash_aliases"
config.vm.provision "handle_aliases", type: "shell" do |s|
s.inline = "awk '{ sub(\"\r$\", \"\"); print }' /tmp/bash_aliases > /home/vagrant/.bash_aliases && chown vagrant:vagrant /home/vagrant/.bash_aliases"
end
end
...
end
...
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.insert_key = false
if File.exist? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "/tmp/bash_aliases"
config.vm.provision "handle_aliases", type: "shell" do |s|
s.inline = "awk '{ sub(\"\r$\", \"\"); print }' /tmp/bash_aliases > /home/vagrant/.bash_aliases && chown vagrant:vagrant /home/vagrant/.bash_aliases"
end
end
...
end
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
- Create inside the C:\sites_laravel folder a file index.php with the content
<?php echo phpinfo();
- Restart the server with option
2
from laravel.bat - Open http://homestead.test in a browser
TIP
- Sometimes VirtualBox is running slowly when Hyper-V is running
- You can disable/enable Hyper-V with the Hyper-V Switch application
6: PhpMyAdmin
phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the Web
- Download phpMyAdmin
- Unzip the file at the root of C:\sites_laravel and rename the folder to phpMyAdmin (C:\sites_laravel\phpMyAdmin)
- Open C:\vagrant\homestead\Homestead.yaml and add, under sites, a new path to phpMyAdmin
yaml
sites:
- map: homestead.test
to: /home/vagrant/code # change this line (remove /public)
php: "8.1" # run this site with PHP 8.1.x
- map: phpmyadmin.test
to: /home/vagrant/code/phpMyAdmin
php: "8.1"
sites:
- map: homestead.test
to: /home/vagrant/code # change this line (remove /public)
php: "8.1" # run this site with PHP 8.1.x
- map: phpmyadmin.test
to: /home/vagrant/code/phpMyAdmin
php: "8.1"
1
2
3
4
5
6
7
2
3
4
5
6
7
- Next, run option
2
from laravel.bat to restart the server - phpMyAdmin is also available at http://phpmyadmin.test
- Login with name homestead and password secret
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
php
$cfg['Servers'][$i]['auth_type'] = 'config'; // Change from 'cookie' to 'config'
$cfg['Servers'][$i]['user'] = 'homestead';
$cfg['Servers'][$i]['password'] = 'secret';
$cfg['CheckConfigurationPermissions'] = false;
$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
2
3
4
5
7: PhpStorm
- Ensure that you have an up-to-date version of PhpStorm on your machine
(Follow the installation guide on our Web Advanced course)