Using Laravel Sail alongside PhpStorm
Tags: laravel, docker, sail, phpstorm
Published: 2022-11-18 19:00:10

---
title: Using Laravel Sail alongside PhpStorm
published: true
date: 2022-11-12 01:29:00 UTC
tags: Laravel, Docker, Sail, PhpStorm
canonical_url: https://dcblog.dev/using-laravel-sail-alongside-phpstorm
---

 ![Using Laravel Sail alongside PhpStorm](https://dcblog.dev/images/posts/using-laravel-sail-alongside-phpstorm.png) 

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;

<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/Bbe_GzjEfG4" title="YouTube video player" width="560"></iframe>

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/](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
```

**Install Sail**

```

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.

```

./vendor/bin/sail up
```

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”/> 
```

## 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 
```

Then connect using:

```

host: 127.0.0.1
username: sail
password: password
```

 

## Configuring PHPStorm to use docker

Configure Test Runner

Open settings select PHP -> Test Frameworks

Click the plus and select the remote connection

![](https://dcblog.dev/assets/images/blog/development/sail/remote-inteperator.png)

Next select the sail container

![](https://dcblog.dev/assets/images/blog/development/sail/select-remote.png)

Select docker

![](https://dcblog.dev/assets/images/blog/development/sail/cli-interpreter.png)

Then select the sail image

![](https://dcblog.dev/assets/images/blog/development/sail/configure-remote.png)

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 

![](https://dcblog.dev/assets/images/blog/development/sail/test-config.png)

For the default interpreter select docker followed by the image.

You may need to configure docker to use the image name

![](https://dcblog.dev/assets/images/blog/development/sail/configure-docker.png) 

Enter the network name.

![](https://dcblog.dev/assets/images/blog/development/sail/bridge.png)

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