Solved

Virtual hosts not workiing on Apache

Posted on 2008-06-12
9
604 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
  • 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now