Richard Eriksson - January 10, 2007 - 17:12
Every new VPS comes with the capability to run more than one site with the single IP address. That is, you can have multiple domains and/or subdomains pointing to a single installation of Drupal on your site.
(Note that these instructions assume you have only one install of Drupal: otherwise, if you have more than one version of Drupal, you will need to make modifications to your httpd.conf file. Please contact us for instructions on how to do that, and note that every time you point a new domain to the server, you will need to edit the httpd.conf file again.)
These instructions assume knowledge with working on the Unix command line. Many, if not all, of these steps can be taken by logging on to the server via SFTP.
Setting Up the Database
We have some generic instructions for creating a new database. After following those, you will need to follow some steps specific to the version of Drupal you are running on your VPS:
- for Drupal 4.7, you will need to load the initial data on the command line:
mysql -uNewUsername -pNewPassword Database_Name < /var/www/html/database/database.4.1.mysql
- for Drupal 5, just go to your new site and you will be prompted to select an install profile. Select "Bryght Base" in this case.
Setting Up Drupal for Multiple Sites
After you've created the database and given it the correct permissions (see the above section), you will need to setup the Drupal file system so that it uses the domain.
Setting Up an Entire New Site Using a Domain or Subdomain
- pick a subdomain or domain. We will use example.com in this example.
- create a directory in
/var/www/html/sites with the name of that domain name. For example, mkdir /var/www/html/sites/example.com Note that you should not use the 'www' as Drupal will pick up on it if the DNS is setup correctly. If you use a subdomain, you would type mkdir /var/www/html/sites/subdomain.example.com
- copy the settings.php file and other support files from the "default" folder:
cp -a /var/www/html/sites/default/* /var/www/html/sites/example.com/
- change the ownership of the new site's files directory:
chown apache /var/www/html/sites/example.com/files
- setup settings.php:
- for Drupal 4.7: edit the settings.php file, and search for 'mysql', and edit the line that starts with "$db_url =" that isn't commented out. Use the values you chose in step 1 in the "Setting Up the Database" instructions, i.e. when you typed in
'GRANT ALL PRIVILEGES' etc.
- for Drupal 5:
- edit the settings.php file, and look for a line that looks like the following:
$db_url = 'mysql://username:password@localhost/databasename
- change username, password, and databasename to reflect the values you chose above for your new database.
- change the ownership settings.php file:
chown apache /var/www/html/sites/example.com/settings.php
- in your browser, go to example.com/install.php
Setting Up an Entire New Site in a Subfolder
- Decide on a subfolder. These instructions assume you already have a domain pointing to the IP address. We'll use example.com just like above.
- create a directory in
/var/www/html/sites with the name of that domain name and the name of the subfolder, separated by a dot.
- So for a subfolder of example.com, that is, a site at example.com/newsite/, type in
mkdir /var/www/html/sites/example.com.newsite
- Create a symbolic link back to your install of Drupal. This may sound a little confusing, but it's a necessary step to make Drupal think it's inside a subfolder.
cd /var/www/html/
ln -s . newsite
- # note the dot, it's important
- copy the settings.php file and other support files from the "_template" folder:
cp -a /var/www/html/sites/_template/* /var/www/html/sites/example.com.newsite/
- change the ownership of the new site's files directory:
chown apache /var/www/html/sites/example.com.newsite/files
- setup settings.php:
- for Drupal 4.7: edit the settings.php file, and search for 'mysql', and edit the line that starts with "$db_url =" that isn't commented out. Use the values you chose in step 1 in the "Setting Up the Database" instructions, i.e. when you typed in
'GRANT ALL PRIVILEGES' etc.
- for Drupal 5:
- edit the settings.php file, and look for a line that looks like the following:
$db_url = 'mysql://username:password@localhost/databasename
- change username, password, and databasename to reflect the values you chose above for your new database.
- change the ownership settings.php file:
chown apache /var/www/html/sites/example.com.newsite/settings.php
- in your browser, go to example.com/newsite/install.php
DNS settings
When you've done all the above, now it's time to point the domain or subdomain's DNS records to your server.
For a subdomain, choose one of the following:
- in your domain's settings, create a subdomain, and point the A record to your server's IP address
- use a CNAME record pointing to any domain that's already using the server. Drupal will automatically use the settings from the new subdomain in
/var/www/html/sites in order to display the correct site
For a domain, choose one of the following:
- point an A record for the domain to the IP address of the server, then a CNAME record for 'www' pointing to the domain. If you can't point a CNAME record for the subdomain 'www', use an A record pointing to the same IP address.
- point nameserver records to ns1.bryght.com, ns2.bryght.com, and ns3.bryght.com. If you choose this option, you will need to notify Bryght Support that you are pointing your nameservers to us, and if you have an email provider, what DNS settings they require for the service to work.
Automated Cron Maintenance Script Setup
Last but not least, when you've setup your domain to point to your server, you will most likely want to setup Drupal's automated maintenance tasks, which run courtesy of the Unix cron system. These maintenance tasks include, but are no means limited to: clearing out old watchdog logs; sending new content notifications to pingomatic.com; updating the RSS aggregator by pulling in feeds from external sites; and tasks that other modules need to perform on a regular basis, such as sending mail or clearing out spam comments.
Setting Up Cron For Your New Site
- Login to your server via SSH.
- edit the crontab file. This is done with the following command:
sudo nano /etc/crontab
- copy one of the lines that looks like the following into a new line
0 * * * * root /usr/bin/wget -O - -q http://example.com/cron.php
- replace "example.com" with your domain. If you've used a subfolder, then replace "example.com" with the domain and subfolder
- the above line states that every hour, at the top of the hour, the 'wget' program will fetch the cron.php script, which runs maintenance tasks. Replace 0 (zero) with a number indicating at which point every hour you want it to run. For example, 15 will tell it to run at 15 minutes past every hour.
- save the file and exit
no _template dir?
Hi, I don't seem to have a /_template folder in /sites on my VPS, just /CVS , /all , and /default
Everything else seems to be ok so far.
I'm trying to follow this step:
3. copy the settings.php file and other support files from the "_template" folder: cp -a /var/www/html/sites/_template/* /var/www/html/sites/example.com/
Suggestions? Thanks!
settings.php
Just copy the settings.php from an existing site. The one in /default should be fine. You will have to manually edit the new settings.php file and change the password in that file to the user/password that you created for your new database, as well as update the database name.
gotcha
Thanks Richard
Statistics in a multi-site setup
Boris/Richard, I wonder how you provide domain stats in Bryght's multi-site setup. I asked my hosting provider the following:
Apart from the regular stats which many clients demand (I provide the stuff generated by AWStats), I was thinking about the SEO angle for which these stats are aboslutely crucial.
My host responded:
Over at drupal irc, someone suggested that if the apache logs indicate the requested domain in the log entry, then you can parse it out that way using sed/awk or your favorite log processing tool.
Any suggestions about this?
Thanks,
Venkat
Google analytics
Logging httpd is difficult with a multidomain setup. Use Google analytics or other tracking tools.
Exactly!
Thanks. I read the doc page on Google analytics just after posting my question, but it's great to get a confirmation.
A question about DNS settings for multi-site
Thanks for this great page; it makes understanding drupal multisite on VPS a lot easier. I found my way here thanks to Richard's comment at http://drupal.org/node/104340#comment-177257
My only concern is that the DNS settings recommendations above will make the domains pretty much useless for anything else. I saw similar instructions about DNS settings at http://drupal.org/node/49605:
This is fine when a drupal webmaster only wants to expose clients to the drupal admin interface and nothing more. But, I think it is reasonable to say that there will be situations when a drupal webmaster will want to do the following when running a multi-site install:
As far as I know, neither is possible when using domain pointers via A records and CNAME records for a multi-site install because the domains are just aliases for the main domain on which the drupal code base is installed. That is, they are not properly set up in WHM/cPanel or Plesk or other control panels.
Somehow, I can't believe that the recommended procedure for a drupal multi-site install is one which will make lame the domains on which the other sites run.
My question, therefore:
Can I setup domains properly in WHM/Ensim/Plesk or other control panels so that they function as full hosting accounts and still use the Apache vhosts option for a drupal multi-site install?
Will that scenario have any catch that will prevent it from working?
Thanks,
Venkat.
We don't use control panels
So don't really know much about them. In our experience, production hosting with Drupal is best done without a control panel. Or at least, without any of the ones we have come across.
Recommended procedure for Bryght VPS servers
As I mention in my comment to the thread you pointed to, Venkat, the instructions here are for Bryght's VPS servers, and don't reflect the variety of setups that other servers (shared and dedicated) will have. The documentation on Drupal.org, when it is completed, should probably cover the questions you have. I know that doesn't answer your question, but like I say, since there are no control panels on Bryght VPS servers, and the documentation here is specific to our setup, we won't cover it here.
I will point out that our recommended DNS settings (an A record pointing to the IP address of Bryght's VPS server) won't prevent you from doing other things with the domain's DNS, like subdomains or MX records for mail servers.
Thanks, Boris and Richard
Thanks, Boris and Richard for taking the time to answer my questions.
I think the best thing for me would be to try out multisite on a VPS I have and ask again if I have further questions.
Venkat