I've customized the original Laravel settler scripts (https://github.com/laravel/settler) for my own use. You can freely use these scripts to make your own Vagrant Box as well.
These scripts build Vagrant box for the customized Laravel Homestead development environment, which is lighter than the original one.
The features will include:
- Ubuntu 22.04LTS
- PHP
- 7.4
- 8.0
- 8.1 (default)
- 8.2
- MySQL
- ID: homestead
- PWD: secret
- Apache (installed but disabled)
- Nginx
- SQlite3
- MailHog
- Redis
- Memcached
- Supervisor
- Postfix
- Composer
- laravel/envoy
- laravel/installer
- NodeJS
- npm
- gulp-cli
- bower
- yarn
- grunt-cli
If you want the full features of Laravel Homestead, you probably don't want this repo. In that case, follow instructions at https://laravel.com/docs/homestead instead.
STOP: You can download this from https://app.vagrantup.com/nitekeeper/boxes/light-weight-homestead-vmware. You do not need to create it from scratch.
Even so, if you want to create your own box, follow the instructions below. These scripts are intended to work on Windows 11. You will need to install the followings first.
NOTE: Ensure that your Windows 11 is up-to-date.
- VMWare Workstation Pro: https://www.vmware.com/content/vmware/vmware-published-sites/us/products/workstation-pro.html.html
- VMWare Workstation Player: https://www.vmware.com/products/workstation-player.html
- I haven't checked this version, but you can try it.
- VMWare Fusion: https://www.vmware.com/products/fusion.html
- VirtualBox: https://www.virtualbox.org
If you are using VirtualBox as your choice of VM, replace vmware-iso.vm with virtualbox-iso.vm in the packer command below.
If you want to customize the packer command, follow the normal Packer practice. Since the original
Laravel Settler utilizes Chef/Bento source code as its base, I recommand you to check its repo as well: https://github.com/chef/bento
Open your PowerShell as administrator and type the following:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
git clone https://github.com/nitekeeper/laravel-settler-lite
cd laravel-settler-lite
git clone https://github.com/chef/bento
./bin/link-to-bento.ps1
cd bento
packer init -upgrade ./packer_templates
packer build -only="vmware-iso.vm" -var-file="os_pkrvars/ubuntu/ubuntu-22.04-x86_64.pkrvars.hcl" ./packer_templatesIt will take about 16 ~ 30 minutes to finish, depending on your network speed and your system specification.
You can find the created vagrant box in the bento > builds folder.
Rename the box as you wish and copy it to your safe folder.
Let's say:
- you named your custom box as
my-homestead.box. - you save your custom box in the following folder
D:\Boxes. - your project folder is
D:\Projects\Test.
NOTE: You can change the label my-custom-box in the vagrant box add command as you like.
cd D:\Boxes
vagrant box add my-custom-box my-homestead.box
cd D:\Projects\Test
vagrant init my-custom-box
vagrant up
vagrant sshIn the box:
laravel new example-site
cd example-site
ifconfigGet your private ip address from the result of the command ifconfig. The proper private IP address should look like 192.168.x.x.
Let's say your private IP address for this box is 192.168.217.156. Keep it some where safe and enter the following command in your terminal.
php artisan serve --host=0.0.0.0All done! Now, open your browser and type 192.168.217.156:8000.
VMWare, installed on Windows 11, has a problem with creating a symbolic link by npm on Ubuntu Guest OS.
In order to avoid this issue, install npm on Windows 11 and use it there, instead of using one installed
on Ubuntu Guest OS.
composer sometimes runs npm when installing libraries as well. In order to solve this issue, you can also install
composer on Windows 11 and use it there, instead of using one installed on your Ubuntu Guest OS. To install
composer on Windows 11, you will need PHP library files stored somewhere on your Windows Host system.
Please note that you do not need to install PHP. You just need its executable and extension files stored somewhere
on your Windows OS, so that you can bypass the package installation requirements of composer.
You can download PHP library files from https://windows.php.net/download.
- Download the zip file of the
Thread Safeversion, and - unzip it to somewhere in your system. When installing
composer, you will be asked to locate thephp.exefile. - Open
php.iniand uncomment the followings and save it. The following extensions are frequently used bycomposer.
;extension=zip
;extension=fileinfo
Just in case that you need other extensions to be enabled, you can simply uncomment them here as well. However, please
note that the PHP extensions on your Windows are not actually used by your PHP application on Ubuntu Guest OS.
Those are just needed to bypass the composer's package installation requirements.
In addition, you will encounter a problem when you are trying to create symbolic link between Laravel storage and Laravel public folder on Ubuntu Guest server. When you run VMWare on Windows 11, you need to create your symbolic link on your Windows Host system, not on your Ubuntu Guest system. The following instructions will help you to create the symbolic link, which you need.
- Run
cmdas administrator. - Use the command
mklinkin the following formatmklink /D absolute_target_folder absolute_source_folder. The following is an example for you.
mklink /D "D:\your\laravel\project\public\destination\folder" "D:\your\laravel\public\source\folder"
To change the PHP version, server type, xdebug setting, type the following commands.
select-phpWhen you configure xdebug with your client, refer to the setting values:
xdebug.mode = debug
xdebug.discover_client_host = true
xdebug.client_port = 9003
xdebug.max_nesting_level = 512
opcache.revalidate_freq = 0
If you want some convenience while using this box, you can add followings to your .bashrc file.
cd ~
nano .bashrcNOTE: If your shared directory on your virtual machine is not /vagrant, change the vagrant
shared folder address in the following vagrant alias setting.
# Git Branch Beautifier
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[\033[31m\]>\[\033[37m\]>\[\033[34m\]>\[\033[00m\] \[\033[32m\]\W\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
# Change the vagrant shared folder address according to your vagrant shared folder setting.
alias vagrant='cd /vagrant && clear && ls'
# Use the followings in your laravel project directory.
alias phpunit='./vendor/bin/phpunit'
alias artisan='php artisan'
alias serve='artisan serve --host=0.0.0.0'
vagrantThat's it! Happy coding!