LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-16-2012, 12:33 AM   #1
arpitr
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Rep: Reputation: Disabled
localhost pointing to last configured site on local


I am using ubuntu 10.04. My localhost points to the last configured website.If I try accessing localhost ,the web browser opens the last website I have configured on apache.

My virtual host settings inside /etc/apache/sites-available goes like this

NameVirtualHost 127.0.0.1:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

Due to this I'm not able to access any php file directly ,I have to first make a host entry for any new php script and then have to create a virtual host entry.I'm gettin no clew about the problem
 
Old 08-16-2012, 01:56 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Hi,
Quote:
Due to this I'm not able to access any php file directly ,I have to first make a host entry for any new php script and then have to create a virtual host entry.I'm gettin no clew about the problem
I don't understand what you mean by that, but I can see that you have a couple of errors in your vhost configuration:
1 You need to use:
Code:
NameVirtualHost *:80
2 You don't have a ServerName and/or ServerAlias inside the vhost definition. So add
Code:
ServerName localhost
inside <VirtualHost *:80>...</VirtualHost>

Regards
 
Old 08-16-2012, 02:36 AM   #3
arpitr
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi bathory
thanks for the reply

By "Due to this I'm not able to access any php file directly ,I have to first make a host entry for any new php script and then have to create a virtual host entry.I'm gettin no clew about the problem "
I mean if I put a php file lets say abc.php inside /var/www/abc.php and try to open it from browser with access path localhost/abc.php ,the php file doesn't execute rather the last configured website on local opens up

As you suggested I hav change the virtual host file to


NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

and on restarting apache there shows a warning
"directive
[Thu Aug 16 13:05:35 2012] [warn] VirtualHost 127.0.0.1:80 overlaps with VirtualHost 127.0.0.1:80, the first has precedence, perhaps you need a NameVirtualHost "

and the problem still continues
 
Old 08-16-2012, 02:42 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Due to this I'm not able to access any php file directly ,I have to first make a host entry for any new php script and then have to create a virtual host entry.I'm gettin no clew about the problem
That is how it's supposed to work. Create a new virtualhost (and set the ServerName directive as indicated by bathory) in /etc/apache2/sites-available, enable it with a2ensite (so apache knows about it), add the domain to /etc/hosts (so your browser can resolve the name) and you're ready to go with http://site1 and http://site2

If you don't want that, you should not use virtual hosts and design all sites under the document root (default /var/www) like shown below.

Code:
/var/www
  |
  +-- site1
  |     |
  |     +-- index.html
  |     +-- someotherfile.php
  |
  +-- site2
  |     |
  |     +-- index.html
  |     +-- someotherfile.html
and access them via http://localhost/site1/ and http://localhost/site2/

Last edited by Wim Sturkenboom; 08-16-2012 at 02:57 AM.
 
Old 08-16-2012, 02:54 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
After your second post in this thread

This is the default site (access via http://localhost) in ubuntu; configuration /etc/apache2/sites-available/default
Code:
<VirtualHost *:80>
	ServerAdmin webmaster@localhost

	DocumentRoot /var/www
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
#		Options FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>
	<Directory /var/www/testje>
		Options FollowSymLinks MultiViews
	</Directory>

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	<Directory "/usr/lib/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
		Order allow,deny
		Allow from all
	</Directory>

	ErrorLog /var/log/apache2/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

This is a new site that I have added; configuration /etc/apache2/sites-available/mynewsite
Code:
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName mynewsite

	DocumentRoot /home/wim
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /home/wim/>
		Options Indexes FollowSymLinks MultiViews
#		Options FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	<Directory "/usr/lib/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
		Order allow,deny
		Allow from all
	</Directory>

	ErrorLog /var/log/apache2/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
If you use a servername that is defined in the virtual host configuration (and the browser can resolve it), you will be taken to that site.
If you use a servername that is not defined in any virtual host configuration, apache will fall back to a default (the one that does not have a servername directive).

So with above example (assuming the browser can resolve the names to 127.0.0.1)
http://localhost will take you to the default site
http://somesite will take you to the default site (as somesite is not configured in virtualhosts)
http://mynewsite will take you to mynewsite


Please note that the files for mynewsite reside in /home/wim and not in /var/www

Last edited by Wim Sturkenboom; 08-16-2012 at 02:59 AM.
 
Old 08-16-2012, 03:14 AM   #6
arpitr
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi Wim Sturkenboom
Thanks for the quick reply

Here is an example of a vhost for a new site I have setup on local
I have created this as separate vhost entry inside /etc/apache/sites-available
and have enabled the site by sudo ln -s /etc/apache/site-enable which I guess is equivalent to sudo a2ensite sitename
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/newProject/drupal_openid
ServerName drupal_openid
</VirtualHost>

I'm able to access this site simply by http://drupal_openid
but I wish if I can access the same by http://localhost/drupal_openid also

here is a look for my default vhost

NameVirtualHost 127.0.0.1:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

When I made the changes as bathory suggested i.e. NameVirtualHost *:80 and added ServerName localhost then the problem continues and also the other sites on local with separate vhosts stopped working
 
Old 08-16-2012, 04:04 AM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
You need to create a symbolic link in the website that is used by local host. For my example, I created a symbolic link to /home/wim in /var/www

Code:
cd /var/www
sudo ln -s /home/wim mynewsite
after which I can access it in a browser using http://localhost/mynewsite

My feeling tells me that this however might not always work properly; you are now using 'localhost' as the domain and not 'mynewsite'. So something like $_SERVER['DOCUMENT_ROOT'] (in PHP) will return something different in the two scenarios; session variables are now going to be shared between pseudo-sites which might also not be what you want.

I don't know if there is another solution, and to me your requirement actually does not really make sense.
 
Old 08-20-2012, 02:11 AM   #8
arpitr
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi
In other words when I try to access http://localhost I don't get It works rather I get a website opened which is configured on local with a separate virtualHost entry.I hope it make sense.
Thanks
 
Old 08-20-2012, 05:23 AM   #9
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by arpitr View Post
Hi
...I hope it make sense.
Not quite

You have configured a virtual host but want to access is using localhost? That will only work if your localhost configuration uses the documentroot of your virtualhost configuration.

But what will you do with a second, third, fourth, ... virtualhost? You can't let localhost use all those documentroots in one go.

It also defeats the objects of virtualhosts. What is the problem accessing sites with

http://localhost
http://myfirstdrupalsite
http://myotherdrupalsite

etc?

Last edited by Wim Sturkenboom; 08-20-2012 at 05:26 AM.
 
1 members found this post helpful.
Old 08-20-2012, 01:08 PM   #10
arpitr
LQ Newbie
 
Registered: Jul 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi
Only thin which bothers me most is that every time I need to test a website on my local I have to go through long procedure of making vhost entry, though its not that much long but still. I wish if I could simply put my website inside /var/www/mywebite and can access it by http://localhost/mywebsite ,as I already said as of now if try to access with the mentioned url, wht I get is someother site which has separate vhost entry.Earlier when I had installed apache things used to work the way I want, but since I tried making new vhosts I'm facing this problem.
 
Old 08-20-2012, 08:42 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,398

Rep: Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780Reputation: 2780
Are you confusing website (contains 1 or more(!) pages/php scripts) with a single webpage/php script?
In any case, if you want a std test area; create that as your first vhost site and then just add/remove pages/scripts from that area; no need to keep creating new vhosts.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is my website pointing to my local lan ip address jmzcons Linux - Newbie 17 07-21-2012 04:22 AM
[SOLVED] Enabling ssl with only one domain pointing to site duceduc Linux - Newbie 8 09-07-2010 06:00 AM
Localhost pointing to default page if I don't specify the port number in the address rajaoLQ Linux - Server 6 08-24-2009 02:52 PM
Can sunrpc be configured to listen only to localhost? Robhogg Linux - Security 3 03-02-2006 06:37 PM
pointing browser to localhost??? asiatrek Linux - Networking 2 05-22-2002 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration