2017-04-14 10:43:26 +02:00
---
title: Guides
type: index
weight: 4
---
2017-05-01 21:00:32 +02:00
* [Production Setup on Digital Ocean ](#Digital-Ocean )
* [PHPStorm XDebug Setup ](#PHPStorm-Debugging )
2017-08-11 05:07:59 +02:00
* [Running Laravel Dusk Test ](#Laravel-Dusk )
2017-05-01 21:00:32 +02:00
< a name = "Digital-Ocean" > < / a >
2017-04-14 10:43:26 +02:00
# Production Setup on Digital Ocean
## Install Docker
- Visit [DigitalOcean ](https://cloud.digitalocean.com/login ) and login.
- Click the `Create Droplet` button.
- Open the `One-click apps` tab.
- Select Docker with your preferred version.
- Continue creating the droplet as you normally would.
- If needed, check your e-mail for the droplet root password.
## SSH to your Server
Find the IP address of the droplet in the DigitalOcean interface. Use it to connect to the server.
```
ssh root@ipaddress
```
You may be prompted for a password. Type the one you found within your e-mailbox. It'll then ask you to change the password.
You can now check if Docker is available:
```
$root@server:~# docker
```
## Set Up Your Laravel Project
```
$root@server:~# apt-get install git
$root@server:~# git clone https://github.com/laravel/laravel
$root@server:~# cd laravel
2017-04-20 19:55:09 +02:00
$root@server:~/laravel/ git submodule add https://github.com/Laradock/laradock.git
2017-04-14 10:43:26 +02:00
$root@server:~/laravel/ cd laradock
```
## Install docker-compose command
```
$root@server:~/laravel/laradock# curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose
$root@server:~/chmod +x /usr/local/bin/docker-compose
```
2017-05-13 19:51:19 +02:00
## Enter the laradock folder and rename env-example to .env.
```
$root@server:~/laravel/laradock# cp env-example .env
```
2017-04-14 10:43:26 +02:00
2017-04-20 19:55:09 +02:00
## Create Your Laradock Containers
2017-04-14 10:43:26 +02:00
```
$root@server:~/laravel/laradock# docker-compose up -d nginx mysql
```
Note that more containers are available, find them in the [docs ](http://laradock.io/introduction/#supported-software-containers ) or the `docker-compose.yml` file.
## Go to Your Workspace
```
docker-compose exec workspace bash
```
## Install and configure Laravel
Let's install Laravel's dependencies, add the `.env` file, generate the key and give proper permissions to the cache folder.
```
$ root@workspace:/var/www# composer install
$ root@workspace:/var/www# cp .env.example .env
$ root@workspace:/var/www# php artisan key:generate
$ root@workspace:/var/www# exit
$root@server:~/laravel/laradock# cd ..
$root@server:~/laravel# sudo chmod -R 777 storage bootstrap/cache
```
You can then view your Laravel site by visiting the IP address of your server in your browser. For example:
```
http://192.168.1.1
```
It should show you the Laravel default welcome page.
However, we want it to show up using your custom domain name, as well.
## Using Your Own Domain Name
Login to your DNS provider, such as Godaddy, Namecheap.
Point the Custom Domain Name Server to:
```
ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com
```
Within DigitalOcean, you'll need to change some settings, too.
2017-05-01 21:00:32 +02:00
Visit: https://cloud.digitalocean.com/networking/domains
2017-04-14 10:43:26 +02:00
Add your domain name and choose the server IP you'd provision earlier.
## Serving Site With NGINX (HTTP ONLY)
Go back to command line.
```
$root@server:~/laravel/laradock# cd nginx
$root@server:~/laravel/laradock/nginx# vim laravel.conf
```
Remove `default_server`
```
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
```
And add `server_name` (your custom domain)
```
listen 80;
listen [::]:80 ipv6only=on;
server_name yourdomain.com;
```
## Rebuild Your Nginx
```
2017-05-13 19:51:19 +02:00
$root@server:~/laravel/laradock# docker-compose down
$root@server:~/laravel/laradock# docker-compose build nginx
2017-04-14 10:43:26 +02:00
```
## Re Run Your Containers MYSQL and NGINX
```
$root@server:~/laravel/laradock/nginx# docker-compose up -d nginx mysql
```
2017-05-01 21:00:32 +02:00
**View Your Site with HTTP ONLY (http://yourdomain.com)**
2017-04-14 10:43:26 +02:00
## Run Site on SSL with Let's Encrypt Certificate
**Note: You need to Use Caddy here Instead of Nginx**
To go Caddy Folders and Edit CaddyFile
```
$root@server:~/laravel/laradock# cd caddy
$root@server:~/laravel/laradock/caddy# vim Caddyfile
```
Remove 0.0.0.0:80
```
0.0.0.0:80
2017-05-01 12:36:31 +02:00
root /var/www/public
2017-04-14 10:43:26 +02:00
```
2017-05-01 21:00:32 +02:00
and replace with your https://yourdomain.com
2017-04-14 10:43:26 +02:00
```
https://yourdomain.com
2017-05-01 12:36:31 +02:00
root /var/www/public
2017-04-14 10:43:26 +02:00
```
uncomment tls
```
#tls self-signed
```
and replace self-signed with your email address
```
tls serverbreaker@gmai.com
```
This is needed Prior to Creating Let's Encypt
## Run Your Caddy Container without the -d flag and Generate SSL with Let's Encrypt
```
$root@server:~/laravel/laradock/caddy# docker-compose up caddy
```
You'll be prompt here to enter your email... you may enter it or not
```
Attaching to laradock_mysql_1, laradock_caddy_1
caddy_1 | Activating privacy features...
caddy_1 | Your sites will be served over HTTPS automatically using Let's Encrypt.
caddy_1 | By continuing, you agree to the Let's Encrypt Subscriber Agreement at:
caddy_1 | https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf
caddy_1 | Activating privacy features... done.
caddy_1 | https://yourdomain.com
caddy_1 | http://yourdomain.com
```
After it finishes, press `Ctrl` + `C` to exit.
## Stop All Containers and ReRun Caddy and Other Containers on Background
```
$root@server:~/laravel/laradock/caddy# docker-compose down
$root@server:~/laravel/laradock/caddy# docker-compose up -d mysql caddy
```
2017-05-01 21:00:32 +02:00
View your Site in the Browser Securely Using HTTPS (https://yourdomain.com)
2017-04-14 10:43:26 +02:00
**Note that Certificate will be Automatically Renew By Caddy**
2017-05-01 21:00:32 +02:00
>References:
>
- [https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 ](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 )
- [https://www.digitalocean.com/products/one-click-apps/docker/ ](https://www.digitalocean.com/products/one-click-apps/docker/ )
- [https://docs.docker.com/engine/installation/linux/ubuntulinux/ ](https://docs.docker.com/engine/installation/linux/ubuntulinux/ )
- [https://docs.docker.com/compose/install/ ](https://docs.docker.com/compose/install/ )
- [https://caddyserver.com/docs/automatic-https ](https://caddyserver.com/docs/automatic-https )
- [https://caddyserver.com/docs/tls ](https://caddyserver.com/docs/tls )
- [https://caddyserver.com/docs/caddyfile ](https://caddyserver.com/docs/caddyfile )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
< br >
< br >
< br >
< br >
< br >
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
< a name = "PHPStorm-Debugging" > < / a >
2017-04-14 10:43:26 +02:00
# PHPStorm XDebug Setup
2016-11-18 21:12:10 +01:00
- [Intro ](#Intro )
- [Installation ](#Installation )
2017-05-01 21:00:32 +02:00
- [Customize laradock/docker-compose.yml ](#CustomizeDockerCompose )
- [Clean House ](#InstallCleanHouse )
- [Laradock Dial Tone ](#InstallLaradockDialTone )
- [hosts ](#AddToHosts )
- [Firewall ](#FireWall )
- [Enable xDebug on php-fpm ](#enablePhpXdebug )
- [PHPStorm Settings ](#InstallPHPStorm )
- [Configs ](#InstallPHPStormConfigs )
2016-11-18 21:12:10 +01:00
- [Usage ](#Usage )
2017-05-01 21:00:32 +02:00
- [Laravel ](#UsageLaravel )
- [Run ExampleTest ](#UsagePHPStormRunExampleTest )
- [Debug ExampleTest ](#UsagePHPStormDebugExampleTest )
- [Debug Web Site ](#UsagePHPStormDebugSite )
2017-04-14 10:43:26 +02:00
- [SSH into workspace ](#SSHintoWorkspace )
2017-05-01 21:00:32 +02:00
- [KiTTY ](#InstallKiTTY )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
< a name = "Intro" > < / a >
2016-11-18 21:12:10 +01:00
## Intro
2017-05-01 21:00:32 +02:00
Wiring up [Laravel ](https://laravel.com/ ), [Laradock ](https://github.com/Laradock/laradock ) [Laravel+Docker] and [PHPStorm ](https://www.jetbrains.com/phpstorm/ ) to play nice together complete with remote xdebug'ing as icing on top! Although this guide is based on `PHPStorm Windows` ,
you should be able to adjust accordingly. This guide was written based on Docker for Windows Native.
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "Installation" > < / a >
2016-11-18 21:12:10 +01:00
## Installation
- This guide assumes the following:
2017-05-01 21:00:32 +02:00
- you have already installed and are familiar with Laravel, Laradock and PHPStorm.
- you have installed Laravel as a parent of `laradock` . This guide assumes `/c/_dk/laravel` .
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "AddToHosts" > < / a >
2016-11-18 21:12:10 +01:00
## hosts
2017-05-01 21:00:32 +02:00
- Add `laravel` to your hosts file located on Windows 10 at `C:\Windows\System32\drivers\etc\hosts` . It should be set to the IP of your running container. Mine is: `10.0.75.2`
On Windows you can find it by opening Windows `Hyper-V Manager` .
- ![Windows Hyper-V Manager ](images/photos/PHPStorm/Settings/WindowsHyperVManager.png )
2017-04-14 10:43:26 +02:00
2016-11-18 21:12:10 +01:00
- [Hosts File Editor ](https://github.com/scottlerch/HostsFileEditor ) makes it easy to change your hosts file.
2017-05-01 21:00:32 +02:00
- Set `laravel` to your docker host IP. See [Example ](images/photos/SimpleHostsEditor/AddHost_laravel.png ).
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "FireWall" > < / a >
2016-11-18 21:12:10 +01:00
## Firewall
2017-05-01 21:00:32 +02:00
Your PHPStorm will need to be able to receive a connection from PHP xdebug either your running workspace or php-fpm containers on port 9000. This means that your Windows Firewall should either enable connections from the Application PHPStorm OR the port.
2016-11-18 21:12:10 +01:00
- It is important to note that if the Application PHPStorm is NOT enabled in the firewall, you will not be able to recreate a rule to override that.
- Also be aware that if you are installing/upgrade different versions of PHPStorm, you MAY have orphaned references to PHPStorm in your Firewall! You may decide to remove orphaned references however in either case, make sure that they are set to receive public TCP traffic.
### Edit laradock/docker-compose.yml
Set the following variables:
```
2017-04-14 10:43:26 +02:00
### Workspace Utilities Container ###############
2016-11-18 21:12:10 +01:00
workspace:
build:
context: ./workspace
args:
- INSTALL_XDEBUG=true
- INSTALL_WORKSPACE_SSH=true
...
2017-04-14 10:43:26 +02:00
### PHP-FPM Container #####################
2016-11-18 21:12:10 +01:00
php-fpm:
build:
context: ./php-fpm
args:
- INSTALL_XDEBUG=true
...
2017-05-01 21:00:32 +02:00
2016-11-18 21:12:10 +01:00
```
### Edit xdebug.ini files
- `laradock/workspace/xdebug.ini`
- `laradock/php-fpm/xdebug.ini`
Set the following variables:
2017-07-26 02:27:24 +02:00
2016-11-18 21:12:10 +01:00
```
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.cli_color=1
```
2017-05-01 21:00:32 +02:00
< a name = "InstallCleanHouse" > < / a >
2016-11-18 21:12:10 +01:00
### Need to clean house first?
2017-07-26 02:27:24 +02:00
2017-05-01 21:00:32 +02:00
Make sure you are starting with a clean state. For example, do you have other Laradock containers and images?
Here are a few things I use to clean things up.
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
- Delete all containers using `grep laradock_` on the names, see: [Remove all containers based on docker image name ](https://linuxconfig.org/remove-all-containners-based-on-docker-image-name ).
2017-07-26 02:27:24 +02:00
2017-05-01 21:00:32 +02:00
`docker ps -a | awk '{ print $1,$2 }' | grep laradock_ | awk '{print $1}' | xargs -I {} docker rm {}`
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
- Delete all images containing `laradock` .
2017-07-26 02:27:24 +02:00
2017-05-01 21:00:32 +02:00
`docker images | awk '{print $1,$2,$3}' | grep laradock_ | awk '{print $3}' | xargs -I {} docker rmi {}`
**Note:** This will only delete images that were built with `Laradock` , **NOT** `laradock/*` which are pulled down by `Laradock` such as `laradock/workspace` , etc.
**Note:** Some may fail with:
`Error response from daemon: conflict: unable to delete 3f38eaed93df (cannot be forced) - image has dependent child images`
2016-11-18 21:12:10 +01:00
- I added this to my `.bashrc` to remove orphaned images.
2017-07-26 02:27:24 +02:00
```
dclean() {
processes=`docker ps -q -f status=exited`
2017-12-11 01:01:15 +01:00
if [ -n "$processes" ]; then
2017-07-26 02:27:24 +02:00
docker rm $processes
fi
images=`docker images -q -f dangling=true`
if [ -n "$images" ]; then
docker rmi $images
fi
}
```
2016-11-18 21:12:10 +01:00
2017-04-20 19:55:09 +02:00
- If you frequently switch configurations for Laradock, you may find that adding the following and added to your `.bashrc` or equivalent useful:
2017-07-26 02:27:24 +02:00
2017-05-01 21:00:32 +02:00
```
# remove laravel* containers
# remove laravel_* images
dcleanlaradockfunction()
{
echo 'Removing ALL containers associated with laradock'
docker ps -a | awk '{ print $1,$2 }' | grep laradock | awk '{print $1}' | xargs -I {} docker rm {}
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
# remove ALL images associated with laradock_
# does NOT delete laradock/* which are hub images
echo 'Removing ALL images associated with laradock_'
docker images | awk '{print $1,$2,$3}' | grep laradock_ | awk '{print $3}' | xargs -I {} docker rmi {}
2017-05-01 12:36:31 +02:00
2017-05-01 21:00:32 +02:00
echo 'Listing all laradock docker hub images...'
docker images | grep laradock
2017-05-01 12:36:31 +02:00
2017-05-01 21:00:32 +02:00
echo 'dcleanlaradock completed'
}
# associate the above function with an alias
# so can recall/lookup by typing 'alias'
alias dcleanlaradock=dcleanlaradockfunction
```
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "InstallLaradockDialTone" > < / a >
2017-04-14 10:43:26 +02:00
## Let's get a dial-tone with Laravel
2016-11-18 21:12:10 +01:00
```
# barebones at this point
docker-compose up -d nginx mysql
2017-04-14 10:43:26 +02:00
# run
2016-11-18 21:12:10 +01:00
docker-compose ps
# Should see:
Name Command State Ports
-----------------------------------------------------------------------------------------------------------
laradock_mysql_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp
laradock_nginx_1 nginx Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
laradock_php-fpm_1 php-fpm Up 9000/tcp
laradock_volumes_data_1 true Exit 0
laradock_volumes_source_1 true Exit 0
laradock_workspace_1 /sbin/my_init Up 0.0.0.0:2222->22/tcp
2017-05-01 21:00:32 +02:00
```
2017-05-01 12:36:31 +02:00
2017-05-01 21:00:32 +02:00
< a name = "enablePhpXdebug" > < / a >
## Enable xDebug on php-fpm
2017-07-26 02:27:24 +02:00
2017-05-01 21:00:32 +02:00
In a host terminal sitting in the laradock folder, run: `.php-fpm/xdebug status`
You should see something like the following:
2017-07-26 02:27:24 +02:00
2016-11-18 21:12:10 +01:00
```
xDebug status
laradock_php-fpm_1
PHP 7.0.9 (cli) (built: Aug 10 2016 19:45:48) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
```
2017-07-26 02:27:24 +02:00
2017-04-20 19:55:09 +02:00
Other commands include `.php-fpm/xdebug start | stop` .
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
If you have enabled `xdebug=true` in `docker-compose.yml/php-fpm` , `xdebug` will already be running when
`php-fpm` is started and listening for debug info on port 9000.
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "InstallPHPStormConfigs" > < / a >
2017-04-14 10:43:26 +02:00
## PHPStorm Settings
2017-07-26 02:27:24 +02:00
2016-11-18 21:12:10 +01:00
- Here are some settings that are known to work:
2017-05-01 21:00:32 +02:00
- `Settings/BuildDeploymentConnection`
- ![Settings/BuildDeploymentConnection ](/images/photos/PHPStorm/Settings/BuildDeploymentConnection.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/BuildDeploymentConnectionMappings`
- ![Settings/BuildDeploymentConnectionMappings ](/images/photos/PHPStorm/Settings/BuildDeploymentConnectionMappings.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/BuildDeploymentDebugger`
- ![Settings/BuildDeploymentDebugger ](/images/photos/PHPStorm/Settings/BuildDeploymentDebugger.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/EditRunConfigurationRemoteWebDebug`
- ![Settings/EditRunConfigurationRemoteWebDebug ](/images/photos/PHPStorm/Settings/EditRunConfigurationRemoteWebDebug.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/EditRunConfigurationRemoteExampleTestDebug`
- ![Settings/EditRunConfigurationRemoteExampleTestDebug ](/images/photos/PHPStorm/Settings/EditRunConfigurationRemoteExampleTestDebug.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/LangsPHPDebug`
- ![Settings/LangsPHPDebug ](/images/photos/PHPStorm/Settings/LangsPHPDebug.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/LangsPHPInterpreters`
- ![Settings/LangsPHPInterpreters ](/images/photos/PHPStorm/Settings/LangsPHPInterpreters.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/LangsPHPPHPUnit`
- ![Settings/LangsPHPPHPUnit ](/images/photos/PHPStorm/Settings/LangsPHPPHPUnit.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `Settings/LangsPHPServers`
- ![Settings/LangsPHPServers ](/images/photos/PHPStorm/Settings/LangsPHPServers.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `RemoteHost`
To switch on this view, go to: `Menu/Tools/Deployment/Browse Remote Host` .
- ![RemoteHost ](/images/photos/PHPStorm/RemoteHost.png )
2017-04-14 10:43:26 +02:00
2017-05-01 21:00:32 +02:00
- `RemoteWebDebug`
- ![DebugRemoteOn ](/images/photos/PHPStorm/DebugRemoteOn.png )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
- `EditRunConfigurationRemoteWebDebug`
Go to: `Menu/Run/Edit Configurations` .
- ![EditRunConfigurationRemoteWebDebug ](/images/photos/PHPStorm/Settings/EditRunConfigurationRemoteWebDebug.png )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
- `EditRunConfigurationRemoteExampleTestDebug`
Go to: `Menu/Run/Edit Configurations` .
- ![EditRunConfigurationRemoteExampleTestDebug ](/images/photos/PHPStorm/Settings/EditRunConfigurationRemoteExampleTestDebug.png )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
- `WindowsFirewallAllowedApps`
Go to: `Control Panel\All Control Panel Items\Windows Firewall\Allowed apps` .
- ![WindowsFirewallAllowedApps.png ](/images/photos/PHPStorm/Settings/WindowsFirewallAllowedApps.png )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
- `hosts`
Edit: `C:\Windows\System32\drivers\etc\hosts` .
- ![WindowsFirewallAllowedApps.png ](/images/photos/PHPStorm/Settings/hosts.png )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
- [Enable xDebug on php-fpm ](#enablePhpXdebug )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "Usage" > < / a >
2016-11-18 21:12:10 +01:00
## Usage
2017-05-01 21:00:32 +02:00
< a name = "UsagePHPStormRunExampleTest" > < / a >
2016-11-18 21:12:10 +01:00
### Run ExampleTest
- right-click on `tests/ExampleTest.php`
2017-05-01 21:00:32 +02:00
- Select: `Run 'ExampleTest.php'` or `Ctrl+Shift+F10` .
- Should pass!! You just ran a remote test via SSH!
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "UsagePHPStormDebugExampleTest" > < / a >
2016-11-18 21:12:10 +01:00
### Debug ExampleTest
- Open to edit: `tests/ExampleTest.php`
- Add a BreakPoint on line 16: `$this->visit('/')`
- right-click on `tests/ExampleTest.php`
2017-05-01 21:00:32 +02:00
- Select: `Debug 'ExampleTest.php'` .
- Should have stopped at the BreakPoint!! You are now debugging locally against a remote Laravel project via SSH!
- ![Remote Test Debugging Success ](/images/photos/PHPStorm/RemoteTestDebuggingSuccess.png )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "UsagePHPStormDebugSite" > < / a >
2016-11-18 21:12:10 +01:00
### Debug WebSite
2017-05-01 21:00:32 +02:00
- In case xDebug is disabled, from the `laradock` folder run:
`.php-fpm/xdebug start` .
- To switch xdebug off, run:
`.php-fpm/xdebug stop`
2017-04-14 10:43:26 +02:00
2016-11-18 21:12:10 +01:00
- Start Remote Debugging
2017-05-01 21:00:32 +02:00
- ![DebugRemoteOn ](/images/photos/PHPStorm/DebugRemoteOn.png )
2017-04-14 10:43:26 +02:00
2016-11-18 21:12:10 +01:00
- Open to edit: `bootstrap/app.php`
- Add a BreakPoint on line 14: `$app = new Illuminate\Foundation\Application(`
- Reload [Laravel Site ](http://laravel/ )
2017-05-01 21:00:32 +02:00
- Should have stopped at the BreakPoint!! You are now debugging locally against a remote Laravel project via SSH!
- ![Remote Debugging Success ](/images/photos/PHPStorm/RemoteDebuggingSuccess.png )
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "SSHintoWorkspace" > < / a >
2017-04-14 10:43:26 +02:00
## Let's shell into workspace
2017-05-01 21:00:32 +02:00
Assuming that you are in laradock folder, type:
`ssh -i workspace/insecure_id_rsa -p2222 root@laravel`
**Cha Ching!!!!**
2016-11-18 21:12:10 +01:00
- `workspace/insecure_id_rsa.ppk` may become corrupted. In which case:
2017-05-01 21:00:32 +02:00
- fire up `puttygen`
- import `workspace/insecure_id_rsa`
- save private key to `workspace/insecure_id_rsa.ppk`
2016-11-18 21:12:10 +01:00
2017-05-01 21:00:32 +02:00
< a name = "InstallKiTTY" > < / a >
2016-11-18 21:12:10 +01:00
2017-04-14 10:43:26 +02:00
### KiTTY
2016-11-18 21:12:10 +01:00
[Kitty ](http://www.9bis.net/kitty/ ) KiTTY is a fork from version 0.67 of PuTTY.
- Here are some settings that are working for me:
2017-05-01 21:00:32 +02:00
- ![Session ](/images/photos/KiTTY/Session.png )
- ![Terminal ](/images/photos/KiTTY/Terminal.png )
- ![Window ](/images/photos/KiTTY/Window.png )
- ![WindowAppearance ](/images/photos/KiTTY/WindowAppearance.png )
- ![Connection ](/images/photos/KiTTY/Connection.png )
- ![ConnectionData ](/images/photos/KiTTY/ConnectionData.png )
- ![ConnectionSSH ](/images/photos/KiTTY/ConnectionSSH.png )
- ![ConnectionSSHAuth ](/images/photos/KiTTY/ConnectionSSHAuth.png )
- ![TerminalShell ](/images/photos/KiTTY/TerminalShell.png )
2017-08-11 05:07:59 +02:00
< br >
< br >
< br >
< br >
< br >
< a name = "Laravel-Dusk" > < / a >
# Running Laravel Dusk Tests
2017-10-06 10:13:33 +02:00
- [Option 1: Without Selenium ](#option1-dusk )
- [Option 2: With Selenium ](#option2-dusk )
< a name = "option1-dusk" > < / a >
## Option 1: Without Selenium
- [Intro ](#option1-dusk-intro )
- [Workspace Setup ](#option1-workspace-setup )
- [Application Setup ](#option1-application-setup )
- [Choose Chrome Driver Version (Optional) ](#option1-choose-chrome-driver-version )
- [Run Dusk Tests ](#option1-run-dusk-tests )
< a name = "option1-dusk-intro" > < / a >
### Intro
This is a guide to run Dusk tests in your `workspace` container with headless
google-chrome and chromedriver. It has been tested with Laravel 5.4 and 5.5.
< a name = "option1-workspace-setup" > < / a >
### Workspace Setup
Update your .env with following entries:
```
...
# Install Laravel installer bin to setup demo app
WORKSPACE_INSTALL_LARAVEL_INSTALLER=true
...
# Install all the necessary dependencies for running Dusk tests
WORKSPACE_INSTALL_DUSK_DEPS=true
...
```
Then run below to build your workspace.
```
docker-compose build workspace
```
< a name = "option1-application-setup" > < / a >
### Application Setup
Run a `workspace` container and you will be inside the container at `/var/www` directory.
```
docker-compose run workspace bash
/var/www#> _
```
Create new Laravel application named `dusk-test` and install Laravel Dusk package.
```
/var/www> laravel new dusk-test
/var/www> cd dusk-test
/var/www/dusk-test> composer require --dev laravel/dusk
/var/www/dusk-test> php artisan dusk:install
```
Create `.env.dusk.local` by copying from `.env` file.
```
/var/www/dusk-test> cp .env .env.dusk.local
```
Update the `APP_URL` entry in `.env.dusk.local` to local Laravel server.
```
APP_URL=http://localhost:8000
```
You will need to run chromedriver with `headless` and `no-sandbox` flag. In Laravel Dusk 2.x it is
already set `headless` so you just need to add `no-sandbox` flag. If you on previous version 1.x,
you will need to update your `DustTestCase#driver` as shown below.
```
< ?php
...
abstract class DuskTestCase extends BaseTestCase
{
...
/**
* Update chrome driver with below flags
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--no-sandbox'
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
}
```
< a name = "option1-choose-chrome-driver-version" > < / a >
### Choose Chrome Driver Version (Optional)
You could choose to use either:
1. Chrome Driver shipped with Laravel Dusk. (Default)
2. Chrome Driver installed in `workspace` container. (Required tweak on DuskTestCase class)
For Laravel 2.x, you need to update `DuskTestCase#prepare` method if you wish to go with option #2 .
```
< ?php
...
abstract class DuskTestCase extends BaseTestCase
{
...
public static function prepare()
{
// Only add this line if you wish to use chrome driver installed in workspace container.
// You might want to read the file path from env file.
static::useChromedriver('/usr/local/bin/chromedriver');
static::startChromeDriver();
}
```
For Laravel 1.x, you need to add `DuskTestCase#buildChromeProcess` method if you wish to go with option #2 .
```
< ?php
...
use Symfony\Component\Process\ProcessBuilder;
abstract class DuskTestCase extends BaseTestCase
{
...
/**
* Only add this method if you wish to use chrome driver installed in workspace container
*/
protected static function buildChromeProcess()
{
return (new ProcessBuilder())
->setPrefix('chromedriver')
->getProcess()
->setEnv(static::chromeEnvironment());
}
...
}
```
< a name = "option1-run-dusk-tests" > < / a >
### Run Dusk Tests
Run local server in `workspace` container and run Dusk tests.
```
# alias to run Laravel server in the background (php artisan serve --quiet &)
/var/www/dusk-test> serve
# alias to run Dusk tests (php artisan dusk)
/var/www/dusk-test> dusk
PHPUnit 6.4.0 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 837 ms, Memory: 6.00MB
```
< a name = "option2-dusk" > < / a >
## Option 2: With Selenium
2017-08-11 05:07:59 +02:00
- [Intro ](#dusk-intro )
- [DNS Setup ](#dns-setup )
- [Docker Compose Setup ](#docker-compose )
- [Laravel Dusk Setup ](#laravel-dusk-setup )
- [Running Laravel Dusk Tests ](#running-tests )
< a name = "dusk-intro" > < / a >
2017-10-06 10:13:33 +02:00
### Intro
2017-08-11 05:07:59 +02:00
Setting up Laravel Dusk tests to run with Laradock appears be something that
eludes most Laradock users. This guide is designed to show you how to wire them
up to work together. This guide is written with macOS and Linux in mind. As such,
it's only been tested on macOS. Feel free to create pull requests to update the guide
for Windows-specific instructions.
This guide assumes you know how to use a DNS forwarder such as `dnsmasq` or are comfortable
with editing the `/etc/hosts` file for one-off DNS changes.
< a name = "dns-setup" > < / a >
2017-10-06 10:13:33 +02:00
### DNS Setup
2017-08-11 05:07:59 +02:00
According to RFC-2606, only four TLDs are reserved for local testing[^1]:
- `.test`
- `.example`
- `.invalid`
- `.localhost`
A common TLD used for local development is `.dev` , but newer versions of Google
Chrome (such as the one bundled with the Selenium Docker image), will fail to
resolve that DNS as there will appear to be a name collision.
The recommended extension is `.test` for your Laravel web apps because you're
running tests. Using a DNS forwarder such as `dnsmasq` or by editing the `/etc/hosts`
file, configure the host to point to `localhost` .
For example, in your `/etc/hosts` file:
```
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 myapp.test
```
This will ensure that when navigating to `myapp.test` , it will route the
request to `127.0.0.1` which will be handled by Nginx in Laradock.
< a name = "docker-compose" > < / a >
2017-10-06 10:13:33 +02:00
### Docker Compose setup
2017-08-11 05:07:59 +02:00
In order to make the Selenium container talk to the Nginx container appropriately,
the `docker-compose.yml` needs to be edited to accommodate this. Make the following
changes:
```yaml
...
selenium:
...
depends_on:
- nginx
links:
- nginx:< your_domain >
```
This allows network communication between the Nginx and Selenium containers
and it also ensures that when starting the Selenium container, the Nginx
container starts up first unless it's already running. This allows
the Selenium container to make requests to the Nginx container, which is
necessary for running Dusk tests. These changes also link the `nginx` environment
variable to the domain you wired up in your hosts file.
< a name = "laravel-dusk-setup" > < / a >
2017-10-06 10:13:33 +02:00
### Laravel Dusk Setup
2017-08-11 05:07:59 +02:00
In order to make Laravel Dusk make the proper request to the Selenium container,
you have to edit the `DuskTestCase.php` file that's provided on the initial
installation of Laravel Dusk. The change you have to make deals with the URL the
Remote Web Driver attempts to use to set up the Selenium session.
One recommendation for this is to add a separate config option in your `.env.dusk.local`
so it's still possible to run your Dusk tests locally should you want to.
2017-10-06 10:13:33 +02:00
#### .env.dusk.local
2017-08-11 05:07:59 +02:00
```
...
USE_SELENIUM=true
```
2017-10-06 10:13:33 +02:00
#### DuskTestCase.php
2017-08-11 05:07:59 +02:00
```php
abstract class DuskTestCase extends BaseTestCase
{
...
protected function driver()
{
if (env('USE_SELENIUM', 'false') == 'true') {
return RemoteWebDriver::create(
'http://selenium:4444/wd/hub', DesiredCapabilities::chrome()
);
} else {
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()
);
}
}
}
```
< a name = "running-tests" > < / a >
2017-10-06 10:13:33 +02:00
### Running Laravel Dusk Tests
2017-08-11 05:07:59 +02:00
Now that you have everything set up, to run your Dusk tests, you have to SSH
into the workspace container as you normally would:
```docker-compose exec --user=laradock workspace bash```
Once inside, you can change directory to your application and run:
```php artisan dusk```
One way to make this easier from your project is to create a helper script. Here's one such example:
```bash
#!/usr/bin/env sh
LARADOCK_HOME="path/to/laradock"
pushd ${LARADOCK_HOME}
docker-compose exec --user=laradock workspace bash -c "cd my-project & & php artisan dusk & & exit"
```
This invokes the Dusk command from inside the workspace container but when the script completes
execution, it returns your session to your project directory.
2016-11-18 21:12:10 +01:00
2017-08-11 05:07:59 +02:00
[^1]: [Don't Use .dev for Development ](https://iyware.com/dont-use-dev-for-development/ )