Local Classic + PHPUnit + PhpStorm

Note! This is an involved tutorial, and is focused on Local Classic (Version 3.3.0 and earlier).

We plan on drastically streamlining the PHPUnit experience with Local in future versions.


Step 1: Map the SSH Port

In order to access SSH inside the Local container, port 22 needs to be exposed. This is done using the Local Ports Add-on.

  1. Navigate to the site in Local
  2. Click More » Ports
  3. Add a port for SSH pointing to 22
  4. Click “Remap Ports”
  5. Note the Host Port of the newly added SSH port. We will reference this later. In this case, it’s 4008.

Step 2: Install OpenSSH Server in the site’s container:

  1. Right-click on the site in Local’s sidebar
  2. Click “Open Site SSH” (If you’re curious, “Open Site SSH” isn’t true SSH, it’s attaching to a TTY)
  3. Run apt-get update && apt-get install -y openssh-server

  1. Run the follow command to tell OpenSSH to start when the site is [re]started: sed -i "/service mysql start/aservice ssh start" /etc/scripts/startup.sh
  2. Change the root password to root by running: passwd and then entering root twice.
  3. Allow the root user to log in with SSH by running the following: sed -i "s/PermitRootLogin without-password/PermitRootLogin yes/" /etc/ssh/sshd_config
  4. Restart the site in Local

Step 3: Install PHPUnit in the site’s container

Reference: PHPUnit – Make WordPress Core

(If you still have the site’s SSH terminal window open, skip to #3 below)

  1. Right-click on the site in Local’s sidebar
  2. Click “Open Site SSH”
  3. Run wget https://phar.phpunit.de/phpunit-6.5.phar && chmod +x phpunit-6.5.phar && mv phpunit-6.5.phar /usr/local/bin/phpunit
  4. Run phpunit --version to verify that PHPUnit was installed correctly

Step 4: Configure PhpStorm

  1. Navigate to PhpStorm » Preferences » Languages & Frameworks » PHP

  1. Click ... beside CLI Interpreter to open the following window

  1. Click the + button and then go to "From Docker, Vagrant, VM, Remote…` (if this option is not available, you may need to enable the Remote PHP Interpreter plugin in PhpStorm) 51%20PM

  2. Enter the following details:

  • Host: This can be found by going to the site in Local and then copying the “Remote Host” option in the “Database” tab
  • Port: See Step #1.5 at the beginning of this article
  • User name: root
  • Password: root
  • PHP interpreter path: /usr/local/bin/php
  1. Hit OK then Apply

  2. Change the PHP language level option to whatever matches the PHP version that the Local site is running

  3. Click on ... beside “Path mapping”

  4. Map the site’s public folder in the project to /app/public

  1. When you’re done adding the CLI Interpreter and Path Mappings, it should look something like this. Make sure you hit Apply.

  1. Go to Languages & Frameworks » PHP » Test Frameworks and click the + to add a new Test Framework

  2. Select the newly created Interpreter

  1. Select “Path to phpunit.phar” under “PHPUnit library”

  2. Enter /usr/local/bin/phpunit for “Path to phpunit.phar”

  1. Hit Apply and close the Preferences

Using PHPUnit!

In this case I’m checking out wordpress-develop and running the phpunit.xml.dist file. See PHPUnit – Make WordPress Core.


Thank you Clay. While I went through this, I decided to take notes on the issues I ran into to help anyone who’s going through these steps.

Problem 1:
When I ran phpunit --verison, I ran into this error:
cannot use PHPUnit\Framework\MockObject\Stub as Stub because the name is already in use in phar:///usr/local/bin/phpunit/phpunit-mock-objects/Builder/InvocationMocker.php on line 16

Solution 1:
And I resolved it by updating my PHP version to 7.1.4.

Problem 2:
After clicking "From Docker, Vagrant, VM, Remote I didn’t see “Host”, “User Name”, etc…

Solution 2:
I had to click the SSH Credentials radio button to display these configurations

Problem 3:
It wasn’t clear to me that I needed to click "PHPUnit By Remote Interpreter on step 11

Solution 3:
Well, I clicked on “PHPUnit By Remote Interpreter” before moving on to step 11 :slight_smile:

Problem 4:
I was getting errors on step 13.

Solution 4:
This was solved, again, by using PHP 7.1.4

1 Like

This seems broken in Local 2.4.0.

I got to step 4 (Click “Remap Ports”) and now it just says “Provisioning” with no indicator that anything is happening.

Stuff I also did:

  • Fully restarted my Mac.
  • VirtualBox version 5.2.18 r124319 (Qt5.6.3)
  • Updated Xcode to 10 (also tried 10.1 beta)

The logs haven’t been updated in 10+ minutes, which I’ll take as an indication that it’s hung up on something:

Sep 20, 2018, 9:28 PM CDT - info: [EnvironmentCustom] Empty /etc/mysql
Sep 20, 2018, 9:28 PM CDT - info: [EnvironmentCustom] Copying MySQL config to container prior to starting.
Sep 20, 2018, 9:28 PM CDT - info: [main/waitForFile] Waiting for  /conf/php/7.2.0/etc/php-fpm.conf c7a3fc178a3456574ae80167a555156d941199f0a38d1773d081f2def739e409
Sep 20, 2018, 9:28 PM CDT - info: [main/waitForFile] /conf/php/7.2.0/etc/php-fpm.conf exists
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] getRouterContainers()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] teardown()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] Removing router container 2afa58d51be84875b1b51621c30c6ec94d3c4dd6bce42c6a5f715bc7f4bb428c
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] updateProxyManager()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] runContainer()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-network-manager] removeExistingNetworks
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-network-manager] createNetwork
Sep 20, 2018, 9:28 PM CDT - info: [EnvironmentCustom]  Starting php-fpm  done
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] reconnectNetwork()

Hey @JJJ,

Are you still running into this issue? I wasn’t able to reproduce it with Custom or Preferred on Local 2.4.0.

Hi Clay,

I’m experiencing exactly the same: I hit Remap ports and it spins on ‘Provisioning’ forever…

I’m running on Local 2.4.0 on a Windows10 machine.

Any thoughts???


Sorry about that! It’s tough to say what’s going on without more details.

Can you please provide your local-by-flywheel.log file? See How do I retrieve Local's log file? for instructions on how to do so.

…and the same here. Mac OS X Mojave, Local 2.4.2, VirtualBox 5.2.18
Provisioning forever.

@JJJ Have you solved it in any way?

I want to clarify that it works for me.
(MacPro under Mac OS X Mojave, LBF 2.4.2, VirtualBox 5.2.18)

Maybe your problems come from elsewhere.

First problem I ran into was that a /etc/scripts/startup.sh file did not exist.

Next issue was that after creating it and running sed, it didn’t create any update in the file.

Any ideas?

Running 2.4.3 on Windows 10.


Hi Clay,

Sorry it’s been a while I got sidetracked but still need to set up automated testing!

Yes the problem still occurs. I’m on local 2.4.6 on Windows 10

Here is a link for the log file - I took a look but nothing obvious stuck out.

FYI I also tried on my laptop and got exactly the same results

Any help is much aprpeciated

I believe I have the same issue, stuck on Provisioning, does not go past that point.
Also I noticed if I force quit after 20min or so and restart and try again the new port when trying to add SSH has incremented by one, i.e from 4033, 4034, 4035 each time I try and you cant change that field.

LBFW 2.4.5
VB 5.2.20

Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-machine] checking IP
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-machine] checked IP

Nov 16, 2018, 11:38 AM GMT+10 - info: [EnvironmentCustom] Empty /etc/mysql
Nov 16, 2018, 11:38 AM GMT+10 - info: [EnvironmentCustom] Copying MySQL config to container prior to starting.
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/waitForFile] Waiting for  /conf/php/7.1.4/etc/php-fpm.conf da8509b02a193c18fa1fa75689a865fc791c8e5b5508d498b208f009eb84260b
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] getRouterContainers()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] teardown()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] Removing router container 76979bc2f905bd7e2da32b48b7789cc587933000a587cd77ef4bc2975ffadec1
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] updateProxyManager()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] runContainer()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-network-manager] removeExistingNetworks
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-network-manager] createNetwork
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/waitForFile] /conf/php/7.1.4/etc/php-fpm.conf exists
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] reconnectNetwork()
Nov 16, 2018, 11:38 AM GMT+10 - info: [EnvironmentCustom]  Starting php-fpm  done```

My need wasn’t for PHP unit, but searching if it was possible to connect with SSH to container. And how to do it with security (adding this possibility only for a user with a specific password …)
As I read this tutorial carefully, I have followed Step1 and Step2 and I wonder… Isn’t it dangerous to install OpenSSH-server in a Local By Flywheel container and give the ability to connect to container with root / root ? Anyone discover your Remote Host and Port can connect with SSH and then break everything… isn’t it?
… …
Finally, I tried an SSH connection with an external PC to the one containing LBFW and the result is a connection timed out! So, everything is OK!!! :blush:

I’m also getting the provisioning forever bug (OSX 10.14.3, Local 3.0.4). Is the ports add-on still being maintained?

Just had to do this again in 2019. My working process was:

  1. Download and run this script in my local environment: https://gist.github.com/keesiemeijer/a888f3d9609478b310c2d952644891ba
  2. Follow the steps above, but skip step 3
1 Like

I just ran into this exact same issue today. The only way I was able to fix it was by completely creating a new site and starting over :confused:

Current process:

  1. Set up ports as detailed in step 1 above
  2. open site SSH and run this script: https://gist.github.com/alexstandiford/0728ba7b21caa323a5ecf67c6e98abd2
  3. Restart local
  4. Open site SSH and run this script:
  5. Start on step 4 - Configure PHPStorm above.

The Ports extension is deprecated, and I don’t see any way to add ports in Local Lightning. Is there any way to use PHPUnit and PhpStorm with Local Lightning?

Sorry I can’t help you get setup with PhpStorm, but the above should help.

Thanks, @afragen, but the part of the process I need help with is setting up PhpStorm.