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.
- Navigate to the site in Local
- Click More » Ports
- Add a port for
SSH pointing to
- Click “Remap Ports”
- Note the Host Port of the newly added SSH port. We will reference this later. In this case, it’s
Step 2: Install OpenSSH Server in the site’s container:
- Right-click on the site in Local’s sidebar
- Click “Open Site SSH” (If you’re curious, “Open Site SSH” isn’t true SSH, it’s attaching to a TTY)
apt-get update && apt-get install -y openssh-server
- 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
- Change the
root password to
root by running:
passwd and then entering
- 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
- 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)
- Right-click on the site in Local’s sidebar
- Click “Open Site SSH”
wget https://phar.phpunit.de/phpunit-6.5.phar && chmod +x phpunit-6.5.phar && mv phpunit-6.5.phar /usr/local/bin/phpunit
phpunit --version to verify that PHPUnit was installed correctly
Step 4: Configure PhpStorm
- Navigate to PhpStorm » Preferences » Languages & Frameworks » PHP
... beside CLI Interpreter to open the following window
+ 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)
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:
- PHP interpreter path:
Hit OK then Apply
Change the PHP language level option to whatever matches the PHP version that the Local site is running
... beside “Path mapping”
Map the site’s
public folder in the project to
- When you’re done adding the CLI Interpreter and Path Mappings, it should look something like this. Make sure you hit Apply.
Go to Languages & Frameworks » PHP » Test Frameworks and click the
+ to add a new Test Framework
Select the newly created Interpreter
Select “Path to phpunit.phar” under “PHPUnit library”
/usr/local/bin/phpunit for “Path to phpunit.phar”
- Hit Apply and close the Preferences
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.
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
And I resolved it by updating my PHP version to 7.1.4.
After clicking "From Docker, Vagrant, VM, Remote I didn’t see “Host”, “User Name”, etc…
I had to click the SSH Credentials radio button to display these configurations
It wasn’t clear to me that I needed to click "PHPUnit By Remote Interpreter on step 11
Well, I clicked on “PHPUnit By Remote Interpreter” before moving on to step 11
I was getting errors on step 13.
This was solved, again, by using PHP 7.1.4
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()
Are you still running into this issue? I wasn’t able to reproduce it with Custom or Preferred on Local 2.4.0.
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.
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
@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.
Running 2.4.3 on Windows 10.
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.
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 192.168.95.100
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!!!
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:
- Download and run this script in my local environment: https://gist.github.com/keesiemeijer/a888f3d9609478b310c2d952644891ba
- Follow the steps above, but skip step 3
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
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.