Você está na página 1de 16

Drupal 6.

x multi-site on a Windows PC
Posted by glennr on July 28, 2008 at 3:11am The key to learning the ropes on Drupal is setting up a good test/development environment on your PC, and for me, Drupal's multi-site feature has become the vital tool in this regard. I just wished I had done this earlier, so I'm posting the following guide in the hope that it might help save time and headaches for other Drupal newcomers. Multi-site is not exactly as easy as some Drupal experts suggest, so why bother? Because it allows you to try things and, well, stuff up as much as you like. The strategy works like this: You keep your original Drupal installation clean and untouched, and do your work on a second site (or a third or as many as you like). If a site doesn't work out, you simply remove that particular site and try again -- without having reinstall Drupal and all your contributed modules and themes again (if they're installed in Drupal's sites/all/modules and sites/all/themes folders). So let's start. You'll first need to an install Apache, PHP and MySQL, and the easiest way to do this is with a pre-packaged 'AMP' setup. For the following guide, I've used my favourite package, WampServer. The technique should also work with others, such as Xampp, with some minor differences such as some of the paths, but it's strictly for Windows Vista or XP PCs only. (Nothing against MacOS or Linux, but Vista was preinstalled on my laptop). 1. Install WampServer (or another 'AMP' package). Then make sure the Apache and MySQL services are running, and start phpMyAdmin in your browser (the URL should be something like http://localhost/phpmyadmin/ or it can be launched via the WampServer icon in your system tray). Create a new database -- we'll call it drupal6 because this will be our base installation which we will leave untouched. While you're here create a second and third database, which we'll call site1 and site2, as these will be our first two test sites. You can also change the database privileges if you want, but to keep things simple here, we'll stick with the default user, root, and no password. 2. Download Drupal 6 into WampServer's wamp/www folder (or the htdocs folder in Xampp and some other packages). (You'll need a tool like 7-zip to unpack the Drupal tar.gz file). 3. Do your first Drupal installation by pointing your browser to your Drupal folder, which should be something like http://localhost/drupal-6.x. Use the drupal6 database with the database user settings (root and no password in this example). Fully complete the installation, but then leave it alone. 4. Find Drupal's sites folder, make a copy of the default folder and rename it to the URL you want for your first test. To keep it simple, we'll make it the same as the first test site database: site1. While you're here, create files, tmp and themes sub-folders within this new folder. The themes subfolder will be used for any custom theme you create specifically for this site. Similarly, you can create a modules sub-folder for any module you use only with this site. However, generally, I find it easier to keep all contributed modules together in the sites/all/modules folder so I can use them with all my test sites.

5. Use a text editor to open the settings.php file in your new site1 folder and change $db_url line to reflect your first test site database, and the dabatase user name and password, eg:
$db_url = 'mysql://root@localhost/site1';

(If you added a password to the database username, add this to the line, eg: mysql://username:password@localhost/site1). Also, change the $base_url to the above site URL, eg:
$base_url = 'http://site1';

// NO trailing slash!

Repeat steps 4 and 5 for the other test site (site2). 4. Find the Windows hosts file, which should be in Windows' System32/drivers/etc folder, make a backup of that file and then open the hosts file in a text editor. Here, add new lines mapping your localhost IP address to match the URLs of your test sites and your original Drupal site. In our example, it would look like this:
127.0.0.1 127.0.0.1 127.0.0.1 127.0.0.1 localhost site1 site2 drupal6

5. Find the Apache httpd.conf file which, in WampServer, should be in the wamp/bin/ApacheX.X/conf folder (where X.X is the Apache version number). Sorry, I can't remember where Xampp installs this, but it will be in the Apache folder. Anyway, all you need to do here is make sure the "Virtual hosts" line is active by removing the # before Include conf/extra/httpd-vhosts.conf. 6. Make a backup of that httpd-vhosts.conf file (which is in Apache's conf/extra folder), then open httpd-vhosts.conf with a text editor and add these lines:
<VirtualHost *:80> DocumentRoot C:/wamp/www/drupal-6.x ServerName site1 <VirtualHost>

where C:/wamp/www/drupal-6.x is the path to the Drupal installation folder and site1 is the URL for your first test site. Add another entry for your other test site, another entry for your original Drupal installation and another entry for WampServer's localhost URL (if you want to keep this active), eg:
<VirtualHost *:80> DocumentRoot C:/wamp/www/drupal-6.x ServerName site2 <VirtualHost>

<VirtualHost *:80> DocumentRoot C:/wamp/www/drupal-6.x ServerName drupal6 <VirtualHost> <VirtualHost *:80> DocumentRoot C:/wamp/www ServerName localhost <VirtualHost>

7. Restart Apache for the changes to take effect. With WampServer, this is done by selecting the WampServer icon in the system tray and then "Restart all services". 8. Now you're ready to install each Drupal test site using your browser, eg:
http://site1/install.php http://site2/install.php

And that's it. As I said, it's not exactly simple, but it's well worth the effort. Now you can do whatever you like with your test sites. If you mess up with, say, site1, just delete the site1 folder, the site1 database in phpMyAdmin and the site1 entries in the Windows hosts and Apache httpdvhosts.conf files and start again. Alternatively, if a site works out and you want to go live with it, the multi-site approach makes this easier (in my opinion). One final caveat: I'm no expert. This technique works for me, but I'd welcome any feedback, especially if there are any accuracies. Login or register to post comments Categories: Installing Drupal, Drupal 6.x

Comments
=-=
Posted by VM on July 28, 2008 at 3:16am Very nicely done. I nominate this a handbook page.

Login or register to post comments

Thanks
Posted by glennr on July 28, 2008 at 5:26am I've not done this before -- should I post it to the handbook myself or does someone else?

Also, If you have time, would you (or anyone else) mind checking out my previous post on Multisite setup in 6.x using cPanel? My only previous experience with Linux servers is setting up a domain and uploading html files. The technique described in my other posting is working fine for me, but I would be interested to know if there's a better way to set up multi-site on a typical Linuxbased hosting provider.

Login or register to post comments

=-=
Posted by VM on July 28, 2008 at 12:21pm handbook pages can be created by all users on drupal.org. use the create content link The page you link to there is also a good page for the handbooks, IMO.

Login or register to post comments

Putting this in the handbook


Posted by siliconmeadow on July 28, 2008 at 12:46pm I think the best approach would be to click on the edit link of your post and copy the body. Then go to this page: http://drupal.org/getting-started/6/install/multi-site and add it as a child page (the link at the bottom) I hope this helps. I suspect the cpanel posting could be dealt with in a similar way in a similar place, although I seem to remember reading a cpanel post yesterday. -LinkedIn: http://www.linkedin.com/in/RichardSheppard my site: http://www.siliconmeadow.net -LinkedIn: http://www.linkedin.com/in/RichardSheppard

Login or register to post comments

2 sites one database


Posted by isagarjadhav on September 1, 2008 at 10:18am

I have 2 themes (e.g: http://something.com/us supposed to look different than http://something.com/in). But, here i want use only single database and single drupal installation. Currently I'm working on localhost (on windows machine). Can any one explains me how can i install different theme on different sites developed under same drupal 6.4 installation and shared(common) database. S

Login or register to post comments

Some options
Posted by glennr on September 1, 2008 at 1:47pm Multi-site is designed to run multiple sites off the one Drupal installation, but it requires a separate database for each site. Is there any specific reason why you want to run different sites in a single database? If so, there is a contributed module (http://drupal.org/project/virtual_site) which might do the job (although I haven't tried it). However, in most circumstances, multi-site does the job, offering the benefits of single installation (easier maintenance, etc) while running completely separate sites, with a separate theme for each site, if you want. BTW, there's no need to post support questions in a handbook (eg http://drupal.org/node/288126). You'll get better response in the forums, while keeping the handbook pages "cleaner". I hope this helps.

Login or register to post comments

Can't Start PHPMyAdmin


Posted by maguffinator on August 1, 2008 at 7:09pm I'm running Vista and am able to install WAMP Server 2, but I get a 404 Error when I type http://localhost/phpmyadmin/ into the IE address bar. I just get a blank page when I try it in Firefox. Any ideas? Samething happens when I just try to access http://localhost/. Also, same thing happened when I tried using Apache2Triad, which I uninstalled and replaced with WAMP Server 2 when I found this page. What am I doing wrong? Thanks.

Login or register to post comments

Sorry if I'm stating the obvious . . .

Posted by glennr on August 2, 2008 at 12:09am But are Apache and MySQL running? Check the WampServer icon in the Windows system tray. (If the icon is not there, you need to launch WampServer, obviously). Then select the WampServer icon and "Start all services". If Apache and MySQL are already running, try selecting "Restart all services" and see if that works. Apologies if I'm stating the obvious here, but that's the best place to start when troubleshooting.

Login or register to post comments

A couple of typos
Posted by glennr on August 2, 2008 at 10:17am Sorry, I left out the forward slashes in the VirtualHost closing tags in my posting above. Each VirtualHost entry in the Apache httpd-vhosts.conf file must close with </VirtualHost>. The correct version of this guide can be found in the handbook here: http://drupal.org/node/288126.

Login or register to post comments

nicely done...
Posted by isagarjadhav on August 10, 2010 at 12:28pm Nicely done. I've even referred the link in https://twitter.com/sagarjadhav/statuses/917543927 :) S

Login or register to post comments

Bravo
Posted by romi_adetio on October 2, 2008 at 3:20pm Thank's Alot...it is working very nicely... I will inform this tutorials to all my pals. thank you again

Login or register to post comments

Multiple Drupal sites on different port


Posted by asteffes on October 3, 2008 at 5:28pm

Thanks for this guide as I have been trying to get this to work on my dev machine for quite some time, and this so far has been the most concise guide. However, I am also running IIS on my Windows XP Pro Dev machine, and that is a necessity for .NET development. I've got Apache running on port 81 to keep them playing nice together. However, after following this guide step by step, I cannot get multiple sites to work. I suspect that it has to do with port 81, although I cannot be sure. I do not fully understand how the windows "hosts" file works, as I've tried to put in a "localhost1" mapping to 127.0.0.1:81 with no consequences. I've also tried removing the "localhost" entry completely, but it still does not disrupt the mapping. Can someone provide some help as to what additional steps are necessary if Apache is running on a separate port? I imagine this is a common need for Windows developers. Again, thank you for your post.

Login or register to post comments

Thanks for the very clear


Posted by rsbecker on October 3, 2008 at 5:50pm Thanks for the very clear instructions. Regarding coexisting with IIS, you can use another port for Drupal. For example, you can use 8080. To do that you need to change the Apache htppd.conf file by replacing the line Listen 80 with the line Listen 8080 Or you could have both. You also need to change the vhost.conf file by changing the
<VirtualHost *:80>

with
<VirtualHost *:8080>

You might also find it necessary to change the $base_url line in settings.php to include the port number, i.e., my-site.loc:8080. Alternatively, you could change the mod_rewrite rule in drupal/.htaccess to strip the :8080 off the site name using one of the commented suggestions in the file.

RewriteCond %{HTTP_HOST} ^my-site1.loc:8080$ [NC] RewriteRule ^(.*)$ http://my-site1.loc/$1 [L,R=301]

But I have a problem that has been driving me crazy. My multi-site installation is running fine if I'm sitting at my desktop PC. But getting to it from another computer on my network is difficult. I installed Hamachi, a VPN package that is free for non-commercial use. Using it I can get to a drupal site on my desktop, but only the site defined as the default site. That is because to get to the site I have to type the internal IP address Hamachi assigned to my computer. I cannot use the site name, which would be identified by drupal and passed to the appropriate site. In other words, in the drupal/sites folder I have my-site1.loc my-site2.loc. Each has its own subfolder and settings.php file. But the way drupal works is that if it cannot resolve the name it receives it sends you to the default site. Is there a way using Hamachi or some other low-/no-cost solution that would allow me to pass the actual site name to drupal over the network so I can open the site I want to work in? Thanks.

Login or register to post comments

Remaining install problems


Posted by asteffes on October 3, 2008 at 6:11pm Thanks for your reply to my inquiry. I've got myself in a bit of a strange situation now. I've changed all the settings that you've recommended to indicate that the drupal installation is on a different port (port 81 in my case). In fact, I've changed port 80 to 81 in just about every file that I've come across. The problem is now that I'm not even able to access my base drupal install. My hosts file looks like this:
127.0.0.1 127.0.0.1:81 localhost webdev #(this is my test site)

Perhaps it should look different? I simply don't know how to troubleshoot this file, because none of the changes seem to have an affect on mappings after I update, save, restart IIS & Apache. In addition, I am no longer able to access my other Apache/PHP sites, such as phpMyAdmin since I have attempted to create virtual hosts.

I used to be able to reach any of the websites listed in my apache base directory using localhost:81/drupal, or whatever the folder name is. This is no longer functioning. Any additional assistance is greatly appreciated.

Login or register to post comments

The error you have made is


Posted by rsbecker on October 3, 2008 at 7:17pm The error you have made is in trying to assign a port number in the windows\system32\drivers\etc\hosts file. Use 127.0.0.1 for your webdev site. In the httpd.conf file change Listen 80 to Listen 81 The httpd.conf file is in a subfolder of Apache. I am using xampp and it is in Apache/conf Next you need to edit the httpd-vhosts.conf file to make each of your virtualhosts look for an address at port 81 by using *:81 Assuming you have then set all of the other directives in httpd-vhosts.conf for each virtualhost correctly you should get to your site. On my multi-site installation the directory tree is as follows: www\my-site1.loc\drupal The sites are defined in www\my-site1.loc\drupal\sites\my-site1.loc www\my-site1.loc\drupal\sites\my-site2.loc There is a site specific settings.php file in each but in httpd-vhosts.conf the DocumentRoot directive for each site is the same DirectoryRoot 'E:/www/my-site1.loc/drupal'; The Directory directives are the same for both sites as well, i.e.
<Directory E:/www/my-site1.loc> Options Indexes FollowSymLinks ... </Directory>

But the ServerName and ServerAlias directives are site specific, i.e.

ServerName my-site1.loc ServerAlias my-site1.loc *.my-site1.loc ServerName my-site2.loc ServerAlias my-site2.loc *.my-site2.loc MAKE SURE TO USE FORWARD SLASHES IN THE httpd-vhosts.conf FILE, NOT BACK SLASHES Once drupal initializes it will send the call to the proper settings.php file. I hope this clears up your confusion.

Login or register to post comments

Hamachi problems
Posted by asteffes on October 3, 2008 at 6:15pm It sounds like from your post that you are working on two computers that are both located on the same network. In this case, why is a VPN adapter like hamachi necessary? Why not use http://computerIPaddress/drupal? Perhaps I'm missing something, if so, please explain your requirement again. I don't know how to help you troubleshoot hamachi; although I am familiar with its use for multiplayer gaming, I'm not familiar with how it maps urls, etc.

Login or register to post comments

I have tried every way I can


Posted by rsbecker on October 3, 2008 at 7:32pm I have tried every way I can think of to do what you suggest. I assigned my computer a fixed IP address and modified the windows hosts file as follows 127.0.0.1 localhost 127.0.0.1 my-site1.loc 127.0.0.1 my-site2.loc IPAddress my-site1.loc IPAddress my-site2.loc When I put in http://IPAddress/my-site1.loc from another computer I get to the site defined as the default and get its theme with Page Not Found. If I use http://IPAddress:8080/my-site1.loc I get Access Forbidden. The same goes for http://IPAddress/my-site1.loc:8080

My httpd.conf and httpd-vhosts.conf files apparently are set up correctly because I can get to both sites from my computer. Obviously I'm missing something, but I cannot figure out what it is.

Login or register to post comments

Access Forbidden
Posted by asteffes on October 3, 2008 at 9:32pm I'm certainly no expert on getting multi-sites working in Windows. But regarding your "Access forbidden" problem, that looks like a good sign to me. It appears as if you have reached the page but do not have sufficient security privileges to see the page. Although, I could be mistaken. I'm more familiar with IIS than I am with Apache. Make sure you have your ports opened up inside windows firewall so that other computers are allowed to look at your port 80, or 8080, whatever the case may be. Before trying to make sure that drupal works from another computer, trying putting an index.php or index.html file in your root apache directory and then try to reach that simple page from an outside computer. You won't (necessarily) need a static IP address inside your network just for this test to work, although it won't hurt. Just try to have your IP address and port number that Apache is using from another computer: http://192.168.1.101:8080 If this does not bring up your index.php page on the local machine, you've got other issues. If it does not come up on another computer inside of your network, you've got firewall/security issues. Hope this helps.

Login or register to post comments

Unsuccessful with different port


Posted by asteffes on October 3, 2008 at 10:00pm I'm relatively inexperienced with drupal, although I have done several successful installations and setups already. However, setting up a multi-site drupal on XP Pro while running IIS has eluded me. Today I spend most of the day installing and re-installing this WAMP server to make sure there were no areas that I have missed. My latest attempt was a minimalist attempt. I tried to create a Drupal parent site and a "Site1" additional site. Here are my code snippets so that perhaps someone

can provide me with a suggestion on how to properly setup multiple sites on XP when I am running IIS on port 80 and Apache on Port 81 Here is my hosts file:
127.0.0.1 localhost 127.0.0.1:81 site1 127.0.0.1:81 drupal6

Here is my site1 settings.php file:


$db_url = 'mysqli://site1user:password@localhost/site1'; $base_url = 'http://site1';

Here is my defaultsettings.php file, which I did not change at all


$db_url = 'mysqli://drupaluser:password@localhost/drupal6'; (no $base_url setting)

Here are all the virtual host settings


<VirtualHost *:80> ServerAdmin webmaster@dummy-host.localhost DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost" ServerName dummy-host.localhost ServerAlias www.dummy-host.localhost ErrorLog "logs/dummy-host.localhost-error.log" CustomLog "logs/dummy-host.localhost-access.log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@dummy-host2.localhost DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host2.localhost" ServerName dummy-host2.localhost ErrorLog "logs/dummy-host2.localhost-error.log" CustomLog "logs/dummy-host2.localhost-access.log" common </VirtualHost> <VirtualHost *:81> DocumentRoot C:/wamp/www/drupal6 ServerName site1 </VirtualHost> <VirtualHost *:81> DocumentRoot C:/wamp/www/drupal6 ServerName drupal6 </VirtualHost>

Going to "http://site1/install.php" just does a google search through firefox3. http://localhost:81/ brings me to my default Drupal installation.

Is there are path I can use to get to Site1? For example, http://localhost:81/sites/site1/ does not work. Any help is greatly appreciated.

Login or register to post comments

Let me take one more quick


Posted by rsbecker on October 4, 2008 at 2:14pm Let me take one more quick shot at this and add a couple of things I left out yesterday. Things left out: If you installed wampserver you probably need to go into the httpd.conf file and find the following near the bottom of the file:
# Virtual hosts #Include conf/extra/httpd-vhosts.conf

Remove the hash mark from the beginning of the second line. If you installed xampp that line probably was not commented out. IF that line is commented out you will not be able to use virtual hosts In the httpd-vhosts.conf file you will find the line
NameVirtualHost *:80

You should add the line


NameVirtualHost *:81

Then you might try a fuller definition of each virtual host:


<VirtualHost *:81> ServerAdmin webmaster@site1 DocumentRoot "C:/www/site1/drupal" //Or whatever the directory path is. ServerName site1 ServerAlias site1 *.site1 // This takes care of www.site1, rerouting to site1 <Directory /> Options FollowSymLinks AllowOverride all </Directory> <Directory "C:/www/site1/drupal"> Options Indexes FollowSymLinks AllowOverride all Order Allow,Deny

Allow from all </Directory> ErrorLog logs/site1-error_log help CustomLog logs/site1-access_log common </VirtualHost>

//Not necessary, but may //you track down the problem

<VirtualHost *:81> ServerAdmin webmaster@drupal6 DocumentRoot "C:/www/site1/drupal" // Same path as above ServerName drupal6 ServerAlias drupal6 *.drupal6 <Directory /> Options FollowSymLinks AllowOverride all </Directory> <Directory "C:/www/site1/drupal"> // Same as above Options Indexes FollowSymLinks AllowOverride all Order Allow,Deny Allow from all </Directory> ErrorLog logs/drupal6-error_log CustomLog logs/drupal6-access_log common </VirtualHost>

Just one more idea. I started with wamp and got it running. But in trying to set up my connection over the network I did something that broke it. After spending a day or more trying to fix wamp I gave up, uninstalled it, and installed xampp. I have had no problems since then. So if the above does not work for you try another server.

Login or register to post comments

+1 for handbook page. It's


Posted by dman on October 4, 2008 at 4:01pm +1 for handbook page. It's not exactly what I'd have done but is certainly a valid way to do it, and will help folk Everyone else: Stop trying to put port numbers in your HOSTS file. It's simply invalid. HOSTS defines where you look. Ports define what you ask for when you get there. You may find it neccessary to open a command shell and run
ifconfig /renew

when testing your local hosts file changes. Maybe not, but I do. Getting Apache to listen to other ports is part of apache docs. Geting Drupal multisite to respond to alternative ports is an extra config and documented in your settings.php file!

* * * *

If you are installing on a non-standard port number, prefix the hostname with that number. For example, http://www.drupal.org:8080/mysite/test/ could be loaded from sites/8080.www.drupal.org.mysite.test/.

Ports are OK, and better than subfolders Messing with your HOSTS file is better (but messier nd less portable) I run my own LAN DNS wildcard thing .. but I'm a geek. .dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.

| http://www.coders.co.nz/ |
.dan. is the New Zealand Drupal Developer working on Government Web Standards

Login or register to post comments

Working!!
Posted by asteffes on October 6, 2008 at 4:13pm Thank you for your tip regarding the hosts file. Removing the Port numbers there and also getting a new IP address after saving it have both worked to progress my issue. Thanks again.

Login or register to post comments

Apache Won't Restart


Posted by cocogodiva on November 2, 2008 at 5:40pm I've followed the above directions, Apache will not restart. When I remove the virtual host scripts Apache starts with no problem. Any ideas? Below is the virtual host script, along with the conf & host file scripts. httpd = Virtual hosts Include conf/extra/httpd-vhosts.conf vhosts = DocumentRoot G:/xampp/htdocs/drupal ServerName vanilla

DocumentRoot G:/xampp/htdocs/drupal ServerName drupal DocumentRoot G:/xampp/htdocs ServerName localhost host = 127.0.0.1 localhost 127.0.0.1 drupal 127.0.0.1 vanilla Praying to The Drupal Gods

Login or register to post comments

Not sure if this is your problem, but


Posted by glennr on November 2, 2008 at 9:43pm Not sure if this is your problem, but there were a couple of code typos in my original posting, so check that you've got the correct </VirtualHost> closing tags in the httpd-vhosts.conf entries. While you're at it, it wouldn't hurt to double-check every step, especially the changes you've made to the httpd-vhosts.conf and httpd.conf files. If that doesn't help, post some more details about your system (if are you using Vista/XP, WampServer, etc), and maybe someone here can help.

Login or register to post comments

Você também pode gostar