h1ghlevelb1ts

OpenShift and Drupal

Over the Christmas holidays I had some more time for OpenShift Express experiments. This time I experimented with Drupal based on this template.

After a slightly bumpy start and a quick pull request I got the basic installation up and running. One problem I encountered now, however, was that there is no easy way to manage data created by the application once running.

For example, Drupal users can upload images (per default into sites/default/files). Naturally I would like to add these uploaded resources under version control as well. However, that's not possible at the moment. OpenShift Express had the notion of a OPENSHIFT_DATA_DIR directory whose content is preserved between redeploys, but this directory is outside of the git repository. What I really want is to be able to use the same resource directory for my local development as well as on the remote site and manage the resources via git.

Locally I can add resources created in sites/default/files directly to git, but how to solve this on the sever side? The first problem I had, which I already encountered when installing Gollum on OpenShift, was that the repo directory from which the application is run from is not a git clone, but an git archive which means that there are no git control files. If OPENSHIFT_REPO_DIR were a git clone I could somehow add created files to the git repo, commit, push and finally pull it into my local environment. Unfortunately, the OpenShift gang decided for now against a full git clone mainly (afaik) due to size concerns. The good news is that there is a way to fix this yourself with some lines in the .openshift/action_hooks/build hook:

cd $OPENSHIFT_HOMEDIR/$OPENSHIFT_APP_NAME/runtime
rm -rf repo
git clone $OPENSHIFT_HOMEDIR/git/$OPENSHIFT_APP_NAME.git repo

This will delete the git archive and and replace it with a git clone. This is of course only half the rent. Somehow you need to add and commit new content on the server side. One way is to add some more code to the build hook,but so far I went with another simpler solution. I just ssh into onto the remote server.  As far as I know this was not always possible, but it is now. Just check your git remote url via git remote -v or rhc-user-info.The former will display something like:

ssh://<uuid>@<app-name>-<domain>.rhcloud.com/~/git/<app-name>.git

To ssh to your app use:

ssh <uuid>@<app-name>-<domain>

Once you are on the server you can change into OPENSHIFT_REPO_DIR run your git commands and finally git push. Once you've done that you can do a git pull from your local machine. The disadvatange of this method is that a git push on the remote server is of course running the git hooks meaning you are forcing a redeploy. Whether this is a bad thing depends on the usecase. An alternative could be to use scp to copy new resources to the local machine and then add them there, but of course you would need a way to determine what to copy.

As you can see, I am also still figuring things out. I haven't yet found an approach I am really happy with, but I am getting there :-) Let me know what you think.

--Hardy

P.S. For the Mac developers out there. To develop my Drupal app locally using the default Apache server I added the following to /System/Library/LaunchDaemons/org.apache.httpd.plist:
 

<!--?xml version="1.0" encoding="UTF-8"?-->

<plist version="1.0">
<dict>
        ...
        <string>system.preferences</string>
        <key>EnvironmentVariables</key>
        <dict>
                <key>OPENSHIFT_APP_NAME</key>
                <string>myapp</string>
                <key>OPENSHIFT_DB_USERNAME</key>
                <string>mydbuser</string>
                <key>OPENSHIFT_DB_PASSWORD</key>
                <string>mydbpass</string>
                <key>OPENSHIFT_DB_HOST</key>
                <string>127.0.0.1</string>
                <key>OPENSHIFT_DB_PORT</key>
                <string>3306</string>
        </dict>
</dict>
</plist>

This way I can develop my Drupal application locally without making any changes to settings.php in php/sites/default which contains the database connection settings.

Old comments

2013-02-06Sokratis
Hi there,I would like to ask if this is possible to host drupal sites in Openshift.Also is this possible to host Drupal sites?thanks
comments powered by Disqus