EDIT: I will edit this question properly later but this is NOT an Apache problem it is an IDE problem within PhpStorm. I have sorted all the problems and answered below.
I have been trying to sort things out for literally months on various machines. I have cleared the gremlins from my Apache setup by good magic I think (here if you want more details https://stackoverflow.com/questions/33251175/virtual-host-not-working) .
Now everything seems to be working fine. I have various virtual hosts including sane30
and sane30.dev
which in a web browser behave as expected.
If I do an echo $_SERVER['DOCUMENT_ROOT'];
in sane30.dev/index.php
or sane30/index.php
I get C:/xampp/htdocs/sane30/
. If I do the same test with localhost/sane30/index.php
I get C:/xampp/htdocs/
- the page runs BUT any include
or images or whatever are not found. All as expected I guess.
My real problem at the moment is debugging in PhpStorm.
A) I am really struggling to understand how to debug in PhpStorm - I am 100% convinced it will be mammothly helpful but I am finding it difficult to understand but also
B) I am having a nightmare getting PhpStorm to find the right document root consistently. Every time I hit debug it launches as http://localhost/sane30/beta30/newForm.php
not http://sane30/beta30/newForm.php
or http://sane30.dev/beta30/newForm.php
which screws up all the includes
and makes it impossible to debug. To make matters worse there seems to be something very random going on. I have tried changing many settings with little success.
So a) is anyone familiar with PhpStorm and able to advise me where to define sane.dev
as the root server as opposed to localhost
and/or
b) can anyone help with a strategy to make all pages understand the same root despite how the are originally launched (sane30 or localhost)?
In hosts
I have
127.0.0.1 sane30
127.0.0.1 sane30.dev
and in httpd-vhosts.conf I have
<VirtualHost *:80>
ServerName sane30
ServerAlias sane30.dev *.sane30.dev
DocumentRoot c:/xampp/htdocs/sane30/
</VirtualHost>
if that is helpful.
There are two problems here:
1) PhpStorm does NOT translate $_SERVER['DOCUMENT_ROOT']
so any use of this to make a path is doomed.
2) setting directories in PhpStorm.
I am not sure this HAS to be done but it seems to have worked for me.
In settings you need deployment:
There I set my root URL and used "In place" which seems to work fine.
Then on the Mapping tab I set up the relevant paths (this might have been OK but worth a check).
Finally two of the debugging hurdles I hit and for which I could not find any solutions here or Google.
"Frames are not available": I wasted an hour thinking this was a problem - it just means debug has nothing to report. If you look at the console it simply say "yippee it ran without incident" so if you have set breakpoints, variable watches or whatever - then you need to check what you are looking at!
I also wasted ages because the Frames tab in the debugger had disappeared (was not visible).
The solution could not be simpler but if you are a newb like me hope this save you time. Simply click the "Restore layout" button and voila.