Search code examples
phpsymfonyphpstormvirtual-machinevirtualbox

Developing on VM


I'm currently using a VirtualBox VM for development. It's a CENTOS box with Apache and PHP installed using the instructions at: http://tuline.com/wp-content/uploads/2015/11/A-Centos-Web-Development-Environment.pdf

I set the web folder on the server as a Samba share and mounted it in the host OS (Windows 7 or 10 depending on the machine I'm working on). The only issue I've had is when I started a Symphony project and downloaded PhpStorm to aide with auto completion.

PhpStorm immediately complained about working on a mapped network drive. I'm not sure if any features aren't working since I've been using VS Code until this point. I tried a couple of different ways of sharing the folder, but I'm not quite happy with any of them.

I tried using the VirtualBox shared folder feature, then mapping that to the web folder. This fixed PhpStorm complaints, but made the server incredibly slow. The basic page went from rendering in ~150ms to over 4s.

I also tried starting a local project using the mapped Samba share as the source and letting PhpStorm auto publish changed files. The problem with this configuration is that files created by Webpack don't show up in the PhpStorm project unless I manually tell PhpStorm to download them.

I'm currently thinking of going one of two ways:

  • Option one is to leave the Samba share like it is and let PhpStorm complain. I don't know how wise this option is, so I would like to hear from someone who has done this and if there are any issues that I'm not aware of.

  • Option two is to find a way to mirror folders in the host OS. Then I can mirror the Samba share and work out of the target folder in PhpStorm.

My question is, how does everyone else who develops in a VM handle sharing files? Hopefully someone will have something clever I haven't thought of.

Everything is running on SSDs if that makes any kind of difference.

Edit

I accepted Yarimadam's answer. If I was starting from scratch Docker seems like the way to go. However, with one development machine running Windows 7 and one on Windows 10, it seemed like the learning curve would be a bit much.

I finally went with unison to keep the directories synced. It was a bit of a pain to get to work properly. Here's the tutorials/articles I used to set them up. https://winscp.net/eng/docs/guide_windows_openssh_server

https://mike.eire.ca/2008/10/01/configuring-unison-on-windows/

https://gist.github.com/federivo/a1c56909b3f712e516a3cd2f70c0eaa6

http://rnowling.github.io/software/engineering/2015/04/02/installing-ocaml.html

Finally:

wget https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh -O - | sh -s /usr/local/bin

I couldn't find any guides that covered everything about setting up Unison. Most of them are linux to linux which isn't that problemmatic. The issues comes from two things. First the versions much match. That's not that big of a deal, but not only must the versions match, but they must be compiled with the same version of OCaml.

There's no note on the binary download page about which version was used for the last stable Windows version. Through trial and error, I finally got 2.84.4 to work properly compiling with OCaml 4.03.0 on the server.

The last bit with the wget is to install OPAM to install OCaml. I couldn't find a package in yum for OPAM and if you install OCaml through yum it will be version 4.01.0 which will crash when watching a directory.


Solution

  • PhpStorm's advanced features like code completion and find in path relies heavily on index, involving thousands of files. Due to this nature of PhpStorm, it needs to watch all change events on project directory and index them immediately. This procedure needs fast and reliable access to project directory. But in a typical network share map, it's not the case. Thats why PhpStorm is complaining about your samba mapping.

    Have you ever heard of Docker ?

    It's a vm like container platform which has mounted volumes built in. So you can map your local folder to a guest container and enjoy realtime sync. Docker is the best solution out there for this purpose.

    I personally use Docker. But in old days, i never need two way sync between host and guest os. I used to install everything at guest os (vendors, frontend task runners) and then download everything via sftp deployment server as follows:

    Configure a deployment server (sftp)

    [Tools > Deployment > Configure]

    Browse remote host, right click and choose "Download from here"

    [Tools > Deployment > Browse Remote host]

    Setup automatic upload

    [Tools > Deployment > Automatic Upload ]