Is there any way to SSH directly without running through Docker? I’d like to add a connection to a site via PHPStorm as a new remote interpreter, and their Docker support doesn’t seem to be doing anything to actually tunnel in (or I can’t figure out how to make the connection in the PHPStorm settings).
This is for setting up a test runner via PHPUnit (which I got working via the right-click SSH in local itself), I just can’t connect the two. I don’t think the add-on to set up XDebug does the trick to set up a connection in PHPStorm to Local vs. the other way around.
I’ve came up with a shell script that you can use to trick PhpStorm into using Local’s PHP.
First off, here’s the shell script. Save this somewhere, chmod +x it.
#### Change This #####
DOCKER_CONTAINER='64c399646bbe68320c72d90de5b63d535e92681b728cfa17c4b48bb99263a533'
######################
#### Maybe Change These ####
DOCKER_MACHINE='local-by-flywheel'
LOCAL_PATH='/Applications/Local by Flywheel.app'
############################
PHPUNIT_WRAPPER=$3
PHPUNIT_WRAPPER_PATH=$(dirname $PHPUNIT_WRAPPER)
alias docker="'$LOCAL_PATH/Contents/Resources/extraResources/virtual-machine/vendor/docker/osx/docker'"
alias docker-machine="'$LOCAL_PATH/Contents/Resources/extraResources/virtual-machine/vendor/docker/osx/docker-machine'"
# Update config path since PHPStorm will always pass the host system path. We need only what's after /app
CONFIG_PATH=$(echo $5 | grep -o "/app/.*$")
set -- "${@:1:4}" "$CONFIG_PATH"
eval $(docker-machine env $DOCKER_MACHINE);
# Copy PHPStorm's wrapper file into the container
docker exec $DOCKER_CONTAINER mkdir -p $PHPUNIT_WRAPPER_PATH
docker cp $PHPUNIT_WRAPPER $DOCKER_CONTAINER:$PHPUNIT_WRAPPER
# Run PHPUnit
docker exec $DOCKER_CONTAINER php "$@"
After saving that shell script and running chmod +x on it, you’ll need to adjust the variables at the top of the file to match your setup.
Then, right-click on the site in Local, go to “Open Site SSH”, and install Composer if it isn’t already. The easiest way to do this is to do run the following:
apt-get update && apt-get install -y wget
wget -qO- https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
After Composer is installed you need to install PHPUnit. Here’s how:
composer global require phpunit/phpunit (ignore the root user warning)
In PhpStorm do the following:
Go to Preferences » Languages & Frameworks » PHP
Add a new CLI Interpreter by clicking on the ... by the dropdown
Click on the + in the upper-left and select Other Local...
Point the PHP Executable to the shell script. Apply and ignore any warnings.
Go to Run » Edit Configurations…
Click on the + and add a PHPUnit configuration
For Test Scope select Defined in the configuration file
Check Use alternative configuration file and browse to the path. Note: it must be in the app folder for the site
Set Interpreter options to -d include_path=./:/usr/local/lib/php:/root/.composer/vendor/phpunit
I’ve tried playing around the the PHPUnit options (the second … in the “Use alternative configuration file” line), and am using the ID found in /Users/bhogg/Library/Application\ Support/Local\ by\ Flywheel/ssh-entry/rJ8FNfZpx.sh (file run when you SSH in via the right-click in Local by Flywheel) near the end:
(so 58e3e471c34fa35059d9c8bf9f9eed72634cdbd8de8f3c083df04ead59a20e68 is what I’m assuming is the docker container ID).
If you SSH in and go into /app/public/wp-content/plugins/event-calendar-newsletter and run /root/.composer/vendor/bin/phpunit the tests run as expected.
Will keep playing around and seeing if I can get it working, but any thoughts welcome!
@brent Unfortunately not, I’ve just been getting the error above when running the tests. I just updated to the latest version of PHPStorm and I’m getting the same issue.