注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

John's Blog

天空,有梦就可以飞翔!

 
 
 

日志

 
 
关于我

刚走出校园的毕业生,就读计算机网络专业,对网站建设有一定的基础。开始探求Drupal已有一段时间,对Drupal的发展很是看好。现就职于深圳慧衡科技有限公司(intematrix.cn),它是一家专门服务于中国及海外中小企业的网络营销分析和优化服务提供商。 QQ交流群:44581272

网易考拉推荐

Drupal多站点:Drupal Multisite Installation On cPanel  

2009-11-10 21:00:28|  分类: drupal学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

If you have a cPanel shared hosting account and want to use Drupal to host multiple sites, this article will help. By creating such a configuration, you can have one shared code base and separate databases per website making it easier to upgrade and maintain.

Preliminaries

These instructions are can be used with any cPanel based share hosting account. We assume you are hosting on a LAMP application stack (Linux, Apache, Mysql, PHP).

Before you begin, make sure you have the following system requirements:

  • Apache 2.x and higher
  • PHP version 5.2 and higher
  • Mysql version 5.0 and higher
  • PHP XML extension
  • PHP mysqli extension
  • PHP GD extension
  • mod_rewrite enabled

If you don't want to go through the hassle of figuring out if your host meets Drupal requirements and wasting time troubleshooting, use Hostgator. This site happens to be on HostGator and is running Drupal multisites. I've used them throughout the years and they are affordably priced and very good on support.

If you sign up using Hostgator please use the banner above as we are a Hostgator affilliate. We use the ad revenue to run this website. And if you don't mind please contact me if you have done so. Thank you.

The Main Domain

To make the explanations in this article easier to understand, assume site1.com is your main domain name and site2.com, site3.com, etc. are your other domains. Of course, substitute these with your real domain names.

We will start by creating our first domain.

Download Drupal And Store On Web Server

  1. Download the latest Drupal release to your local computer. Do NOT use the development release (marked X.X-dev)
  2. Use WinRar to decompress the TAR.GZ file onto your local computer
  3. Go to your domain registrar and set the DNS to point to your hosting companies DNS servers
  4. In cPanel click on Add Domains
  5. Enter in your domain name and username/password (*)
  6. All files for the main domain will be stored in web server's public_html folder
  7. FTP the Drupal distribution to the Apache public_html folder. You can use FileZilla for your FTP client.
  8. To prevent installation problems do not install Drupal in its own folder

(*) Note that it may take up to 24 hours before your domain name resolves as it needs to propagate across the Internet.

Configure php.ini

Go to cPanel and click on the php.ini QuickConfig icon. Make sure the following configurations are set:

  • Zlib.output_compression: on
  • safe mode: off
  • register_globals: off

Create your Mysql database

  1. Go to cPanel and click on the Mysql databases icon
  2. Enter in a database name and click the create database button. Choose a short name similar to your domain name
  3. Add a new user specifying the username and password. We will use this one one for all sites.
  4. Add the user to your database

Copy Drupal Config Files

  1. Copy /sites/default/default.settings.php to /sites/site2.com/ and file mask 744
  2. Copy /sites/default/default.settings.php to /sites/site2.com/settings.php and 744

Do NOT change $db_url to your database parameters of username/password/server/databasename as this will result in tables not being created. Just leave these files alone and let Drupal fill it in on install.

.htaccess

Take the original .htaccess from Drupal and modify the file to add the following:

DE<  RewriteCond %{HTTP_HOST} ^siteN\.com$ [NC]
  RewriteRule ^(.*)$ http://www.siteN.com/$1 [L,R=301]DE<

For SEO purposes we make sure all URL requests go to the canononical URL. That is, if someone typed http://siteN.com or http://www.siteN.com it will be changed to http://www.siteN.com/.

Install Drupal For Your Main Site

Go to http://www.site1.com and you should be presented with the installation program. Fill in all the information as required and write down everything you entered to refer back later.

Make sure you test everything out to make sure it works.

Create Additional Drupal Site

Now that you have your main site installed, you can add additional Drupal sites! You basically do the same steps again.

  1. Add your domain via cPanel
  2. Delete the domain folder (*)
  3. Create your Mysql database
  4. Copy Drupal config files to the /sites/siteN.com folder
  5. Add your website to the main domain's .htaccess

(*) As you add more domains through cPanel site2.com, site3.com folders will be created. Delete them as they won't be used. You will see why below.

Create Symlinks

Here is the trick to creating Drupal multisites. Now that the siteN.com folder is deleted you must point siteN.com to the root public_html folder. On shared hosting accounts you don't have root access so you have to do it though programming.

Run your text editor and create a symlinkcreate.php file. Type the following in:

DE<<?php symlink( '/home/yourusername/public_html/', 'siteN.com' ); ?>DE<

Replace username and siteN.com with appropriate information. FTP symlinkcreate.php to public_html and run it from your browser (http://www.siteN.com/symlinkcreate.php).

After execution, a folder by the name of siteN.com will exist. If you use your FTP client to access the siteN.com folder, it will point back at your public_html root.

Technical stuff:

The Apache httpd.conf is told that a siteN.com virtual host is available at /public_html/siteN.com directory. Every siteN.com HTTP request is file mapped to /public_html via the symlink. Because index.php is the default home file it will get executed. Index.php is Drupal's bootloader so all website requests to the symlinks will be handled by index.php. This is how a Drupal multisite can work.

Add .htaccess code

Do the same instructions as mentioned above to add your new site to .htaccess for friendly URLs and site SEO.

Install Drupal For Your Additional Websites

Go to www.siteN.com and you should be presented with the installation for your siteN.com domain. Fill in all the information as required.

Post installation

  • Check to make sure your default.settings.php and settings.php files are marked read only 444.
  • Look at your robots.txt file and make sure everything in there is ok
  • Rename your install.php and update.php files to something else or remove it.

Congratulations! You are now done!

Proceed to add modules, setup users and all the other things you need to run your site. Refer to the Drupal documentation for assistance.

  评论这张
 
阅读(701)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016