PHPStorm and XAMP: Issue with PHP "Includes"
Hi,
I have an issue with a site i am developing locally, using the IDE PHPStorm and xampp server.
The issue i have is with the url:
e.g http://localhost:63342/mysite
If i remove the port number from the url : i am presented with a problem - including other php files from other directories will not work, until i insert the port number back in.
How can i fix this?
thanks.
Please sign in to leave a comment.
Hi there,
The http://localhost:63342/mysite kind of URL means that built-in simple web server is in use. The URL used will be something like this: http://localhost:63342/PROJECT_NAME/index.html
If you want to use your XAMP as webserver to serve your files, check these links:
Sorry i didint make it clear, this is the url i was just giving an example showing the port number
this: http://localhost:63342/mysite/index.php
More to the point have you come across the issue i am having using includes?
Your new URL and comment do not make any difference here (at least I fail to see it).
In any case: such URL still means that built-in simple web server is in use (in case if you are wondering what that is).
If you are referring about the fact that when script is served via built-in web server it works fine .. but when served via your local XAMPP it cannot find include files .. then you should check PHP's error log to see what files it tries to find and where (with that little info you gave here it's hard to suggest something reasonable).
Quite likely that PHP used by XAMPP searches for include files differently or in slightly different paths (for whatever reason; for example, built-in server may add extra folders in include search path automatically while under XAMPP you will have to do it manually). Try using FULL ABSOLUTE paths when including/requiring files -- will it start working properly?
I have been using the server document root when specifying every include, it seems that with the port number it searches the right place, but removing the port number searches the wrong place. I am trying to understand why adding the port number changes the behaviour of this.
Possibly because 2 different webservers (and therefore, possibly 2 different PHP configs) are used...
It is not clear for me from your answers, therefore I will ask: do you understand that when you use URL with port number then PhpStorm's own built-in web server is used .. and when URL has no port number, then it is served by your XAMPP (Apache)?
If you do understand that .. then can you please verify that it is the same file being executed in both cases (to exclude the case where 2 different files got called by mistake)?
This (potentially) could be the source of the problem. I'll have to ask again (since you have not said anything about that): have you tried specifying full absolute paths -- did it worked? -- Yes or No?
If that worked (full absolute paths) .. then try not to use $_SERVER['DOCUMENT_ROOT'] .. but try doing it via constant that is defined in your index.php (entry point). Something like this:
Possibly DOCUMENT_ROOT points to different folders when running via built-in server and XAMPP
I understand now.
I have one additional question. Is it better to use the XAMP server or inbuilt PHPStorm server? I think i prefer the XAMP server without the port number, so is it possible i can disable this in PHPStorm to only use the XAMP server i.e (localhost).
I tried using absolute paths, however it wasent working because i am including from many different sub-directories. I found my problem was solved when i started using the server document root. However i will try your method again of defining the root directory - Once the above is decided.
XAMPP of course, for various reasons. Few of them:
Sure. Built-in web server is used when no deployment is configured. Once configured and marked as default the URL you provide there will be used instead.
Just follow the first link I gave in my first post ( http://stackoverflow.com/a/24914837/783119 )
Right that is done,
Now my server document root includes are messed up. I shall try put them back to absolute path - hopefully it should work
Actually Server document root, should get the absolute path, no?
I think ive fixed everything, thanks for the help :)