Skip to content

Instantly share code, notes, and snippets.

@burningTyger
Created August 26, 2012 13:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burningTyger/3479004 to your computer and use it in GitHub Desktop.
Save burningTyger/3479004 to your computer and use it in GitHub Desktop.
Drupal on Openshift

#Drupal on Openshift There is an existing repo for a quick install of Drupal 7 over at https://github.com/openshift/drupal-example. This didn't really cut the deal for me because the example was Drupal 7, I needed Drupal 6 and I wasn't happy about the way it is managed codewise.

I needed this:

  • Drupal 6
  • easy updates via git
  • simple module management
  • multisite setup

The following solution works for Drupal 7 as I originally intended to upgrade to it but then thought better of it – upgrading is a pain.

##Migrating from your old server to Openshift If you have Drupal running on a different machine that you either managed via good old ftp or ssh you will need to put your data in a suitcase and move to openshift. The setup is then slightly different. I managed three sites in a single multisite drupal install and backed up my databases first. If Drupal uses a MySQL db phpmyadmin is usually a good choice to use if you want to get hold of your data. You can use it on Openshift as well.

Make sure you only export your drupal database and not the other dbs. On Openshift then re-import the database.

##Setting up the Drupal repository for Openshift

Once you have that you can start setting uo Openshift for your needs:

  • Create an account and a domain if you haven't done so yet
  • Create an app in your console or via the rhc interface, in this example drupal
  • Add php, cron, mysql and myphpadmin cartridges to your app and clone the repo locally

From here on some more details:

git clone ssh://5678_your_id@drupal-your_domain.rhcloud.com/~/git/drupal.git/
cd drupal
rm -r php

You want to delete the old php directory and replace it with a drupal subtree. I found the subtree a lot easier to use because you will be able to easily update it and not worry about git submodule weirdness. If there is a better solution to that let me know.

So to include the current stable release of Drupal 6 this needs to be done like so:

git subtree add --prefix=php git://git.drupal.org/project/drupal.git 6.26
git commit -am 'replace php with drupal 6.26 stable'

Now you have a somewhat working Drupal in your repo but you need to fine tune everything a bit.

##Adding modules and the domain folders Now it's time to add your modules to your repo. Since we chose not to include drupal as a submodule but as a subtree we can easily add submodules to our module directory php/sites/all/modules.

If you like the admin_menu module for easy navigation you'd add it like that:

git submodule add http://git.drupal.org/project/admin_menu.git php/sites/all/modules/admin_menu

This will initiate another git repo inside your drupal repo but you still need to checkout the version that you want to use:

cd php/sites/all/modules/admin_menu/
git co 6.x-1.8
cd ../../../../..

You then need to tell git about your changes and commit:

git add php/sites/all/modules/admin_menu
git commit -m 'add and checkout admin_menu submodule'

Do this for all your modules.

Now that you Drupal and its modules in place you will need a place for your local files. If you upload media files to your site or if you make changes to the theme these files need a place to reside. Normally you'd have them inside your /php/sites/domain.com/files dir but on Openshift it is recommended to use the data dir for persistent file storage. To do just that you add a link to your domain dir that will redirect to the right place:

mkdir php/sites/domain.com
ln -s php/sites/domain.com ../../../../../data/domain

Now Drupal will find a files dir in your domain dir which links to the persistent file storage dir in a dir called app-root/data. However, you need to also create the domain dir in that place. For this you need to ssh into your Openshift repo:

ssh 5678_your_id@drupal-your_domain.rhcloud.com
mkdir app-root/data/domain

This is also a perfect moment to transfer all your files from your old server to Openshift. Everything that was previously in your files dir should go into the newly created dir on Openshift. There are many ways of doing that the easiest and probably fastest is to ssh into your repo and connect from there to your old server and then fetch all the files directly. Otherwise you can simply get a copy from the old server and then scp the files to their destination, assuming you are currently in your old server's file directory:

scp -r . 5678_your_id@drupal-your_domain.rhcloud.com:app-root/data/domain/

The multi site setup only works with domains properly set so the following command will create a www subdomain alias:

rhc app add-alias -a drupal --alias www.domain.com -l your_email

And don't forget to set a cname in your dns entry that points to drupal-your_domain.rhcloud.com.

These last steps, creating a domain folder in the data and creating a link there has to be done for all domains you want to use with this setup. Make sure that each domain has a different folder, if you need domain.com and sub.domain.com create dirs accordingly. The secret to muli site and multi domain hosting is just to create the appropriate directories each with its own settings.php which is created upon calling the site for the first time.

Note that a root domain alias won't work because you're only setting cname records and not your a records. For naked domains you will need to forward it to your subdomain (until Openshift gets a proper dns solution).

##Going live Everything is set up and you're ready to go. Your repo has everything you need and you can push it to Openshift:

git push -f origin master

Now you should visit your site and enter all the necessary information. Make sure to use the database username and password that Openshift has given you.

Have fun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment