All In One Script



PHP,HTLM,CSS,Jquery,AJAX,Javascript and etc doubts and sample codes

  • Home
  • Javascript
  • PHP
  • CSS
  • SQL/MYSQL

Make XAMPP/Apache serve file outside of htdocs

by Blogger 4:31:00 AM Apache htdocs PHP XAMPP

Make XAMPP/Apache serve file outside of htdocs

Is it possible to configure xampp to serve up a file outside of the htdocs directory?
For instance, say I have a file located as follows:
C:\projects\transitCalculator\trunk\TransitCalculator.php
and my xampp files are normally served out from:
C:\xampp\htdocs\
(because that's the default configuration) Is there some way to make Apache recognize and serve up my TransitCalculator.php file without moving it under htdocs? Preferably I'd like Apache to serve up/have access to the entire contents of the projects directory, and I don't want to move the projects directory under htdocs.
edit: edited to add Apache to the question title to make Q/A more "searchable"

Solution: 


Ok, per pix0r's, Sparks' and Dave's answers it looks like there are three ways to do this:

Virtual Hosts

  1. Open C:\xampp\apache\conf\extra\httpd-vhosts.conf.
  2. Un-comment line 19 (NameVirtualHost *:80).
  3. Add your virtual host (~line 36):
    <VirtualHost *:80>
        DocumentRoot C:\Projects\transitCalculator\trunk
        ServerName transitcalculator.localhost
        <Directory C:\Projects\transitCalculator\trunk>
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
  4. Open your hosts file (C:\Windows\System32\drivers\etc\hosts).
  5. Add
    127.0.0.1 transitcalculator.localhost #transitCalculator
    to the end of the file (before the Spybot - Search & Destroy stuff if you have that installed).
  6. Save (You might have to save it to the desktop, change the permissions on the old hosts file (right click > properties), and copy the new one into the directory over the old one (or rename the old one) if you are using Vista and have trouble).
  7. Restart Apache.
Now you can access that directory by browsing to http://transitcalculator.localhost/.

Make an Alias

  1. Starting ~line 200 of your http.conf file, copy everything between <Directory "C:/xampp/htdocs"> and </Directory> (~line 232) and paste it immediately below with C:/xampp/htdocs replaced with your desired directory (in this case C:/Projects) to give your server the correct permissions for the new directory.
  2. Find the <IfModule alias_module></IfModule> section (~line 300) and add
    Alias /transitCalculator "C:/Projects/transitCalculator/trunk"
    (or whatever is relevant to your desires) below the Alias comment block, inside the module tags.

Change your document root

  1. Edit ~line 176 in C:\xampp\apache\conf\httpd.conf; change DocumentRoot "C:/xampp/htdocs" to #DocumentRoot "C:/Projects" (or whatever you want).
  2. Edit ~line 203 to match your new location (in this case C:/Projects).

Notes:
  • You have to use forward slashes "/" instead of back slashes "\".
  • Don't include the trailing "/" at the end.
  • restart your server.






READ MORE
SHARE :

Search This Blog

Followers

  • Popular
  • Recent
  • Comments
    How to get Real IP,ISP,Country,City and etc from Visitor using PHP
    Get first key in a (possibly) associative array?
    Solved : curl_init() function not working in Ubuntu
    Does finally always execute in Java?
    Serving XHTML and self-closing tags
    How can I make the cursor a hand when a user hovers over a list item?
    How to efficiently iterate over each Entry in a Map?
    Window clearTimeout() Method
    Why does this code using random strings print “hello world”?
    How to check whether a checkbox is checked in jQuery?

Instagram

About

Popular Posts

  • How to get Real IP,ISP,Country,City and etc from Visitor using PHP
    How to get Real IP,ISP,Country,City and etc from Visitor using PHP Php Get Real visiter's IP and ISP and Country and City and Countr...
  • Get first key in a (possibly) associative array?
    Get first key in a (possibly) associative array? What's the best way to determine the first key in a possibly associative array? My...
  • Solved : curl_init() function not working in Ubuntu
    Solved : curl_init() function not working in Ubuntu  Here solved the error  Fatal error: Call to undefined function curl_init() ...
  • Does finally always execute in Java?
    Does finally always execute in Java? I have a try/catch block with  return s inside it. Will the finally block be called? For example...
  • Serving XHTML and self-closing tags
    Serving XHTML and self-closing tags I am trying to follow the xhtml 1.0 strict standard as I am creating my website. Right now, validat...
  • How can I make the cursor a hand when a user hovers over a list item?
    How can I make the cursor a hand when a user hovers over a list item? I've got a list, and I have a click handler for its items: ...
  • How to efficiently iterate over each Entry in a Map?
    How to efficiently iterate over each Entry in a Map? If I have an object implementing the  Map  interface in Java and I wish to iterate...
  • Window clearTimeout() Method
    Window clearTimeout() Method Definition and Usage The clearTimeout() method clears a timer set with the setTimeout() method. ...
  • Why does this code using random strings print “hello world”?
    Why does this code using random strings print “hello world”? The following print statement would print "hello world". Could a...
  • How to check whether a checkbox is checked in jQuery?
    How to check whether a checkbox is checked in jQuery? I need to check the  checked  property of a checkbox and perform an action based ...

statcounter



statcounter



Template Created By ThemeXpose & Blogger Templates