Hướng dẫn tạo Drupal 7 Multi-sites trên Ubuntu 10.04 LTS

Hướng dẫn tạo Drupal 7 Multi-sites trên Ubuntu 10.04 LTS

This tutorial starts from a scratch Ubuntu 10.04 LTS installation, in to a clean Drupal 7 mult-site installation. Here's what you need to get started:

  • A dedicated server (this tutorial's examples are using Ubuntu 10.04 LTS)
  • Root & shell access
  • A working knowledge of Linux and Drupal

Setting up the LAMP stack

Creating your user with sudoer priviledges
 
Log in as your root user and execute the following commands:
sudo adduser -G admin <NEW_USER>
sudo passwd <NEW_USER>

Now you should have created yourself an account that can use sudo. Exit the shell and relogin as your newly created user. You may need to set up your name and such, you can do that by modifying the /etc/hostnamelike this:

sudo nano /etc/hostname

For an immediate effect, you can execute the following command:

sudo hostname <HOSTNAME>
Downloading and installing the necessary packages
 
Now we need to get some packages that we'll be using for our multi-site installation:
sudo apt-get install mysql-server
sudo apt-get install phpmyadmin

Take note of your password of course, and when choosing a web server select Apache2. Make sure everything is running fine after this, you may need to start the servers like this:

sudo service apache2 start
sudo service mysql start

And this point you should be able to navigate to your server's IP or hostname if you have set up your DNS, and it should bring up the index.html file that reads "It Works!."

Preparing your Drupal core

Download and install the Drupal core
Go to the Drupal project page and download the latest version of Drupal 7. Using wget, sftp, or ftp upload the Drupal core so that it sits in /var/www/drupal/7. Now you can modify the Drupal .htaccess file to either force www or force no www. I prefer no www prefix, and so I uncommented the area that looks like this:
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
Creating your site directories
For each site that you'd like to host on your Drupal multi-site installation, create a folder in /var/www/drupal/7/sites/<HOSTNAME>. The contents of the folder should include a settings.php and a files directory at minimum.
Rename and modify sites.php
Rename DRUPAL_ROOT/sites/example.sites.php to DRUPAL_ROOT/sites/sites.php.
sudo mv example.sites.php sites.php
sudo nano sites.php

Now modify the sites.php to let Drupal know what directories to use for the corresponding hostname, mine may look like this:

<?php
// $Id: example.sites.php,v 1.3 2010/04/15 12:01:28 dries Exp $

/**
 * @file
 * Configuration file for Drupal's multi-site directory aliasing feature.
 *
 * Drupal searches for an appropriate configuration directory based on the
 * website's hostname and pathname. A detailed description of the rules for
 * discovering the configuration directory can be found in the comment
 * documentation in 'sites/default/default.settings.php'.
 *
 * This file allows you to define a set of aliases that map hostnames and
 * pathnames to configuration directories. These aliases are loaded prior to
 * scanning for directories, and they are exempt from the normal discovery
 * rules. The aliases are defined in an associative array named $sites, which
 * should look similar to the following:
 *
 * $sites = array(
 *   'devexample.com' => 'example.com',
 *   'localhost.example' => 'example.com',
 * );
 *
 * The above array will cause Drupal to look for a directory named
 * "example.com" in the sites directory whenever a request comes from
 * "example.com", "devexample.com", or "localhost/example". That is useful
 * on development servers, where the domain name may not be the same as the
 * domain of the live server. Since Drupal stores file paths into the database
 * (files, system table, etc.) this will ensure the paths are correct while
 * accessed on development servers.
 *
 * To use this file, copy and rename it such that its path plus filename is
 * 'sites/sites.php'. If you don't need to use multi-site directory aliasing,
 * then you can safely ignore this file, and Drupal will ignore it too.
 */

/**
 * Multi-site directory aliasing:
 *
 * Edit the lines below to define directory aliases. Remove the leading hash
 * signs to enable.
 */
$sites['gerbino.co'] = 'gerbino.co';

Configure Apache2 virtual hosts

Configure Apache2 sites
The first thing I like to do is disable Apache2's default site, you can do this by executing the following command:
sudo a2dissite default

Now let's tell Apache2 how to handle our http requests by creating a file called /etc/apache2/sites-available/drupal-7.

sudo nano /etc/apache2/sites-available/drupal-7

Here's an exampe of how it should look:

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName server1.yunices.com

  DocumentRoot /var/www/drupal/7

  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
</VirtualHost>

Now we should activate the Virtual Host (which is really just creating a symlink to sites-enabled, but we'll do it the right way).

sudo a2ensite drupal-7

Finally, we must reload Apache2 so the configuration can take effect, you can do this by executing the following:

sudo service apache2 reload

Creating new Drupal sites in your Multi-site installation

Creating your database
Assuming you've followed my steps, you can easily create new databases for new Drupal sites by navigating your browser to:
http://<HOSTNAME>/phpmyadmin

Create the new emptydatabase, and go to priviledges and add a user that has full access to your specified new database and nothing else. I also like to limit it from localhost only. Take note of the information such as database name, database user, database user password. Now for each one of your new domains you should be able to navigate to:

http://<DOMAIN.TLD>

And see the Drupal installation script running. Simply following the installation as normal and enjoy your new multi-site setup. Every site will be redirect with or without www as you've modified the Drupal .htaccess, and everything is gravy.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Hướng dẫn output từ remote drush commands, Drupal 7

Hướng dẫn output từ remote drush commands, Drupal 7

Have you noticed how the output from your remote drush commands wraps at awkward lengths

Bối cảnh ra đời trang mạng xã hội Facebook

Con người là những tế bào xã hội. Chúng ta có mặt trên đời là hệ quả của những hành động của người khác

7 bước xây dựng  Responsive Theme trong Drupal 7

7 bước xây dựng Responsive Theme trong Drupal 7

Based on the grid system and the nature of your design, download grids from http://960.org. In the case of the RoboSmart theme we have used a single grid at 600 which is fluid and works for any screen resolution greater than 600px.

Công ty diệt chuột T&C

 

Diet con trung