WAMP Virtual Host not working

I’m trying to setup wamp to work locally with 3 virtual hosts and I can’t even get the first one to work properly. I’ve modified the hosts file in windows and it currently points to the wamp index directory. I can’t get it to forward to /domain

I’m hoping I’m just doing something really stupid, I followed the guide here: http://www.dennisplucinik.com/blog/2007/08/16/setting-up-multiple-virtual-hosts-in-wamp/

but something is still not working right.

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
NameVirtualHost *:80

<VirtualHost 127.0.0.1>
	ServerName localhost
	DocumentRoot "c:/wamp/www/"
	<Directory "c:/wamp/www/">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1> // I've tried both the IP and the *:80
	ServerName domain.loc
	DocumentRoot "c:/wamp/www/domain/"
	<Directory "c:/wamp/www/domain/">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

According to this virtualhost tutorial that I followed today:
http://apptools.com/phptools/virtualhost.php

Bad


DocumentRoot "c:/wamp/www/"

Good


DocumentRoot c:\\wamp\\www\\

Because Windows uses \ characters and Linux uses / characters for file paths.
Because whenever there’s no SPACE character in the file path you shouldn’t use " characters in the DocRoot.

Bad


DocumentRoot c:\\Program Files\\wamp\\www\\

Good


DocumentRoot "c:\\Program Files\\wamp\\www\\"

Because whenever there’s a SPACE character in the file path you should use " characters in the DocRoot.

By the way I’m no Apache expert yet I’m also a learner like you, so I might be wrong with a few details. :slight_smile:

1 Like

webnet,

First, you MUST edit the httpd.conf to remove the # from the include line for httpd-vhosts.conf.

In the vhosts file, (I don’t understand why you’d use AllowOverride None so you’d then have to use AllowOverride All in each local domain) be sure to use 127.0.0.1:80 in the declaration. As for whether to use \ or /, ALWAYS USE / (Apache knows which OS it’s using and will make that conversion for you)! Additionally, as kons said, you only need to use quotes if you have a space in your path.

TIP: I use my domain names (or an abbreviation) without the .tld because that allows easy testing when I need to compare/limit access to one domain or another.

WAMP? What have you learned by using a canned installation program (except that it doesn’t work for you)? IMHO, use Kevin Yank’s book (the FREE Chapter One) for instructions and install each daemon the way YOU want to install it. That way, you don’t need to wait for the canned creator to decide to update AND you can mix and match to mirror your host’s setup.

kons,

Actually, webnet’s (path) code was correct and yours was not (see above about the / vs \). Your info about quotes was correct, though!

Regards,

DK

I’ve tried with and without quotes, also tried enabling the httpd-vhosts and doing it through there which had no effect. It’s pointing to localhost so it’s just the apache that’s not working, right?

<VirtualHost 127.0.0.1:80>
    DocumentRoot "C:/wamp/www/domain"
    ServerName domain.loc
</VirtualHost>

dklynn, from what I’m seeing I an EITHER use httpd-vhosts OR the httpd with wamp. I’ve tried both and neither is working.

webnet,

I don’t know whether WAMP includes an httpd-vhosts.conf file or not. As far as I’m concerned, if you have the <VirtualHost> section in httpd.conf (Apache 1.x style), that’s fine. Apache 2.x style httpd-vhosts.conf is good, too.

Did you update your hosts file for the virtual hosts you’ve setup?

Regards,

DK

yes the hosts file is updated. That’s how it’s pointing to my “localhost” which is why I know it’s apache not functioning. It’s registered as a local virtual server, but it’s just not forwarding to the right directory.
WAMP does come with default apache directories/files from what I can tell. It has a vhosts file which I attempted to work with in the same ways I’ve worked with the wamp config file.

webnet,

Okay, what I’ve got inside my TEST SERVER’s files:

httpd.conf:

Include conf/extra/httpd-vhosts.conf

httpd-vhosts.conf:

[indent]<VirtualHost *:80>
ServerName dk
DocumentRoot W:/datakoncepts
ServerPath W:/datakoncepts
</VirtualHost>[/indent]
hosts:

127.0.0.1 dk

That’s all there is to it! I can then access the files there with http://dk/.

FWIW, I have always installed (and, thus, recommend) my daemons from the creators, NOT from a “canned” solution (like WAMP or XAAMP or …).

Regards,

DK

This might be a little off topic but here it goes. I’ve always thought that these were pick and choose solutions.

LAMP = Linux Apache MySQL PHP
WAMP = Windows Apache MySQL PHP

So when you guys talk about WAMP as a canned package you mean WampServer right?
Because you guys make my CV cry and then I have to change it (:

kons,

There are ‘induhviduals’ who create a package to install all the elements of a web server in one package - usually for WinDoze. I know that people have come here for help with XAAMP (a WAMP package) but, IMHO, you’re far better off downloading and installing the different packages yourself.

Yes, LAMP is the Linux flavor of Apache, MySQL and PHP while WAMP is the WinDoze flavor.

Regards,

DK

I guess I’ll just give up and set it all up on the server once we go live or something. I can’t get it to work even with your configuration…

It took me around 5 months to find out how to properly install LAMP on Ubuntu but now that I know.

And now when I’ve figured out howto install WAMP properly. I must say installing LAMP is less work compared to installing WAMP.

Just a few CLI commands in terminal and your’re done.
But then getting used to the permission file system on Linux is a headache for Linux beginners.

Still staying away from canned packages like XAMMP is going to save yourself from headaches down the road. Packages like that add uneccessary complexity that’s going to slow you down more than help you.

… all you do is install wamp and run it. How can it get any easier?

Webnet,

If you’re STILL having problems, how can it get any harder? kons has the right idea - install from the creator’s scripts and make the appropriate adjustments to the config files and you’re set for life.

Regards,

DK


Ctrl + Alt + T (Opens up terminal)

$ sudo apt-get remove apache* libapache* php* mysql-common mysql-server

$ sudo aptitude install apache2 php5-mysql libapache2-mod-php5 mysql-server

Then you have a standard Apache, MySQL, PHP setup. No need to chase for peculiar solutions when dealing with packages like XAAMP when you need to configure things.
I haven’t tested Wampserver before but I got a distaste for canned non-standard packages when they (XAAMP) didn’t do things like standard servers.

Still like I said it’s much more comfortable installing standard LAMP than standard WAMP for the cost of having to learn the troublesome permission file system on Linux as a beginner.

And this is what I have to go through in Windows when I’m not sitting on Linux.
Minus the Virtualhost, DNS, PHP & MySQL testing. It’s just to much work compared to Linux.

[ Apache 2.2 ]

1. Install Apache Server
http://httpd.apache.org/download.cgi

2. Stop Apache Server
Click on the icon next to the clock to get a menu.

3. Configuring Apache Virtualhost
http://apptools.com/phptools/virtualhost.php

C:\Program Files\Apache Group\Apache\conf\httpd.conf

Uncomment this line in httpd.conf:

Include conf/extra/httpd-vhosts.conf

4. Security
Add this block to the httpd-vhosts.conf file:

<Directory “C:/My Sites”>
Order Deny,Allow
Allow from all
</Directory>

5. Creating virtual hosts
Put these below the security block from previous step in the httpd-vhosts.conf file:


NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
   DocumentRoot "C:/My Sites/Site1"
   ServerName site1.local
</VirtualHost>

<VirtualHost 127.0.0.1>
   DocumentRoot "C:/My Sites/Site2"
   ServerName site2.local
</VirtualHost>

If your file path look like this then don’t use quotation marks ( " ).

DocumentRoot C:\\MySites\\Site1

6. Resolving the DNS issue

Edit either of these file paths:

C:\\WINNT\\system32\\drivers\\etc\\hosts
		or
C:\\Windows\\system32\\drivers\\etc\\hosts

Just go to the bottom of the file, below all the comments and any existing
entries and add the following two lines:

127.0.0.1 site1.local
127.0.0.1 site2.local

7. Fixing default localhost after creating virtualhost

Okay, now I’ll mention one very small, but possibly important, caveat.
When you create the virtual hosts like this, the default http://localhost will no longer work.

In many cases, that is unimportant. However, if you’re using something like phpMyAdmin,
you’ll still need it. The solution to that is to create one additional virtual host called “localhost”
that points to the original Apache htdocs folder. It might look something like this:

<VirtualHost 127.0.0.1>
   DocumentRoot C:\\Apache\\htdocs
   ServerName localhost
</VirtualHost>

Don’t forget to include that additional virtual host when you edit the Windows hosts file.

[ MySQL ]

8. Remove old or bad MySQL installation
Improvise!

9. Install MySQL Server

Setup Type: Custom

10. MySQL Server Instance Configuration Wizard

Detailed Configuration
Developer Machine
Multifunctional Database
Select InnoDB Tablespace Settings: Keep default values.
Decision Support (DSS)/OLAP

Select Networking options:
					Enable TCP/IP Networking
					Port number 3306
					Enable Strict Mode

Standard Character Set

Select Windows options:
					Install as Windows Service
					Service Name: MySQL
					Launch the MySQL Server automatically
					Include Bin Directory in Windows PATH

Then finish the install.

11. Testing the MySQL installation

START> Run> cmd


C:\\> mysqladmin -u root -p ping
C:\\> mysqladmin -u root -p version
C:\\> mysqladmin -u root -p status

C:\\> mysqlshow -u root -p
C:\\> mysql --help

C:\\> mysql -u root -p
			mysql> help
			mysql> status
			mysql> quit

12. Install MySQL GUI Tools

sfsdf

[ PHP ]

13. Install PHP
http://www.php.net/downloads.php

Make sure you designate where Apache’s httpd.conf catalog is located during the installation.

14. Choose Items to Install
Select “Will be installed on local hard drive.” for these items.

PHP> Extras> PHP Manual
PHP> Extensions> MySQL
PHP> Extensions> MySQLi
PHP> Extensions> PDO> MySQL

Then finish the install.

15. Testing the PHP installation

http://localhost/phpinfo.php

<?php

phpinfo();

?>

16. Testing PHP call to MySQL database Server

http://localhost/dbtest.php

<html>
<head><title>Testing database connection</title></head>
<body>

<h1>Testing PHP call to MySQL database Server.</h1>

<?php

$dbLink = mysqli_connect("localhost","root","<PASSWORD>");

if ($dbLink) {
	print mysqli_get_server_info($dbLink);
	echo "<br /><br />" . "<h2>1 - It worked!</h2>" . "<br /><br /><hr />";
} else {
	print mysqli_get_server_info($dbLink);
	echo "<h2>1 - It doesn't work!</h2>" . "<br /><br /><hr />";
}

if (!$dbLink) {
	print mysqli_get_server_info($dbLink);
	echo "<h2>2 - It doesn't work!</h2>" . "<br /><br />";
} else {
	echo mysqli_get_server_info($dbLink) . "<br /><br />";
	echo "<h2>2 - It worked!</h2>" . "<br /><br />";
}

mysqli_close($dbLink);

?>

</body>
</html>

kons,

Very nice! Thank you!

Regards,

DK