Problem using Root for href in PhpStorm

I'm trialing PhpStorm after having used Notepad++ in the past for editing php files.

I've installed PhpStorm and setup XAMPP, created a new project and added the files that make up my website.

PhpStorm has the website in the folder C:\Users\username\PhpstormProjects\farmsoftware

When I try to view pages in a browser the css formatting, javascript, images etc. are not shown. The content is there but no styling.

I set the css in the head as follows:

<link rel="stylesheet" href="/scripts/css/reset.css" type="text/css" media="all">


If I remove the initial forward slash (root) from the href the styling appears:

<link rel="stylesheet" href="scripts/css/reset.css" type="text/css" media="all">

I know I could just remove the the slash and use relative instead of root relative locations but it is easier if I can simply reference files relative to the root (The website is structured such that there are pages within subfolders and having the same href for any page is easier).

Is there a setting I need to change or have I missed something obvious? Any help would be greatly appreciated.

2 comments
Comment actions Permalink

Hi Farmsoftware

I don't think your problem lies with PhpStorm. It sounds like the problem lies in your "document root" definition in Xampp.

As you know, a forward slash denotes the root directory of your server. Problems commonly occur when you create subfolders in your root directory to host your projects in. The server then starts to look for your css files in the root directory and not in the directory of your project.

The common solution is to create a virtual host in your Xampp configuration that has a dedicated document root for your project. Searching your favorite search engine for "xampp virtual host" points you in the right direction.

0
Comment actions Permalink

Hi there,

Please show the URL that is used in a browser?

Right now it sounds like you are using PhpStorm's own built-in simple web server instead of XAMPP. If that's true then behavior is correct and you need to correctly configure PhpStom to use your own XAMPP web server.

At the same time it could very likely be the issue described by Peter.

0

Please sign in to leave a comment.