2020-03-21 15:41:49

Hello guys,
I started working at an enterprise that uses a lot XML data as inproper imports from other suppliers. About 90% of employees use Linux as their working environment and aren't not familiar with Windows at all (yeah, I know, sounds great to be perfect at Linux Distro). For me it's a problem and I need to setup my environment to reflect theirs to be consistent. One good thing that their development environment is Dockerized (they use Docker Compose) to build the CMS which they're working on as a MVC structure. Since each controller invoked in index file by the URL request, there is no big issue to start import script (which downloads XML via FTP or HTTP connection) and starts importing that XML to the database. These files are not so small and their're different depending on supplier and my task is to expand existing scripts (classes) that do such imports to transform XML data to our own environment to be able to store it in the database for managers to use later on.
Since it's all written in PHP and Dockerized, I setup my environment like this:
Installed Microsoft Windows 10x64 PRO as my host machine, then on the top of that I installed VirtualBox and Vagrant, vooted VM Ubuntu 18.4, to be exact it's hashicorp/bionic64 box. On that Vm I installed Docker, Docker- Compose and built their Dockerized system as a Docker Compose container on the top. So as you see there are 3 different layers here (host + guest + VM as Docker on VM). They helped me with that Dockerized system and installed it for me.
That Docker container performs function of a server that servers CMS that I mentioned. So I can use browser on my host OS and browse in that CMS. Vagrant does folder sharing / syncing project directory in which there's a docker ant cms folders and this way I can reach them from my Host, from VM and from Docker Compose when rebuilding CMS.
Now on to the problem:
When we simply enter URL in browser's address bar, PHP script starts and executes code line by line, expression by expression from start till the end. Since import scripts handle big files, it takes a long time one script to do it's dirty work and somewhere on the way it might crash because of wrong XML syntaxe, wrong elements or their values being set and my job to fix that. I can use die() function to break code at some point in the code, but then it requires to be reloaded and spins from the start again so takes a lot of precious time, so var_dump() and other PHP functions are out of the question here, because the point that all of them require script to be reloaded.
Now I need some kind of debugging and PHP has one, which I used in the past called XDebug. Their Dockerized system has XDebug as well and settings are set that it's exposed via port 9001 on their config, so it's possible to use an IDE and it's own terminal to debug all the scripts that are served, I mean we can run them through CLI and get an output, as well as set a debugging mechanism. But all they use only 2 layers of systems, I mean Linux on their hardrive and VM as a Docker Compose / VM on the top of that so they can connect to the XDebug from an IDE on Linux and debug. IDEs on Linux aren't accessible with Orca as far as I know and my productivity would be decreased fairly in browsing and doing all the stuff on Linux not because it's terminal, but because of it's GUI and screen reader of course.
Since the same HTTP request goes on the web and import process is working smoothly through web interface, I thaught to debug by using XDebug Helper extension on Google Chrome and VScode would be a saviour here, because it supports PHP Debug and has good screen reader support. So I thaut if I would set the same port for VSCode to listen for XDebug and it would be the same as a port in Dockerized VM (they set 9001), enter an url for a script to be executed in the browser that has XDebug Helper enabled and VSCODE set as an IDE key, script would load and VSCode would get the connection and would stop that code execution where I set up my breakpoints. That way I could debug it and it should work that way, but it just doesn't work...
I set my port forwarding in vagrantfile as such:
config.vm.network "forwarded_port", guest: 80, host: 8081
config.vm.network "forwarded_port", guest: 9001, host: 9001
config.vm.network "forwarded_port", guest: 80, host: 8081, host_ip: ""
config.vm.network "private_network", ip: ""
config.vm.network "public_network"
Then in C:\windows\system32\drivers\etc\hosts file I redirected to that CMS which is on Docker, so it opens in the browser smoothly.
After that I changed the options in my VSCode project which is on c:\users\just\projects\project\cms. In that project folder is vagrantfile, so my guest OS sees the tvs folder and in the same root vagrant folder is docker folder as well. As far as I was saying, I changed c:\users\just\projects\project\tvs\.vscode\launch.json file and added this:
{"name": "Listen for Xdebug",
   "type": "php",
     "pathMappings": {
"/var/www/cms": "c:\\users\\just\\projects\\project\\cms"
   "request": "launch",
   "port": 9001,
   "log": true}]
Then in VSCode I opened my project, chose index.php file which is at c:\users\just\projects\project\cms\web\index.php, set the breakpoint with f9, pressed f5 to run debugger, opened my browser, entered http://cms/ and it loaded index.php file, but it wasn't stopped by VSCode. When I turn on VSCode debugger, it says this:
<- launchResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true
But in fact - nothing happens. I'm sure that XDebug Helper is turned on in browser, also I'm sure that XDebug is selected i VSCode as a default launcher.
Maybe someone has some idea what's happening?

Thumbs up

2020-03-21 20:08:42

I'm sure this problem arises because of VSCode, because XDebug logs showed me that coonection to client is successful

Thumbs up

2020-03-21 21:36:27

I don't know, but it sounds like you massively overcomplicated your setup: why not just use Docker for Windows, and point WSL commands at it?

Also you will have much, much more luck on Stack Overflow or similar.

My Blog
Twitter: @camlorn38

2020-03-22 16:04:19

I know that my environment is possibly overkill, although when I came to work in the company I didn't properly know what concrete tasks I would be assigned to so thaught that Linux would be a really important step in this, although it turned out to be not that important, because everything runs on Docker Compose as a nginks server. Since they helped me to setup my Docker containers, now I just don't wanna waist my time on setuping anymore. They already assigned me the tasks I need to do.
I solved the problem my setting up the XDebug logs and checking remote information and IP on VSCode launch.json configuration was incorrect. It turned out that hostname should be set and there isn't enough to set only port to listen connections from XDebug on, although many tutorials miss that thing somehow, so I found it as a parameter in documentation of that PHP Debug Extension.
Another question is it important to set up my SSH key on a host machine if I already set it on my VM? This SSH key on Windows is generated by Vagrant and if I would regenerate my SSH key, Vagrant might hang up on waking up the virtual machine. I tested this on another PC and it crashed so I cann not regenerate it. My only way to connect to Bitbucket that we use is to use VM where I generated my SSH key and entered in their system as a public one. It allows to pull the CMS from their systems and it works smoothly, but my question is it OK to push commited files in branches that are assigned to a particular tasks by an ID to the remote branch of my own making via CLI? Or should I consider to use IDE for GIT management?

Thumbs up