Are HTML and CSS files necessary in the HTDOCS folder for PHP to work in XAMPP?

  • Context: HTML/CSS 
  • Thread starter Thread starter Dave Ritche
  • Start date Start date
  • Tags Tags
    Php
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 3K views
Dave Ritche
Messages
70
Reaction score
6
Hello everyone..
I am learning php and I'm new to php.I don't know much about it.
i watched a tutuorial on it that told me i were to put my scripts into the HTDOCS folder.
My question is that is it necessary to my html and css files into HTDOCS folder?Will it work?
I am running xampp..
thanks.
 
Physics news on Phys.org
Dave Ritche said:
Hello everyone..
I am learning php and I'm new to php.I don't know much about it.
i watched a tutuorial on it that told me i were to put my scripts into the HTDOCS folder.
My question is that is it necessary to my html and css files into HTDOCS folder?Will it work?
I am running xampp..
thanks.
Every file that the browser has to directly access must be in the HTDOCS folder or a subfolder of HTDOCS.
This applies to a php file that the url refers to.
Also, if your HTML includes statements like:
HTML:
<script src="/somepath/js/directives.js" type="text/javascript"></script>
<link href="/somepath/css/standard.css" rel="stylesheet" type="text/css"/>
then the referenced folders must exist in HTDOCS.

Your can rename the folder (my WAMP version uses www).
Your php code can access files in folders outside the HTDOCS folder. But the browser can't.
 
  • Like
Likes   Reactions: Dave Ritche
Samy_A said:
Every file that the browser has to directly access must be in the HTDOCS folder or a subfolder of HTDOCS.

I'll just add that this is for security reasons. If you made your server accessible to everyone on the Internet (it may actually be that way depending on how your Internet connection is set up!) would you want them to be able to look around everywhere on your hard disk by entering a suitable URL? :wideeyed:
 
  • Like
Likes   Reactions: Dave Ritche
Dave Ritche said:
Hello everyone..
I am learning php and I'm new to php.I don't know much about it.
i watched a tutuorial on it that told me i were to put my scripts into the HTDOCS folder.
My question is that is it necessary to my html and css files into HTDOCS folder?Will it work?
I am running xampp..
thanks.
htdocs is by default set up as your main virtual directory, you can modify your apache server config file to resolve your url to anywhere that your resources are being stored physically. That means you can store your php scripts in the same folder with your html and css. You'd better learn to use a php framework though.
 
  • Like
Likes   Reactions: Dave Ritche