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
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.
For Windows Hosts
C:/Users/Youruser/bin/putty.C:/Users/Youruser/bin/php_vm_tunnel.batwith this content:For Unix-ish Hosts (OS X, Linux, etc)
~\bin\php_vm_tunnelTesting the Script
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:
You should see the PHP version info return from your virtual machine.
Sublime Text 2 Configuration
Now that you have this tunnel set up, you can configure Sublime Text 2 to make use of it:
Package ControlSublime Text 2 pluginSublimeLinterplugin (it sounds like you were already at this point)Preferences->Package Settings->SublimeLinter->Settings - UserAdd 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:
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:
And SublimeLinter should be properly linting PHP files as if it were calling a native PHP binary.
Good luck.