LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   localhost pointing to last configured site on local (https://www.linuxquestions.org/questions/linux-newbie-8/localhost-pointing-to-last-configured-site-on-local-4175422334/)

arpitr 08-16-2012 12:33 AM

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

bathory 08-16-2012 01:56 AM

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

arpitr 08-16-2012 02:36 AM

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

Wim Sturkenboom 08-16-2012 02:42 AM

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/

Wim Sturkenboom 08-16-2012 02:54 AM

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

arpitr 08-16-2012 03:14 AM

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

Wim Sturkenboom 08-16-2012 04:04 AM

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.

arpitr 08-20-2012 02:11 AM

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

Wim Sturkenboom 08-20-2012 05:23 AM

Quote:

Originally Posted by arpitr (Post 4758822)
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?

arpitr 08-20-2012 01:08 PM

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.

chrism01 08-20-2012 08:42 PM

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.