Actions

System Administrator's Guide/Installing Mahara

From Mahara Wiki

< System Administrator's Guide

Nearby: Upgrading Mahara

This is a guide to installing Mahara. It's mainly targeted at the main platform on which people will install it (Linux with Apache), though Mahara can be installed on other platforms.

Mahara is a web application. This means it's not just an executable file you can download and run. You need a server to put it on (you can use your desktop as a server if you're just trialling it). You'll need to install other software for it to run too - such as the Apache web server and PostgreSQL database system. Another alternative is to use shared hosting (see below for more information).

If you're running Debian/Ubuntu, a lot of the required software (and even Mahara itself) can be installed using apt-get. If you're using some other linux distribution, you may be able to use your distribution specific install tool also.

Dependencies

Mahara is mainly designed for use on Linux, using the Apache web server, PostgreSQL database server and PHP. We also support its use with the MySQL database server.

In addition, members of the community have successfully got Mahara running on Mac OSX and Windows, and have also managed to use nginx instead of Apache. The Mahara developers fix bugs found that prevent running on these platforms, but don't explicitly test them from day to day, so you may have less luck than using a Linux box with Apache.

Hardware

See Hardware Requirements

Software

See Software Requirements

Get the code, and put on your webserver

In order for your Mahara to run, you need to put a copy of the code on your own server. You can either:

Once you have the code, copy the contents of the htdocs/ directory to your webserver. It is best if you either:

  • Copy the entire directory, then rename it to something like 'mahara' - so you will see your site at example.org/mahara/; or
  • Copy the contents of the htdocs/ directory to the top level public directory (often called htdocs or public_html) of your webserver, so you can see your site at example.org.

If you are unfamiliar with Ubuntu and need an in more detailed explanation about how to install the files and configure Apache, go to the step-by-step guide.

Create the Database

You need to create a database for Mahara and ensure that the webserver is able to connect to it. Instructions for the command line follow, if you have access to a CPanel or similar software you can create the database using it instead.

Your database must be UTF8 encoded. The commands below create a UTF8 encoded database, if you use CPanel etc., then you will have to make sure it creates you a UTF8 database.

Postgresql

Command line instructions for Postgres:

# Run these commands while su'd to the 'postgres' user
  # If you need to create a database user:
  createuser -SRDP (username)
  # Actual database creation
  createdb -O (username who will be connecting) -EUTF8 (databasename)

MySQL

MySQL and docker

There are instructions for spinning up MySQL in a docker container.

Command line instructions for MySQL:

mysql --user=root -p

 [enter password]

 CREATE DATABASE (databasename) CHARACTER SET utf8mb4;

 GRANT ALL ON (databasename).* TO 'username'@'localhost' IDENTIFIED BY 'password';

By the way, if possible, try to use PostgreSQL for your database if you can.

Create the Dataroot Directory

This is a directory where Mahara will write files that are uploaded to it, as well as some other files it needs to run. The main point about this directory is that it is one that the web server can write to. The other main point is that it cannot be inside the directory where your Mahara code is! In fact, if you have a public_html directory, it should not be inside that at all.

On your webserver, you will need to make this directory. If you have a public_html directory, make the directory alongside it. You can give it a name like 'maharadata'. Once you are done, you should have this directory structure (ignoring files):

.../yourusername/public_html
 .../yourusername/maharadata

You will need to make the maharadata directory writable by the web server user. You can either change its owner to be the web server user, or you can chmod it to 777. The latter isn't recommended, but if you're on shared hosting it's what you'll probably have to do. FTP programs will allow you to chmod the directory.

Create Mahara's config.php

In the Mahara htdocs directory is config-dist.php. You need to make a copy of this called config.php. You then need to go through the file and make changes where appropriate. The file is commented, and there are not many settings to change. However, take special note of the following settings:

  • database connection details: The database you set up in "Create the Database" on this page.
    • $cfg->dbname: 'postgres' or 'mysql'
    • $cfg->dbhost: The hostname of your database server. (In a shared hosting or development environment, this is often 'localhost')
    • $cfg->dbname: The name of the database to connect to
    • $cfg->dbuser: The username for connecting to the database
    • $cfg->dbpass: The password for connecting to the database
  • dataroot: The filesystem path where Mahara should store uploaded files. (See "Create the Dataroot Directory" on this page.)
    • This is a filesystem path, which on Linux will look like "/path/to/your/directory" and on Windows will look like "C:\path\to\your\directory". This is NOT a web address such as "http://example.org/maharadata"
  • passwordsaltmain: This is a secret random string used for encrypting stored user passwords. You should set it to something long and not human-readable, such as a string from random.org.
    • Note: Once set, you must not lose this string, or all stored user passwords will have to be reset! It is recommended to keep a secure backup of your config.php file
  • productionmode: You may wish to set this to "false" if your Mahara site is a test site or a development site. This will place a prominent banner on the top of each page that says "This is not a production site. Some files or data may be missing"; which can help prevent users from confusing your test site with your production site. Setting this to "false" will also enable on-screen display of warnings and error messages to aid in testing


(In addition to these, Mahara has many more optional settings that can be added to the config.php file. Look in the file lib/config-defaults.php in your Mahara code directory for the complete list.)

Apache Configuration

Note: If you're on shared hosting, you probably are not able to change this, so you can ignore this section.

The simplest of Apache VirtualHost configurations will be sufficient:

    <VirtualHost *:80>
         ServerName example.org
         DocumentRoot /path/to/mahara/htdocs

         ErrorLog /var/log/apache2/mahara.error.log
         CustomLog /var/log/apache2/mahara.access.log combined

         <Directory /home/nigel/mahara/htdocs>
                 AllowOverride All
         </Directory>
    </VirtualHost

Please note that your apache configuration should contain no ServerAliases. Mahara expects to be accessed through ONE URL. This gives certainty that cookies are set for the right domain, and also means that SSL certificates for the networking functionality can be generated for this one URL. If you use a server alias, you should expect to see problems like having to log in twice, and potentially SSO between your site and others breaking.

However, you can still make both example.org and www.example.org work for your site, if you use a second VirtualHost directive as well as the one above:

<VirtualHost *:80>
     ServerName www.example.org
     # You _can_ add ServerAliases here if you want more than one URL to
     # redirect to your main site
     # ServerAlias foo.example.org

     Redirect Permanent / http://example.org/
</VirtualHost>

Adjust your PHP settings

In your php.ini file (often found in /etc/php5/apache2/php.ini), make sure you have these:

register_globals off
 magic_quotes_runtime off
 magic_quotes_sybase off
 magic_quotes_gpc off
 log_errors on
 allow_call_time_pass_reference off
 upload_max_filesize 50M
 post_max_size 50M

Run the Installer

As of version 1.5.0 of Mahara, there are now two options for installing Mahara. Most users will want to use the web-based installer but more advanced users may wish to use the Command-Line Interface installer as an alternative.

Using the web-based installer

Once you have set up your config.php (and apache configuration, if not on shared hosting), you should now be able to navigate to the Mahara installation using your web browser. This will pop up a page stating the conditions of using Mahara, and will ask for agreement. If you agree with the conditions, click "agree" and Mahara will install itself into your database. Click continue, and you will be asked to change the administrator's password, then you'll be logged in to your new Mahara installation. Congratulations!

Note: The admin's username is 'admin'. Before Mahara 1.2, you will have to log in before you can change your password. The admin's default password is mahara.

Run the Command-Line Interface Installer

Since version 1.5.0, Mahara has had a command-line installation and upgrade toolset which provide an excellent alternative to the web-based installer.

The Command Line Interface (CLI) installer needs to be run as the same user that your web server will run as because it creates a number of directories and sets file ownerships within the document root.

Navigate to the mahara/htdocs directory and run: php admin/cli/install.php --adminpassword='examplepassword' --adminemail=youremailaddress

You can optionally specify the --verbose option to see exactly what the installation process does or --help for additional help on the options to the installer.

What if the installation process breaks with an error?

Sometimes this can happen. Normally this is because of some misconfiguration in your system - for example, you haven't granted your database user permission to create tables, or you aren't using a high enough version of your database (see the dependencies). Sometimes, it's because of a bug in the Mahara installer. In order to find out, you will need to check the error log for your webserver. Mahara dumps detailed information in there where a bug occurs.

The message might show you that the problem is with your configuration, but if it looks like a problem with Mahara, you should make a bug report with the information from your logs, so we can fix it.

If you were able to fix the problem, you might need to drop and re-create your database again, so you're starting the installation again without any of the previously installed tables in the way.

Final Tasks (don't forget!): Email & Cron Job

1. You may wish to check that Mahara can send email by trying to register on your site. If you receive a registration email, all is well. If you get a message saying "Sorry, your registration attempt was unsuccessful. This is our fault, not yours...", then you will need to install a mail transport agent (such as sendmail, exim, postfix, nullmailer) on your server, or specify an outgoing (SMTP) mail server in your config.php (form version 1.4 mail settings can be configured in Configure Site -> Site options -> Email). See the troubleshooting page, or this thread for more details.

2. You will need to set up a cron job to hit htdocs/lib/cron.php every minute. Mahara implements its own cron internally, so hitting cron every minute is sufficient to make everything work.

If you don't set up the cron job, you will find that RSS feeds will not update, and some email notifications won't be sent out, such as forum post notifications.

You can set it up using the command line 'php' command to run the cron script, or by using a command line web browser such as lynx or w3m.

Something like the following in a crontab file will be sufficient:

* * * * * curl http://your-mahara-site.org/lib/cron.php

If you run cron using curl, the cron output will be logged in your apache error log. If you wish to separate where it's logged to away from your apache logs (which is a particularly good idea, though slightly harder to set up), read the separate article about Mahara's cron.

Secure your Mahara installation

There are a few things that can be done to increase the security of your installation by enabling virus scanning and extra spam protections.

Have a look under Sites options, Security settings.

My Mahara is installed - now what?

Congratulations on getting your Mahara installed! Now read the Next Steps article to see what you can do now - for example, installing a new language pack and theme.

And if you haven't already, now might be a good time to join the Mahara community - you can get help and ideas for your Mahara from a world-wide community of enthusiastic users. We hope to see you on the forums soon!

Troubleshooting

If you are having problems installing Mahara, please check out the Installation Instructions Troubleshooting Page for answers to some common problems.

Mahara and Shared Hosting

Shared hosting isn't as good as having a machine where you can have administrator access. If you would still like to install Mahara on shared hosting, you can follow these installation instructions. This guide will show you how to install Mahara via cPanel and is designed for users who don't have any previous experience with creating websites or setting up databases.

You could also try Softaculous and let us know if that works for you as we have not tried it and don't know how well the installation process there works.

Subpages