This is a laravel runtime for WSL using laravel-sail with a project-independent configuration directory.
- A running WSL machine with bash
- Docker Desktop is installed and started
- Your shell must have admin privileges to update the Windows host file
- Clone this repository anywhere to your WSL machine, except the
/mntdirectory. - Execute
install.shto add sourcing of this repositories.bashrcfile to your own~/.bashrc. - Validate that the command worked inspecting your
~/.bashrc. - (optional) Install php and composer dependencies on the WSL machine. This can be done with
install-prerequisites.sh, although this script might not be sufficient for all needs. - Start the docker-compose service in your runtime for automatic container discovery.
This should in general needed to be done only once.
cd my-runtime-path docker compose up -d
For each site you want to perform these steps to have the runtime set up properly.
- In the WSL machine, navigate to the directory of your project.
- Perform
composer installto fetch laravel-sail in your project.Since this is a standard dependency we want to use sail from the project rather than supplying one via the runtime.
- Navigate to you runtime installation to the
sitesdirectory. - Copy on the example directories to a new name that matches your project directory name.
For example:
cp -R example-8.3 my-new-project
- Open the docker-compose file in
my-new-project/docker-compose.ymland replace all occurrences of example with my-new-project. This should replace:- The sail build context
- The
VIRTUAL_HOSTenvironment variable value - The application volume mapping
- Done. Navigate to your project directory and perform
sail up -dto test if the project can start.
To automatically update the windows hosts file, perform following steps.
- Navigate to
C:\Windows\System32\drivers\etc. - Copy the
hostsfile tohosts_template. - Edit the
hosts_templatefile and append############################################ # Automatic docker hosts generated with # github.com/michiruf/LaravelRuntime ############################################ # update-hosts-file start # update-hosts-file end ############################################ - Done. The hosts file will get updated between
# update-hosts-file startand# update-hosts-file endwhenever a sail command is executed.
- Open the settings in PHPStorm
- Navigate to the main configuration for PHP
- In this window, find the setting for the CLI Interpreter
- Click on dot-menu to open the CLI Interpreter configuration dialog
- Click on the plus icon to add a new docker-compose interpreter
- Choose docker-compose
- Add a new server and select WSL from the radio select
- For the configuration file, navigate to your runtime installation path and find the
docker-compose.ymlin the sites folder for the project you are currently configuring - Select the service laravel-test and hit OK
- (recommended) Set the lifecycle to Connect to existing container
- Done. Tests should now be runnable in PHPStorm.
- Optional: use sail-php as php executable, to have it being run as sail user instead of root
- Configuring Windows Defender exclusion rules: microsoft/WSL#8995 (comment)
[!WARNING]
Might make your system vulnerable. Perform on your own risk!