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 |
Hi,
Quote:
1 You need to use: Code:
NameVirtualHost *:80 Code:
ServerName localhost Regards |
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 |
Quote:
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 |
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> This is a new site that I have added; configuration /etc/apache2/sites-available/mynewsite Code:
<VirtualHost *:80> 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 |
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 |
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 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. |
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 |
Quote:
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? |
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. |
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 11:59 PM. |