Multi-site on Linux - Configuring multi-site for a local user (UserDir)
Last updated on
30 August 2016
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
This guide will cover how to deploy multiple sites from within a single Drupal installation for a local user
The Setup
- Ubuntu 14.04 64-bit
- Apache/2.4.7 with UserDir module
- PHP 5.5.9-1ubuntu4
- MySQL 5.5.37-0ubuntu0.14.04.1
- Drupal 7x
The Sites Directory
- ~/public_html/foo
- ~/public_html/bar
- ~/public_html/foo/bar
The Sites URLs
The Foo
- Create database "foo" (https://drupal.org/documentation/install/create-database).
- Download and extract Drupal.
wget -P ~/ http://drupal.org/files/projects/drupal-x.y.tar.gz tar -zxvf ~/drupal-x.y.tar.gz mv ~/drupal-x.y ~/public_html/foo
- Create the settings.php file.
cd ~/public_html/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.
nano .htaccess
replace# RewriteBase /drupal
withRewriteBase /~[user]/foo
- Run the installation script, point your browser to http://localhost/~[user]/foo.
- Write permissions after install.
chmod go-w sites/default/settings.php chmod go-w sites/default
The Bar and the Foo/Bar
- Create database "bar" and "foo_bar" (https://drupal.org/documentation/install/create-database).
- Create the settings.php file.
cd ~/public_html/foo mkdir sites/bar mkdir sites/foo.bar cp sites/default/default.settings.php sites/bar/settings.php cp sites/default/default.settings.php sites/foo.bar/settings.php chmod -R a+w sites/bar chmod -R a+w sites/foo.bar
- Create the sites.php file.
cp sites/example.sites.php sites/sites.php nano sites/sites.php
Add following lines at the end of file (without syntax).
$sites = array( 'localhost.~[user].bar' => 'bar', 'localhost.~[user].foo.bar' => 'foo.bar', );
- Create symbolic link.
ln -s . ~/public_html/bar ln -s . ~/public_html/foo/bar
- Configure clean URLs.
nano .htaccess
AddRewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{REQUEST_URI} ^/~[user]/bar/ RewriteRule ^ /~[user]/bar/index.php [L]
and
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{REQUEST_URI} ^/~[user]/foo/bar/ RewriteRule ^ /~[user]/foo/bar/index.php [L]
right before
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^ index.php [L]
- Run the installation script, point your browser to http://localhost/~[user]/bar and http://localhost/~[user]/foo/bar in turns.
- Write permissions after install.
chmod go-w sites/bar/settings.php chmod go-w sites/foo.bar/settings.php chmod go-w sites/bar chmod go-w sites/foo.bar
Notes: replace "[user]" with actual username.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion