Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Drupal Multi-site on Local Ubuntu Server

The Foo

Create foo database - see: https://drupal.org/documentation/install/create-database.

Get Drupal - from terminal:

cd ~/public_html
git clone --branch 7.x http://git.drupal.org/project/drupal.git
mv drupal foo
cd foo
cp sites/default/default.settings.php sites/default/settings.php
chmod a+w sites/default/settings.php
chmod a+w sites/default

Configure clean URLs - from terminal:

nano .htaccess replace # RewriteBase /drupal with RewriteBase /~[userDir]/foo and save.

Run the installation script - from browser: http://localhost/~[userDir]/foo/install.php.

Rewrite permissions - from terminal:

chmod go-w sites/default/settings.php
chmod go-w sites/default

Check status report - from browser: http://localhost/foo/admin/reports/status.

The Bar

Create bar database - see: https://drupal.org/documentation/install/create-database.

Create the settings.php file - from terminal:

cd ~/public_html/foo
mkdir sites/bar
cp sites/default/default.settings.php sites/bar/settings.php
chmod -R a+w sites/bar

Configure clean URLs - from terminal:

nano .htaccess than add:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} ^/~[user]/bar/
RewriteRule ^ /~[user]/bar/index.php [L]

right before:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

Create and edit the sites.php file - from terminal:

cp sites/example.sites.php sites/sites.php and nano sites/sites.php than add following lines at the end of file:

$sites = array(
  'localhost.~[user].bar' => 'bar',
);

Create symbolic link - from terminal:

ln -s ~/public_html/foo ~/public_html/bar

Run the installation script - from browser: http://localhost/~[userDir]/bar/install.php.

Rewrite permissions - from terminal:

chmod go-w sites/bar/settings.php
chmod go-w sites/bar

Check status report - from browser: http://localhost/bar/admin/reports/status.

The Baz

Create baz database - see: https://drupal.org/documentation/install/create-database.

Create the settings.php file - from terminal:

cd ~/public_html/foo
mkdir sites/foo.baz
cp sites/default/default.settings.php sites/foo.baz/settings.php
chmod -R a+w sites/foo.baz

Configure clean URLs - from terminal:

nano .htaccess than add:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} ^/~[user]/foo/baz/
RewriteRule ^ /~[user]/foo/baz/index.php [L]

right before:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

Edit the sites.php file - from terminal:

nano sites/sites.php than add the new line:

$sites = array(
  'localhost.~[user].bar' => 'bar',
  'localhost.~[user].foo.baz' => 'foo.baz', //the new line.
);

Create symbolic link - from terminal:

ln -s ~/public_html/foo ~/public_html/foo/baz

Run the installation script - from browser: http://localhost/~[userDir]/foo/baz/install.php.

Rewrite permissions - from terminal:

chmod go-w sites/foo.baz/settings.php
chmod go-w sites/foo.baz

Check status report - from browser: http://localhost/foo/baz/admin/reports/status.

# Drupal multi-site without Apache userdir_module.
# The Foo.
# Create foo database (MySQL).
mysqladmin -u username -p create foo
mysql -u username -p
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON foo.* TO 'username'@'localhost' IDENTIFIED BY 'password';
exit
# Get Drupal than configure.
cd /var/www
git clone --branch 7.x http://git.foo.org/project/foo.git
mv drupal foo
cd foo
cp sites/default/default.settings.php sites/default/settings.php
chmod a+w sites/default/settings.php
chmod a+w sites/default
# Configure clean URLs. Replace # RewriteBase /drupal with RewriteBase /foo.
nano .htaccess
# Run the installation script by visiting http://localhost/foo. follow the flow untill the end.
#Rewrite back the permission.
chmod go-w sites/default/settings.php
chmod go-w sites/default
# Check status report by visiting http://localhost/foo/admin/reports/status.
# The Bar
# Create bar database (MySQL).
mysqladmin -u username -p create bar
mysql -u username -p
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON bar.* TO 'username'@'localhost' IDENTIFIED BY 'password';
exit
# Configure the site.
cd /var/www/foo
mkdir sites/bar
cp sites/default/default.settings.php sites/bar/settings.php
chmod -R a+w sites/bar
# Configure clean URLs.
nano .htaccess
# Add:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} ^/bar/
RewriteRule ^ /bar/index.php [L]
# Right before:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
# Create and edit the sites.php file.
cp sites/example.sites.php sites/sites.php
nano sites/sites.php
# Add following lines at the end of file.
$sites = array(
'localhost.bar' => 'bar',
);
# Create symbolic link.
ln -s /var/www/foo /var/www/bar
#Rewrite back the permission.
chmod go-w sites/bar/settings.php
chmod go-w sites/bar
# Check status report by visiting http://localhost/foo/admin/reports/status.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment