DEV Community

David Carr
David Carr

Posted on • Originally published at dcblog.dev on

Using Laravel Sail alongside PhpStorm

Using Laravel Sail alongside PhpStorm

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.

Install Sail

Download Sail package

Use —dev to install into dev dependencies.


composer require laravel/sail --dev
Enter fullscreen mode Exit fullscreen mode

Install Sail


php artisan sail:install
Enter fullscreen mode Exit fullscreen mode

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.


./vendor/bin/sail up
Enter fullscreen mode Exit fullscreen mode

You may have to chase the DB_HOST in .env to mysql which is the host name created by sail.

Setup Testing

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”/> 
Enter fullscreen mode Exit fullscreen mode

MySQL Access

In order to connect to the database from outside the container the -d command may be needed mean to run detached


sail up -d 
Enter fullscreen mode Exit fullscreen mode

Then connect using:


host: 127.0.0.1
username: sail
password: password
Enter fullscreen mode Exit fullscreen mode

Configuring PHPStorm to use docker

Configure Test Runner

Open settings select PHP -> Test Frameworks

Click the plus and select the remote connection

Next select the sail container

Select docker

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
Enter fullscreen mode Exit fullscreen mode

This sits the container names the name you’re looking for is the name of the project followed by like dcblog_sail

Top comments (2)

Collapse
 
paulpreibisch profile image
Paul Preibisch

Thankyou for this!

Collapse
 
lloricode profile image
Lloric Mayuga Garcia

Hi, how about access db from sail using phpstorm data source?