Current location: Hot Scripts Forums » Other Discussions » Web Servers » Xampp - Changing the word 'localhost'?


Xampp - Changing the word 'localhost'?

Reply
  #1 (permalink)  
Old 04-27-08, 07:57 PM
phpdoctor's Avatar
phpdoctor phpdoctor is offline
Code Guru
 
Join Date: Feb 2007
Location: New Zealand
Posts: 767
Thanks: 4
Thanked 2 Times in 2 Posts
Xampp - Changing the word 'localhost'?

Ok, Is it possible to make a localhost like this:
http://test_site/ just like http://localhost

except the base url is a different folder...?
http://test_site base could be http://localhost/www/test_site/

Get what im saying? lol

Thanks,
Lex
__________________
01010000 01001000 01010000
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-28-08, 08:32 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
Not sure about other OS's, but if you're running Windows, localhost is just an alias for the IP Address. So, open this file:

Windows / system32 / drivers / etc / hosts

Modify the line that mentions localhost, and replace localhost with whatever you'd like

Code:
127.0.0.1      yourdomain.com
That'll do the trick.
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison

Last edited by therocket954; 04-28-08 at 08:35 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-28-08, 04:38 PM
phpdoctor's Avatar
phpdoctor phpdoctor is offline
Code Guru
 
Join Date: Feb 2007
Location: New Zealand
Posts: 767
Thanks: 4
Thanked 2 Times in 2 Posts
mmm ok, i cant find that file lol... whats it called?
so, can i make an alias to a different folder on 127.0.0.1?

Thanks for your help!
Lex
__________________
01010000 01001000 01010000
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-28-08, 05:08 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
To get different folders to correspond to different "domain" names, you need to use name based virtual hosts. The first link below shows how to do this in general. The second link contains an example of doing this on a development system, using the "hosts" file to make your computer look like it is hosting any "domain" name (you can use anything, such as test_site or www.test_site as a name). If the hosts file does not exist, you need to create it.

http://httpd.apache.org/docs/2.0/vhosts/examples.html

http://www.caucho.com/resin/doc/virtual-host.xtp
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???

Last edited by mab; 04-28-08 at 07:36 PM. Reason: proof read and fixed wording
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-28-08, 07:29 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
I did not find a recent example in our Forum for doing this, so here is something I threw together -

Here is a working example using Apache virtual hosts on a Windows development system. This assumes existing Apache settings are the installation defaults for installing Apache directly using the Windows installer and Apache works for http://localhost You will need to adapt your paths as needed for any other type of Apache installation.

The existing "localhost" will remain mapped to the existing folder (on my system this is) -
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

This example will add a "domain" www.example1.com (and example1.com) that will be mapped to a folder -
C:\Program Files\Apache Software Foundation\Apache2.2\example1\htdocs

This could be to any folder. I picked one that starts in the Apache2.2 main folder.

Note: In all the following code blocks, examplel is actually example1


Step 1:

Near the end of your httpd.conf, there is a line to include a httpd-vhosts.conf file -

Code:
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
Remove the # in front of the second line to cause httpd.conf to read the contents of conf/extra/httpd-vhosts.conf

Step 2:

In Windows, navigate to C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra and make a copy of the existing httpd-vhosts.conf file.

Edit httpd-vhosts.conf to contain the following -

Code:
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>

# These settings allow localhost to work using virtual hosts with the existing htdocs folder

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
ServerName localhost

# Other directives here


</VirtualHost>

<VirtualHost *:80>

# These settings add a virtual host for www.example1.com (and example1.com)

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/example1/htdocs"
ServerName example1.com
ServerAlias www.example1.com

# The following directives are a copy of the settings found in httpd.conf

<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/example1/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

</VirtualHost>
Step 3:

Find or create the file C:\WINDOWS\system32\drivers\etc\hosts

The hosts file should have the following lines to work with this example -

Code:
127.0.0.1       localhost
127.0.0.1       www.example1.com
127.0.0.1       example1.com
Step 4:

Stop and start your web server to get these changes to the .conf files to take effect.

Going to http://localhost should get your existing web documents

Going to http://example1.com or http://www.example1.com should get your web documents in the new example1/htdocs folder.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???

Last edited by mab; 04-28-08 at 07:52 PM. Reason: Cleanup
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-28-08, 11:14 PM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
Quote:
Originally Posted by phpdoctor View Post
mmm ok, i cant find that file lol... whats it called?
so, can i make an alias to a different folder on 127.0.0.1?

Thanks for your help!
Lex

It's just called hosts. There's no file extension, so open it with notepad, or your basic text editor of choice.

If Windows is installed in the default directory the exact path is:

C:\Windows\system32\Drivers\etc\hosts
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 04-28-08, 11:15 PM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
oops... didn't read close enough... but yeah... Mab pegged it in step 3.
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 04-28-08, 11:51 PM
phpdoctor's Avatar
phpdoctor phpdoctor is offline
Code Guru
 
Join Date: Feb 2007
Location: New Zealand
Posts: 767
Thanks: 4
Thanked 2 Times in 2 Posts
Wow Mab, Il give it a go later... thanks for the tutorial! it looks awesome.

Lex
__________________
01010000 01001000 01010000
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 05-03-08, 08:17 AM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
I knwo this should be another post but since you guys are talking about xampp.

I just installed it on my local machine and I load localhost it works. But when I creatd a folder inside htdocs it doesn't show that folder. Any idea why?
__________________
Can you think outside the box but remain inside the box?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 05-03-08, 08:22 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Do you have an .htaccess file in that folder? 'Cause the same happens to me if I newly install XAMPP.

If so, open /apache/conf/httpd.conf

And uncomment this line:
Code:
LoadModule rewrite_module modules/mod_rewrite.so
... save, and then restart Apache.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP variables to microsoft word Deansatch PHP 7 12-17-07 03:21 PM
Writing the values to Word Document superprogrammer ASP.NET 1 05-04-07 08:56 PM
multi value hashtable minority ASP.NET 1 03-01-06 09:37 AM
Telephone Word Generator necro_mancer C/C++ 4 09-07-05 05:01 PM
Find the beginning letter of a word mcrob PHP 6 05-23-05 11:06 AM


All times are GMT -5. The time now is 09:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.