Skip to content

Dev Installation on OS X (Apache and MySQL)

floating edited this page Apr 5, 2011 · 12 revisions

Here are some steps to get a development installation up and running without changing the settings.py file. I am assuming you have already forked or cloned the Concert repository, if you haven't done that yet, please clone it to wherever on your filesystem you'd like. My installation lies in /Users/colin/Projects/Concert/.

Using MacPorts, install apache2, mod_python26, and the mysql5 packages. ModPython is outdated and no longer in development, and I will switch these instructions to wsgi sometime soon.

sudo port install apache2 mysql5 mod_python26

Once that is complete, you'll need to configure apache for your installation.

Apache Setup

First, make sure mod_python is enabled. In /opt/local/apache2/conf/httpd.conf, add this line to the end of the LoadModule lines if it doesn't already exist:

LoadModule python_module modules/mod_python.so

A little below that in the same file, there is User and Group settings. I have changed these to my own username, and a group for which I am a member, since I put my installation files under my home folder. This is probably not necessary, but works for me.

Uncomment the following line, so we can do some virtual hosts:

Include conf/extra/httpd-vhosts.conf

At the very end of this file, add the following lines:

MaxRequestsPerChild 1
ServerLimit 5

They will make sure you don't have to restart apache after changing any python files, and the ServerLimit for making sure you don't blow your machine up with too many processes.

We are done with httpd.conf. Now on to the virtual host.

In /opt/local/apache2/conf/extra/httpd-vhosts.conf, I have the following:

# Concert
Listen *:8896

<VirtualHost *:8896>
    DocumentRoot "/Users/colin/Projects/Concert/concertapp"

    <Directory "/Users/colin/Projects/Concert/concertapp">
      AllowOverride All
      Allow from All
      Order allow,deny
    </Directory>



    <Location "/">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE concertapp.settings
        PythonDebug On
        PythonPath "['/Users/colin/Projects/Concert'] + sys.path"
    </Location>

    # Serve static files from media directory
    <Location "/media">
        SetHandler None
    </Location>

</VirtualHost>

I would suggest doing the same thing, but obviously replace all of the paths with your own applicable ones (and a port number that you like to look at). We are done with apache configuration.

For convenience, I've added the following lines to ~/.bash_login:

alias apachestart='sudo /opt/local/apache2/bin/apachectl start'
alias apachestop='sudo /opt/local/apache2/bin/apachectl stop'

Now apachestart, and point your browser to http://localhost:8896/ and hopefully you will see some python errors. This means that ModPython is working, and next is to set up a MySQL user.

MySQL Setup

In the settings.py file, we have hardcoded some entries for database credentials, so it is easiest to just create the same database info on your local install.

I've set up the following aliases for convenience:

alias mysqlstart='sudo /opt/local/bin/mysqld_safe5'
alias mysqlstop='sudo /opt/local/bin/mysqladmin5 -u root -p shutdown'

To startup mysql, sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql then run mysqlstart (in a separate terminal tab).

After logging into the mysql shell (mysql5 -u root -p), the first step is to create our database:

mysql> CREATE DATABASE concert;

Then the user:

mysql> CREATE USER 'concert'@'localhost' IDENTIFIED BY 'concert';
mysql> GRANT ALL PRIVILEGES ON concert.* TO 'concert'@'localhost';

Now from your terminal, from inside the concertapp/ directory, run Django's ./manage.py syncdb command and the database should be created.