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

  • Thread starter Thread starter Dave Ritche
  • Start date Start date
  • Tags Tags
    Php
Click For Summary
When using XAMPP, all files that the browser needs to access directly, including HTML, CSS, and PHP files, must be placed in the HTDOCS folder or its subfolders. This is essential for the files to be served correctly. While PHP scripts can access files outside of the HTDOCS directory, browsers cannot, which is a security measure to prevent unauthorized access to the server's file system. Users can modify the Apache server configuration to change the default directory, but it is recommended to keep resources organized within HTDOCS. Additionally, learning to use a PHP framework is advised for better development practices.
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.
 
Technology 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 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 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 Dave Ritche
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 21 ·
Replies
21
Views
6K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 9 ·
Replies
9
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
3
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K