Opensource, CMS, PHP, MySql, Drupal, Frameworks

Monday, September 27, 2010

Setup Drupal multisite feature in Local machine

Setup Drupal's multisite feature in Local machine.

For that we have to follow the following three steps.


1. Add alias to our Apache configuration file

2. Redirecting all requests to index.php

3. Creating our settings.php


Add alias to our Apache configuration file

We want requests for the 3 subdirectories(emea, la, uk) to go to the same Drupal instance.We can do this using Apache's Alias functionality.

DocumentRoot “/xampp/htdocs/drupal”

Alias /emea C:/xampp/htdocs/drupal

Alias /la C:/xampp/htdocs/drupal

Alias /uk C:/xampp/htdocs/drupal

I'm supposing here Drupal's codebase is hosted in C:/xampp/htdocs/drupal on your machine


Redirecting all requests to index.php

Now that we're serving all requests from one codebase we have to redirect all requests to index.php. This needs to be done since all Drupal requests are served from one endpoint, called index.php. So we have to do the below changes in the .htaccess file in the same order as mentioned below.

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} ^/emea/(.*)$

RewriteRule ^(.*)$ /emea/index.php?q=$1 [L,QSA]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} ^/la/(.*)$

RewriteRule ^(.*)$ /la/index.php?q=$1 [L,QSA]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} ^/emea/(.*)$

RewriteRule ^(.*)$ /uk/index.php?q=$1 [L,QSA]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !=/favicon.ico

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Creating our settings.php

We can now have different settings (database, ...) for each site by creating a different settings file for each site. Place the settings.php for each file under a directory called after the domain name and subdirectory. In our example we would have the following setting files:

C:/xampp/htdocs/drupal/sites/default/settings.php -Base site Settings.php

C:/xampp/htdocs/drupal/sites/localhost.emea/settings.php -EMEA site Settings.php

C:/xampp/htdocs/drupal/sites/localhost.la/settings.php -LA site Settings.php

C:/xampp/htdocs/drupal/sites/localhost.uk/settings.php -UK site Settings.php

Now, start installing the site by using the below URLS

1. http://localhost – Base site

2. http://localhost/emea – EMEA site

3. http://localhost/la – LA site

4. http://localhost/uk – UK site

Enjoy the Drupal's multisite feature in the subdirectories.

Friday, September 24, 2010

MySQL Command-Line

shell> mysql –help

Connect to Server

shell> mysql -h host -u user -p

Enter password: ********

Disconnect from the Server

mysql> QUIT

On Unix, you can also disconnect by pressing Control-D.


Create Database

mysql> CREATE DATABASE menagerie;

Creating a database does not select it for use; you must do that explicitly. To make menagerie the current database, use this command:

mysql> USE menagerie

Database changed

Use a CREATE TABLE statement to specify the layout of your table:

mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),

-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

Once you have created a table, SHOW TABLES should produce some output:

mysql> SHOW TABLES;


To verify that your table was created the way you expected, use a DESCRIBE statement:

mysql> DESCRIBE pet;

After creating your table, you need to populate it. The LOAD DATA and INSERT statements are useful for this.


To load the text file pet.txt into the pet table, use this statement:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;


If you created the file on Windows with an editor that uses \r\n as a line terminator, you should use this statement instead:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet

-> LINES TERMINATED BY '\r\n';


mysql> SELECT VERSION(), CURRENT_DATE;

Keywords may be entered in any lettercase. The following queries are equivalent:

mysql> SELECT VERSION(), CURRENT_DATE;

mysql> select version(), current_date;

mysql> SeLeCt vErSiOn(), current_DATE;

It demonstrates that you can use mysql as a simple calculator:

mysql> SELECT SIN(PI()/4), (4+1)*5;

mysql> SELECT VERSION(); SELECT NOW();


Here is a simple multiple-line statement:

mysql> SELECT

-> USER()

-> ,

-> CURRENT_DATE;


If you decide you do not want to execute a command that you are in the process of entering, cancel it by typing \c:

mysql> SELECT

-> USER()

-> \c

The simplest form of SELECT retrieves everything from a table:

mysql> SELECT * FROM pet;

mysql> SELECT DATABASE();

mysql> SHOW TABLES;

mysql> DESCRIBE pet;

mysql> SELECT USER()