Make Xampp/Apache Serve File Outside of Htdocs Folder

Make XAMPP / Apache serve file outside of htdocs folder

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.

how to configuring a xampp web server for different root directory

You can change Apaches httpd.conf by clicking (in xampp control panel) apache/conf/httpd.conf and adjust the entries for DocumentRoot and the corresponding Directory entry.
Just Ctrl+F for "htdocs" and change the entries to your new path.

See screenshot:

XAMPP config

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">

How to browse to website outside of htdocs from remote computer

Solution by OP.

To accomplish my goal of accessing the pages from a remote computer I had to use the command mklink /J. The example below created a directory named 'my' in my 'htdocs' linking to everything on my 'E:' drive.

    mklink /J C:\xampp\htdocs\my E:

The only thing I don't like about it is that in order to view the webpage in E:/me, I have to type the URL example.com/my/me instead of example.com/me. I know it's not a big deal having to type the extra directory 'my' in the URL, but I just don't like the look of it. Also this negates the need to add 'VirtualHosts' and 'mapping'; although, I may have to do that anyway with '.htaccess' to keep users from accessing directories other than theirs.

XAMPP pointing a file outside root folder

It was chmod problem. I tried giving chmod -r 777 to Development folder, backbone folder and Backboneboilerplate.. It worked.

access xampp/htdocs from outside

You need a virtual host in Apache, that listens to at least the given IP (192.168.1.210:80) or to any IP (*:80):

<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/some_app
</VirtualHost>

See: http://httpd.apache.org/docs/2.2/vhosts/examples.html

Please don't edit the httpd.conf, as the changes might get lost on the next software update. You need to create a vHost inside the site-available in den XAMPP/Apache folder.

XAMPP - PHP Going Outside Main Site Folder

Ok. I propose you a solution. Create a VirtualHost in your xampp, and this will probably fix your problem.

In you xampp\apache\conf\extra\httpd-vhosts.conf, add this :

<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/Testing
ServerName www.testing.com
</VirtualHost>

Now, in your C:\WINDOWS\system32\drivers\etc\ Open the "hosts" file :

127.0.0.1       www.testing.com

Finally, in your C:\xampp\apache\conf\httpd.conf, scroll to the line VirtualHost and it should look like this :

#Virtual hosts
Include conf/extra/httpd-vhosts.conf

Change your css for this :

<link rel="stylesheet" href="/css/styles.css">

Restart your xampp server, and go to www.testing.com in your browser.

Enjoy it !



Related Topics



Leave a reply



Submit