Another Hydra - how to install multisite Drupal

The excellent description on secure multi-site Drupal installation by Justin Hileman worked like a charm. However, for my own records, it’s a good idea to save the exact procedure that I used on my Centos 5.3 system. Hopefully it might help someone else who wants a complete rundown. So, if you dare to unleash another hydra-headed monster on your website, here you go, Nick!

Hail Hydra

Scenario: using one database instance, I wanted to run multiple Drupal sites by using the same core modules and the same contributed modules. The plan was to first install Drupal core, and then to use CVS to get contributed modules, allowing for fairly simple CVS updates of new contributed modules. (Of course, you could do the same to obtain Drupal core, if you want.) Each Drupal site would live in its own folder below the webroot, while the actual core installation and multisites existed above the webroot in an area secure from casual intruders.

(You can also get all the following notes in a PDF file here)

On Centos 5.3, the file system would look something like this:

/var/www/drupal

/var/www/siteOne

/var/www/siteTwo

and where the webroot is at

/var/www/html

and the URL of the example is: www.wottsamotta.edu

Fortunately, Justin Hileman figured out the hard part, involving the establishment of symlinks from each of the multisites back to the core install of Drupal. I’ve integrated his instructions into my own step-by-step case, as follows:

[Note: these instructions assume you are logged in to Linux / Centos 5.3 as root or super-user, and that you have already set up an instance of mySQL with the database called “db1” username “natasha” and password “boris”]

1 Get the latest Drupal core and untar it somewhere, like /home/rocky/

1.1 cd /home/rocky/

1.2 tar -xzvf drupal-6.15.tar.gz

2 Create the folder where your Drupal core will live, then move the Drupal libraries there

2.1 cd /var/www

2.2 mkdir drupal

2.3 cp -R /home/rocky/drupal-6.15/* /var/www/drupal

3 Create the modules folder with CVS and grab some contrib modules (here only showing example Admin_Menu module)

3.1 cd /var/www/drupal/sites/all

3.2 cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d modules -l contributions/modules

3.3 cd /var/www/drupal/sites/all/modules

3.4 cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d admin_menu -r DRUPAL-6 - 1-5 contributions/modules/admin_menu

4 Create the first multisite folder under Drupal core /sites/ (note, use all dots in the folder name, as described), the example here is a multisite called “siteOne,” which will eventually be reached by the URL: www.wottsamotta.edu/siteOne/

4.1 mkdir /var/www/drupal/sites/www.wottsamotta.edu.siteOne

4.2 cd /var/www/drupal/sites/

4.3 chown apache www.wottsamotta.edu.siteOne

4.4 chmod a+x www.wottsamotta.edu.siteOne

4.5 chmod o+w www.wottsamotta.edu.siteOne

5 Now Create the multisite folder itself (where any site specific settings, scripts, templates, etc will live) and sub-folders that will become the means to connect this multisite back to the Drupal core (this will make more sense later when adding the symlinks)

5.1 mkdir /var/www/siteOne

5.2 mkdir /var/www/siteOne/sites

5.3 mkdir /var/www/siteOne/sites/www.wottsamotta.edu.siteOne

5.4 cd /var/www/siteOne/sites/

5.5 chown apache www.wottsamotta.edu.siteOne

5.6 chmod a+x www.wottsamotta.edu.siteOne

5.7 chmod o+w www.wottsamotta.edu.siteOne

6 Copy the settings.php from Drupal core to the new multisite, where specific prefixes can be set to distinguish its own tables from any other multisite. (Note, another option is to set up shared users, profiles, etc among the multisites… But that’s not covered here.) (Note: the filename is changed from default_settings.php to settings.php, and it lives in the root folder of www.wottsamotta.edu.siteOne/, not in www.wottsamotta.edu.siteOne/sites/default/ which doesn’t need to exist )

6.1 cp /var/www/drupal/sites/default/default.settings.php /var/www/drupal/sites/www.wottsamotta.edu.siteOne/settings.php

7 Edit the settings.php for siteOne to reflect the database connections and a unique prefix, which will create completely separate set of tables for siteOne (in this examples all the tables will be preceded by “s1_”)

7.1 cd /var/www/drupal/sites/www.wottsamotta.edu.siteOne/

7.2 vi settings.php

7.3 [edit to your rqmts] $db_url = ‘mysql://natasha:boris@localhost/db1’;

$db_prefix = ‘s1_‘;

8 Create some symlinks from siteOne component folders to the Drupal core folders (if you see any blinking symlinks, they didn’t work!)

8.1 cd /var/www (this shouldn’t matter, but it makes sense to create symlinks from a root folder)

8.2 ln -s /var/www/drupal/misc siteOne/misc

8.3 ln -s /var/www/drupal/modules siteOne/modules

8.4 ln -s /var/www/drupal/themes siteOne/themes

8.5 ln -s /var/www/drupal/includes siteOne/includes

8.6 ln -s /var/www/drupal/sites/all siteOne/sites/all

9 Create a symlink from siteOne /files folder to non-existent /files folder under /drupal/sites/www.wottsamotta.edu.siteOne (naturally this symlink will appear to be broken, & blinking, but it will work AFTER the drupal install.php script is run… so no worries!)

9.1 ln -s /var/www/drupal/sites/www.wottsamotta.edu.siteOne/files/ siteOne/sites/www.wottsamotta.edu.siteOne/files

10 Create a set of .php files that will include the core drupal files when HTTP requests them from siteOne (you can use vi to create each file then paste in the following contents), note that the files should be created in /var/www/siteOne/

10.1 vi index.php

<?php

chdir(‘/var/www/drupal/‘);

include(‘./index.php’);

?>

10.2 vi install.php

<?php

chdir(‘/var/www/drupal/‘);

include(‘./install.php’);

?>

10.3 vi update.php

<?php

chdir(‘/var/www/drupal/‘);

include(‘./update.php’);

?>

10.4 vi cron.php

<?php

chdir(‘/var/www/drupal/‘);

include(‘./cron.php’);

?>

10.5 vi xmlrpc.php

<?php

chdir(‘/var/www/drupal/‘);

include(‘./xmlrpc.php’);

?>

10.6 you should now have the following files under siteOne/ folder: index.php, install.php, update.php, cron.php, xmlrpc.php

11 Finally create the symlink that will send real HTTP requests to siteOne/ and by proxy to drupal/ from the URL: www.wottsamotta.edu/siteOne

11.1 cd /var/www

11.2 ln -s /var/www/siteOne /var/www/html/siteOne

12 Install the first multisite called siteOne by running the install.php script (note, if you try to list contents of folder itself nothing will happen)

12.1 point your browser at: www.wottsamotta.edu/siteOne/install.php

13 you will be prompted to enter your site info and admin password. (if there were any hangups with permissions on /files folders, try chmod 777 as in steps 4.5 and 5.7 above… but change it back to chmod 755, then chmod o+w afterwards)

14 your first multsite should now be running! if you check mySQL database, the tables should all be preceded by the prefix that you added in step 7.3, like “s1_actions”. best to hide or delete the install.php script

14.1 cd /var/www/siteOne

14.2 mv install.php DoneThat_install.php

15 now you can install the next multsite, for this example, called siteTwo.

15.1 mkdir /var/www/siteTwo

15.2 mkdir /var/www/siteTwo/sites

15.3 mkdir /var/www/siteTwo/sites/www.wottsamotta.edu.siteTwo

15.4 cd /var/www/siteTwo/sites/

15.5 chown apache www.wottsamotta.edu.siteTwo

15.6 chmod a+x www.wottsamotta.edu.siteTwo

15.7 chmod o+w www.wottsamotta.edu.siteTwo

16 add the siteTwo profile to the drupal/sites folder

16.1 mkdir /var/www/drupal/sites/www.wottsamotta.edu.siteTwo

16.2 cd /var/www/drupal/sites/

16.3 chown apache www.wottsamotta.edu.siteTwo

16.4 chmod a+x www.wottsamotta.edu.siteTwo

16.5 chmod o+w www.wottsamotta.edu.siteTwo

17 copy the settings.php from siteOne and edit it to reflect the unique table prefix needed for siteTwo (in this example “s2_”)

17.1 cp /var/www/drupal/sites/www.wottsamotta.edu.siteOne/settings.php /var/www/drupal/sites/www.wottsamotta.edu.siteTwo/settings.php

17.2 vi settings.php

17.3 [edit to your rqmts] $db_url = ‘mysql://natasha:boris@localhost/db1’;

$db_prefix = ‘s2_‘;

18 Create some symlinks from siteTwo component folders to the Drupal core folders (if you see any blinking symlinks, they didn’t work!)

18.1 cd /var/www (this shouldn’t matter, but it makes sense to create symlinks from a root folder)

18.2 ln -s /var/www/drupal/misc siteTwo/misc

18.3 ln -s /var/www/drupal/modules siteTwo/modules

18.4 ln -s /var/www/drupal/themes siteTwo/themes

18.5 ln -s /var/www/drupal/includes siteTwo/includes

18.6 ln -s /var/www/drupal/sites/all siteTwo/sites/all

19 Create a symlink from siteTwo /files folder to non-existent /files folder under /drupal/sites/www.wottsamotta.edu.siteTwo (naturally this symlink will appear to be broken, & blinking, but it will work AFTER the drupal install.php script is run… so no worries!)

19.1 ln -s /var/www/drupal/sites/www.wottsamotta.edu.siteTwo/files/ siteTwo/sites/www.wottsamotta.edu.siteTwo/files

20 Copy the needed .php files from siteOne to siteTwo (they are identical)

20.1 cd /var/www/siteOne

20.2 cp *.php /var/www/siteTwo/

20.3 cd /var/www/siteTwo

20.4 mv DoneThat_install.php install.php

21 Create the symlink that will send real HTTP requests to siteTwo/ and by proxy to drupal/ from the URL: www.wottsamotta.edu/siteTwo

21.1 cd /var/www

21.2 ln -s /var/www/siteTwo /var/www/html/siteTwo

22 Install the second multisite called siteTwo by running the install.php script

22.1 point your browser at: www.wottsamotta.edu/siteTwo/install.php

23 you will be prompted to enter your site info and admin password for siteTwo.

24 Now you should have multiple Drupal sites (siteOne and siteTwo) running from the same database, but with their own uniquely prefixed tables, and running from a single instance of drupal core, and a single sites/default/modules folder where all the contrib modules are stored. just to be safe, move or delete the install.php under siteTwo/

24.1 cd /var/www/siteTwo

24.2 mv install.php DoneThatAgain_install.php

25 Huzzah! Lots more Drupal for only one price of admission! PS. Be sure to thank Justin Hileman, who figured it all out!

Remember, you cannot fail, failure is not an option for Hydra!

Failure is not an option

Share