Any way to run sublime text linter with php running in virtualbox vm?

I use sublime text 2, and I wanted to use the Sublimelinter plugin. It checks the code in the background using php -l. I work with a web server running in a virtual virtual machine, the web server is in the virtual machine (guest), and the arrogant text is running on the host.

Any way to get these 2 to work together? I really wanted to avoid installing php outside the virtual machine.

+6
source share
1 answer

I have something that works well on my machine, but seems fragile.

Idea

The idea here is to create a command line script on your host that passes all of its parameters to a PHP call on your virtual machine through an SSH tunnel. SublimeLinter can then call this script, as is usually called by the PHP binary, and from the point of view of Sublime everything will โ€œjust workโ€ without installing PHP on your host.

I use Windows and OS X hosts, so I have two versions of my tunnel script. Note that on Windows you will need to use the Windows PuTTY SSH tools, but for hosts with Unix support SSH is most likely already present.

For Windows hosts

  • Download putty tools and unzip them somewhere useful, for example C:/Users/Youruser/bin/putty .
  • Create a script package in 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 %* 

NOTE. Be sure and replace the path with plink with the correct path where you unzipped the putty above. Also, replace the -l and -pw flag values โ€‹โ€‹with the username and password that you use when you use SSH in your virtual machine. Finally, make sure and replace the IP address in this example with the IP address you use for SSH on your virtual machine.

For Unix-ish hosts (OS X, Linux, etc.)

  • Create a bash script in ~\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 

NOTE. Be sure to replace the -l flag with the username you use when you use SSH in your virtual machine. Also, be sure to replace the IP address in the example with the IP address you use for SSH with your virtual machine.

Testing Script

At this point, you have a script that should tunnel everything that you pass it to your virtual machine. Therefore, if in the terminal you should have done, say:

 cd wherever_you_put_the_script php_vm_tunnel -v 

You should see PHP version information returning from your virtual machine.

Sublime Text 2 Configuration

Now that you have configured this tunnel, you can configure Sublime Text 2 to use it:

  • Install the Package Control Sublime Text 2 Plugin
  • Install the SublimeLinter plugin (it looks like you were already at this stage)
  • Go to Preferences Package Settings SublimeLinter Settings - User
  • Add this to the configuration file (again substituting the correct path to the script and marking the double slashes to properly remove 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 have only one php statement. The first is the Windows version, the second is the Unix version. Remove the one you do not need.

  • restart sublime text

If you open the Sublime Text console (and everything goes according to plan), you should see something in the start text, for example:

 SublimeLinter: php enabled (using "C:\Users\Youruser\bin\php_vm_tunnel.bat" for executable) 

And SublimeLinter should iterate over the PHP files correctly, as if it were calling its own PHP file.

Good luck.

+6
source

Source: https://habr.com/ru/post/925042/


All Articles