Developer Guide: Setting up Mothership environments in Apache

From Mothership
Jump to: navigation, search


Once you have installed Mothership, there are likely going to be some extra steps that you will want to take to get your site up and running in your environment.

This guide will walk you through setting up a Mothership environment in Apache.

Adding your host name to Apache

Your host name is typically localhost, but can be almost anything. To add the host, you will need to edit the /etc/hosts file, and add the following text:       localhost

Obviously, if you want to have a different host name, replace 'localhost' with whatever you like.

Assigning a port number and environment

Mothership works best when you assign the installation to a port number. You will need to edit your /etc/apache2/extra/httpd-vhosts.conf file to do this.

Add the following:

Listen [port number]
<VirtualHost *:[port number]>
  DocumentRoot "[path to the installation]/public"
   <Directory "[path to the installation]/public">
        AllowOverride All
        Options All
        SetEnv COG_ENV local

If you then restart Apache using the command sudo apachectl -k graceful, you will be informed if there are any problems with your configuration (for instance, if the install directory does not exist). If there are no problems, you should now be able to navigate to your admin panel via your browser, by going to localhost:[port number]/admin.


You will notice that in the configuration above, there is the line SetEnv COG_ENV local. This tells Mothership that you are working locally, and it is possible to route configuration settings to your environment (for instance, you would have different database details in your live environment than you would in your local environment).

To apply different config options to different environments, you can create subdirectories within the config directory of your installation. We will use database details as an example:

When you install Mothership, a config directory is created, with a file called db.yml within it, which will be populated with the database details you entered when you ran the installation. It will look something like this:

user: root
pass: password
name: database_name
charset: utf8

If you wanted to assign different database details for your local environment, you can create a subdirectory within the config directory, called local. In here you could create a new db.yml file that looks like this:

user: myuser
pass: mypassword
name: database_name
charset: utf8

These options will override those in the root level configuration. However, the configuration can also be inherited from the root level, so we could simplify this file by only including the variables that have changed:

user: myuser
pass: mypassword

If we wanted to include different database details for the live environment, we would set the COG_ENV to 'live' in the Apache configuration on the server, and store the details in the config/live/db.yml file.

It is also possible to nest environments. This is done by adding a hyphen to the environment variable, so if Louise has a different database setup to everyone else, she would set her environment variable to 'local-louise' in his Apache config.

Her database details would be stored in a the config/local/louise/db.yml file. Any variables that she does not enter will be inherited by the config/local/db.yml file, which in turn inherits details from the config/db.yml file. This rule applies to all configs throughout all Mothership modules.

Now that you have your site set up, you can start customising the content itself! See our guide for further help.