Solved

Virtual hosts not workiing on Apache

Posted on 2008-06-12
9
608 Views
Last Modified: 2013-12-06
Hi,

We have one production server which hosts a dozen or so domains, some of which have many subdomains.

This server is running PHP4 and I want to upgrade it to PHP5. To make sure there are no problems doing so, I want to copy the existing sites onto a development server set up with PHP5 and start debugging that.

I've got the server set up with Debian (same as the live server) and have installed the latest stable versions of PHP/MYSQL on it.

After consulting a more server-savvy friend it was suggested that I:
   * Copy across the contents of /etc/apache2/sites-available
   * Copy across the website place to the same location on thh new server
   * Point the relevent domains to the new server's IP in my hosts file

So I attemted this for a single domain and the first problem encountered was that, other than a file called 'default', there was nothing in my sites-available folder on the live server.

These domains were originally set up using Plesk which seems to have a different way of managing vhosts. Looking in /var/www/vhosts/example.com/conf there is a file called httpd.include which seemed to contain the required information (attached), so I tried copying this to sites-available and disabling 'default'.

I've restarted apache, and tried to access the URL in my browser and it just takes lists the contents of /var/www instead of showing the

As you can tell, I'm no server expert - I'm a programmer - so I'm not entirely sure what I'm doing!

Any help would be much appreciated!
NameVirtualHost *:80
 
<VirtualHost *:80>
	ServerName   example.com
	ServerAlias  www.example.com
	UseCanonicalName Off
	ServerAdmin  "exampel@example.com"
	DocumentRoot /var/www/vhosts/example.com/httpdocs
	CustomLog  /var/www/vhosts/example.com/statistics/logs/access_log plesklog
	ErrorLog  /var/www/vhosts/example.com/statistics/logs/error_log
<IfModule mod_userdir.c>
	UserDir /var/www/vhosts/example.com/web_users
</IfModule>
	ScriptAlias  /cgi-bin/ /var/www/vhosts/example.com/cgi-bin/
	Alias  /plesk-stat /var/www/vhosts/example.com/statistics/
	<Location  /plesk-stat/>
		Options +Indexes
	</Location>
	<Location  /plesk-stat/logs/>
		Require valid-user
	</Location>
	Alias  /webstat /var/www/vhosts/example.com/statistics/webstat
	Alias  /webstat-ssl /var/www/vhosts/example.com/statistics/webstat-ssl
	Alias  /ftpstat /var/www/vhosts/example.com/statistics/ftpstat
	Alias  /anon_ftpstat /var/www/vhosts/example.com/statistics/anon_ftpstat
	Alias  /awstats-icon /usr/share/awstats/icon
	<IfModule mod_ssl.c>
		SSLEngine off
	</IfModule>
	<Directory /var/www/vhosts/example.com/httpdocs>
	<IfModule mod_perl.c>
	<Files ~ (\.pl$)>
		SetHandler perl-script
		PerlHandler ModPerl::Registry
		Options ExecCGI
		allow from all
		PerlSendHeader On
	</Files>
	</IfModule>
	<IfModule mod_php4.c>
		php_admin_flag engine on
		php_admin_flag safe_mode off
		php_admin_value open_basedir "/var/www/vhosts/example.com/httpdocs:/tmp"
	</IfModule>
	<IfModule mod_php5.c>
		php_admin_flag engine on
		php_admin_flag safe_mode off
		php_admin_value open_basedir "/var/www/vhosts/example.com/httpdocs:/tmp"
	</IfModule>
	<IfModule mod_python.c>
	<Files ~ (\.py$)>
		SetHandler python-program
		PythonHandler	mod_python.cgihandler
	</Files>
	</IfModule>
		Options -Includes +ExecCGI
	</Directory>
	<Directory /var/www/vhosts/example.com/web_users>
	<IfModule mod_php4.c>
		php_admin_flag engine off
	</IfModule>
	<IfModule mod_php5.c>
		php_admin_flag engine off
	</IfModule>
	</Directory>
</VirtualHost>

Open in new window

0
Comment
Question by:Office-Shadow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 29

Expert Comment

by:fosiul01
ID: 21769683
Hi yah

the Vhosts file should be in /etc/httpd/conf

and file called vhosts

I am attaching my vhosts, try to follow , hopefully it will work.

you will have to type your document path like this :  DocumentRoot /var/www/html/intranet

but in your vhosts file i am seeing like this : DocumentRoot /var/www/vhosts/example.com/httpdocs
I dont think, you have vhosts folder under your www folder

anyway, see my vhosts configuration, if it help you

First virtual host is a copy of the main server configuration
# since in the absence of a host name, the first virtualhost applies
 
<VirtualHost *:80>
       ServerAdmin root@localhost
       ServerName Myserver
       DocumentRoot "/var/www/html"
       <Directory />
               Options FollowSymLinks
               AllowOverride None
       </Directory>
       <Directory "/var/www/html">
                       Options Indexes FollowSymLinks
                       AllowOverride None
                       Order allow,deny
                       Allow from all
       </Directory>
       Alias /icons/ "/var/www/icons/"
       <Directory "/var/www/icons">
                       Options Indexes MultiViews
                       AllowOverride None
                       Order allow,deny
                       Allow from all
       </Directory>
       ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
       <Directory "/var/www/cgi-bin">
                       AllowOverride None
                       Options None
                       Order allow,deny
                       Allow from all
       </Directory>
</VirtualHost>
 
 
<VirtualHost *:80>
       DocumentRoot /var/www/html
       ServerAdmin root@localhost
       ServerName bvhelp.myserver.local
       ServerAlias bvhelp
       Options FollowSymLinks
       DirectoryIndex /cgi-bin/viewhtml.pl
       <FilesMatch "\.(MAN|WHP|HCP|MCP|TRE|HLP|FLG|RS)$">
               ErrorDocument 404 /cgi-bin/viewhtml.pl
       </FilesMatch>
</VirtualHost>
 
<VirtualHost *:80>
       DocumentRoot /var/www/html/reports
       ServerAdmin it@myserver.com
       ServerName reports.myserver.local  ServerAlias
reports.myserver.local     ServerAlias
reports
 
       <Directory />
               AllowOverride None
       </Directory>
 
       DirectoryIndex index.html
       AccessFileName .htaccess
       ServerSignature On
       ScriptAlias /cgi-bin/ "/var/www/html/reports/cgi-bin/"
 
       <Directory "/var/www/html/reports/cgi-bin/">
               AllowOverride None
               Options None
               Order Allow,Deny
               Allow from all
       </Directory>
 
       Addhandler cgi-script .cgi
       SetEnv LANG en_GB
</VirtualHost>
 
<VirtualHost *:80>
       DocumentRoot /var/www/html/intranet
       ServerAdmin it@myserver.com
       ServerName owl.myserver.local
       ServerAlias owl
       ServerAlias owl.myserver.local
</VirtualHost>
 
 
<VirtualHost *:80>
DocumentRoot /var/www/html/development
ServerAdmin it@myserver.com
ServerName developer.myserver.local
ServerAlias developer.myserver.local
ServerAlias developer
       <Directory "/var/www/html/development">
       Order Allow,Deny
       Allow from all
       </Directory>
 
       <Directory "/var/www/html/dev/internal">
       Order Deny,Allow
       Deny from all
       Allow from 193.XXX.XXX
       </Directory>
</VirtualHost>
 
 
 
 
</VirtualHost>

Open in new window

0
 
LVL 2

Author Comment

by:Office-Shadow
ID: 21778911
Thanks fosiul, but I'm really not sure what I'd need to change from your vhosts file.

As an update, I have tried starting again and followed this guide exactly: http://www.debuntu.org/2006/02/22/7-virtual-hosting-using-apache-2

I still had the same result of listing the /var/www/ contents.

Any more suggestions
0
 
LVL 29

Expert Comment

by:fosiul01
ID: 21779760
HI  yah, they way your tutorial described, i did different way.
i didnot had to create any file called dev.example.com

give little bit of time, i need to see little bit of more configuration in myserver. as i am out of office
i will do that tomorrow morning
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 29

Assisted Solution

by:fosiul01
fosiul01 earned 200 total points
ID: 21779798
quick question :
in your httpd.conf , did you enable this line

Include /etc/httpd/conf/vhosts

without enabling this line, virtual host concept will not work
0
 
LVL 2

Author Comment

by:Office-Shadow
ID: 21780034
Hiya, no I do not have that line because I do not have a file at /etc/httpd/conf/vhosts
0
 
LVL 29

Assisted Solution

by:fosiul01
fosiul01 earned 200 total points
ID: 21780353
are  you using linux or anything else ??

if you are using Red hat or Centos or even Fedora, you should have a file called httpd.conf

and in httpd.conf you will have to mention where is your vhosts file which is by this line etc/httpd/conf/vhosts

and in vhosts file you will have to configure your document root file

now telll me which linux you are using??
0
 
LVL 2

Author Comment

by:Office-Shadow
ID: 21780497
I'm running Debian linux.

I have a couple different httpd.conf's:

/etc/apache2/httpd.conf - this one is blank
/etc/apache/httpd.conf - the last line of this is 'Include /etc/apache/conf.d', which is an empty directory.
0
 
LVL 2

Accepted Solution

by:
Office-Shadow earned 0 total points
ID: 21780531
What it looks like to me is that I have apache and apache2 installed, and I've been configuring apache2 - however it is apache that is actually running!

How do I disable apache and run apache2 instead?
0
 
LVL 2

Author Comment

by:Office-Shadow
ID: 21780599
Yes that was the problem, I've now disabled apache and started apache and have got my vhost working! thanks for your help fosiul01
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question