Recently, I was in need of a testing environment for Mahara’s functionality. For those that do not know, Mahara is an ePortfolio and social networking system, written in PHP, and developed right here in New Zealand.
To test Mahara, I came up with three possible approaches:
- download&install mahara from apt-get (with all its dependencies). Then setup and configure a local environment in which I would be working, as described here.
- Download a virtual machine (maybe from here) and configure it to host Mahara.
- Or create and deploy Mahara to my favourite app server, Heroku.
I tried for an hour or so to install Mahara locally, however I just ended up where I always do, Apache config hell.
I skipped trying to set up the VM as I was tired of looking at configuration files. So… I decided to try my hand at PHP apps on Heroku.
I had read a post a while back about getting PHP applications deployed to Heroku. This was motivation enough to get it running, here is how.
Pre-requisites:
- git
- heroku toolbelt
- other things
First we need to download and prepare the app directory.
`mkdir mahara-heroku
cd mahara-heroku
curl -OL https://launchpad.net/mahara/1.6/1.6.2/+download/mahara-1.6.2.zip
unzip mahara-1.6.2.zip
mv mahara-1.6.2/htdocs/* .
#clean up
rm mahara-1.6.2.zip
rm -rf mahara-1.6.2``#git setup
git init
git add .
git commit -m “Init Commit”
`
The second stage is setting up the Heroku server:
heroku create mahara-heroku --buildpack [https://github.com/grahamjenson/heroku-buildpack-mahara](https://github.com/grahamjenson/heroku-buildpack-mahara)
This will create a Heroku app with a buildpack I have forked from heroku-buildpack-php. This was inspired by ngson2000’s heroku-buildpack-mahara, though I think this is still in flux (I may go back to this when it becomes stable).
Now lets set up the database and config:
heroku addons:add heroku-postgresql:dev
This will return the reference to the database, e.g. HEROKU_POSTGRESQL_MAROON_URL.
Now check the credentials:
heroku pg:credentials HEROKU_POSTGRESQL_MAROON_URL
This will return something like
Connection info string: "dbname=abcdefg host=ec1-2-3-4-5.compute-1.amazonaws.com port=5432 user=iamauser password=thisisapassword sslmode=require"
Using this info we can create the Mahara config config.php:
<?php $cfg = new StdClass; $cfg->dbtype = 'postgres8'; $cfg->dbhost = 'ec1-2-3-4-5.compute-1.amazonaws.com'; $cfg->dbport = 5432; $cfg->dbname = 'abcdefg'; $cfg->dbuser = 'iamauser'; $cfg->dbpass = 'thisisapassword'; $cfg->dbprefix = ''; $cfg->dataroot = '/app'; $cfg->emailcontact = '';
One more change to mahara is necessary as I have not got gd working with freetype yet.
So the comment our the lines in lib/mahara.php:81
... //Check for freetype in the gd extension $gd_info = gd_info(); if (!$gd_info['FreeType Support']) { throw new ConfigSanityException(get_string('gdfreetypenotloaded', 'error')); } ...
We need to add this to git.
git add config.php git add lib/mahara.php git commit -m "added config"
Lets Deploy!
git push heroku master
Then we can visit out app at http://mahara-heroku.herokuapp.com/.
Future TODO’s/Refactorings
- Uploading zip files does not work, however setting $cfg->pathtounzip in your config file to point at an unzip binary (that you can add to your project” will fix this.
- Get GD with Freetype working. See UPDATE
- Getting rid of error warnings, by altering php.ini in the buildpackage.
- If you want background workers, or to execute the ~bin/php on the server, you need to add the paths heroku config:add LD_LIBRARY_PATH=/app/php/ext:/app/apache/lib.
- Heroku will wipe Mahara data, as it is set to a local folder
One of the more difficult TODOs, is getting GD with Freetype working.
I have attempted this by recompiling php (as suggested here with GD and Freetype. I have had limited success; here is a link to help with config errors.
A possible solution is to use vulcan to build php for heroku.
UPDATE:
With the help of ngson2000 in compiling PHP and apache, not to mention much of the config, GD with Freetype is now available.
Overall I found this very rewarding, as it required minimal configuration. If this idea were taken further, I image it would be an excellent way of testing out Mahara.