I am using sublime text 2, and I wanted to use the plugin sublimelinter. It checks the code in the background with php -l. I'm developing with a webserver running in a VirtualBox VM, webserver is in the VM (guest) and sublime text is running on the host.
Any way to get those 2 working together? I really wanted to avoid installing php outside the VM.
I've got something that works reasonably well on my machine, but it seems fragile.
The idea here is to create a command-line script on your host that passes all its parameters to a PHP call on your VM, via an SSH tunnel. SublimeLinter can then call this script as it would usually call the PHP binary, and from Sublime's point of view everything will "just work" without having to install PHP on your host.
I'm using both Windows and OS X hosts so I've got two versions of my tunnel script. Note that on Windows you'll need to fetch the Windows PuTTY SSH tools, but for Unix-flavored hosts SSH will likely already be present.
C:/Users/Youruser/bin/putty
.C:/Users/Youruser/bin/php_vm_tunnel.bat
with this content:
@echo off C:/Users/Youruser/bin/putty/plink -l youruser -pw yourpassword 192.168.56.101 php %*
-l
and -pw
flag values with the username and password that you use when you SSH into your VM. Finally, be sure and replace the IP address in the example with the IP address you use to SSH into your VM.
~\bin\php_vm_tunnel
#!/usr/bin/env bash FIXED_ARGS=''; for (( i = 1; i <= $# ; i++ )); do eval ARG=\$$i FIXED_ARGS="$FIXED_ARGS $(echo "$ARG" | awk '{gsub(".", "\\&");print}')" done ssh -l root 192.168.56.101 php $FIXED_ARGS
-l
flag value with the username that you use when you SSH into your VM. Also, be sure to replace the IP address in the example with the IP address you use to SSH into your VM.
At this point you have a script that should tunnel anything you pass to it through to your VM. So if in a terminal you were to do, say:
cd wherever_you_put_the_script php_vm_tunnel -v
You should see the PHP version info return from your virtual machine.
Now that you have this tunnel set up, you can configure Sublime Text 2 to make use of it:
Package Control
Sublime Text 2 pluginSublimeLinter
plugin (it sounds like you were already at this point)Preferences
-> Package Settings
-> SublimeLinter
-> Settings - User
Add this to the configuration file (again substituting in the proper path to the script and noting the double slashes to properly escape the backslash characters) and save:
{ "sublimelinter_executable_map": { "php": "C:\\\Users\\\Youruser\\\bin\\\php_vm_tunnel.bat" "php": "/Users/youruser/bin/php_vm_tunnel" } }
NOTE - You can only have one "php" statement. The first one above is the Windows version, the second one is the Unix version. Delete the one you don't need.
If you open the Sublime Text console (and everything went according to plan) you should see something in the startup text like like:
SublimeLinter: php enabled (using "C:\Users\Youruser\bin\php_vm_tunnel.bat" for executable)
And SublimeLinter should be properly linting PHP files as if it were calling a native PHP binary.
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With