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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
08-16-2012, 12:33 AM
|
#1
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Rep:
|
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
|
|
|
08-16-2012, 01:56 AM
|
#2
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
|
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
|
|
|
08-16-2012, 02:36 AM
|
#3
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep:
|
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
|
|
|
08-16-2012, 02:42 AM
|
#4
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
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.
|
|
|
08-16-2012, 02:54 AM
|
#5
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
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.
|
|
|
08-16-2012, 03:14 AM
|
#6
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep:
|
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
|
|
|
08-16-2012, 04:04 AM
|
#7
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
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.
|
|
|
08-20-2012, 02:11 AM
|
#8
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep:
|
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
|
|
|
08-20-2012, 05:23 AM
|
#9
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
Quote:
Originally Posted by arpitr
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.
|
08-20-2012, 01:08 PM
|
#10
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep:
|
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.
|
|
|
08-20-2012, 08:42 PM
|
#11
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,398
|
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.
|
|
|
All times are GMT -5. The time now is 10:18 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|