I'm trying out Laravel Sail for my local development, this post serves as documenting the process and getting PhpStorm to play nice with Sail.
Sail is a tool for using docker without needing to use docker commands directly, it builds from an image that installs the latest versions of PHP, Nginx and MySQL.
watch a video version;
Sail is a Laravel package, which means you can use a fresh version of Laravel or install it in existing projects.
You will need docker to be installed, if you don't have docker you can download it at https://www.docker.com/
Note you still need PHP installed so you can run composer to install sail on existing projects.
Download Sail package
Use —dev to install into dev dependencies.
composer require laravel/sail --dev
php artisan sail:install
Select MySQL from the list of options
Start sail, the first time you run this it will take a while whilst all the files are downloaded, future calls are much quicker.
You may have to chase the DB_HOST in .env to mysql which is the host name created by sail.
Change phpunit.xml to use a testing database, sail created the database. This means every time a test runs a database named testing will be used.
<server name=“DB_DATABASE” value=“testing”/>
In order to connect to the database from outside the container the -d command may be needed mean to run detached
sail up -d
Then connect using:
host: 127.0.0.1 username: sail password: password
Configure Test Runner
Open settings select PHP -> Test Frameworks
Click the plus and select the remote connection
Next select the sail container
Then select the sail image
This will tell storm to use docker for CLI actions.
You may find that storm cannot run tests using its test runner, so let's configure it now.
Edit your test configuration
For the default interpreter select docker followed by the image.
You may need to configure docker to use the image name
Enter the network name.
Find the connection name in a terminal run
docker network ls
This sits the container names the name you’re looking for is the name of the project followed by like dcblog_sail