PHPStorm and XAMP: Issue with PHP "Includes"


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?


Comment actions Permalink

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:

Comment actions Permalink

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?

Comment actions Permalink

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?

Comment actions Permalink

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.

Comment actions Permalink

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)?

I have been using the server document root when specifying every include

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:

define('DIR_ROOT', __DIR__);

include DIR_ROOT . '/incldue.php';

Possibly DOCUMENT_ROOT points to different folders when running via built-in server and XAMPP

Comment actions Permalink

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.

Comment actions Permalink

Is it better to use the XAMP server or inbuilt PHPStorm server?

XAMPP of course, for various reasons. Few of them:

  • Same web server (Apache) as on real server once deployed
  • Ability to use that server supported technologies (e.g. .htaccess & url rewriting  etc)
  • Server is available even if PhpStorm is closed
  • etc

so is it possible i can disable this in PHPStorm to only use the XAMP server i.e (localhost).

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 ( )

Comment actions Permalink

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

Comment actions Permalink

Actually Server document root, should get the absolute path, no?

Comment actions Permalink

I think ive fixed everything, thanks for the help :)


Please sign in to leave a comment.