Install

Development Install

Set up like-live environment in Ubuntu using LAMP stack.

Setup Test Server

  1. Install LAMP server: sudo tasksel install lamp-server.

  2. Visit http://localhost/ to confirm Apache is running.

  3. Create a directory under your Userid to use as the website (e.g. mkdir /home/userid/dmcm-site).

  4. Add a dummy html file: cd /home/userid/dmcm-site and echo ‘dmcm site works!’ > index.html.

  5. Go to the Apache sites-available directory: cd /etc/apache2/sites-available.

  6. Copy the default site configuration: sudo cp default dmcm-site.

  7. Edit the new configuration file, gksudo geany dmcm-site giving (‘**’ denote changes):

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        **ServerName dmcm-site**
    
        DocumentRoot **/home/userid/dmcm-site/**
        <Directory />
            Options FollowSymLinks
            AllowOverride None
        </Directory>
        <Directory **/home/userid/dmcm-site/**>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride **All**
            Order allow,deny
            allow from all
        </Directory>
        . . .
  8. Enable the new site: sudo a2ensite dmcm-site.

  9. Edit the hosts file: gksudo geany /etc/hosts.

    Change the first line, adding the new site to the end, giving: 127.0.0.1 localhost dmcm-site.

  10. Reload Apache: sudo /etc/init.d/apache2 reload.

  11. Visit http://dmcm-site/ to check that it works.

  12. Install FTP server using proftpd-basic package. Chose ‘standalone’ from configuration option. (User Guide)

    If you get Connection Refused following a reboot then:

    1. Try getting more diagnostics sudo proftpd -d9 -n.
    2. Create directory: sudo mkdir /var/run/proftpd/.
    3. Start FTP server: sudo proftpd.

(source of Apache configuration instructions)

Install Django

  1. Mod_python: sudo apt-get install libapache2-mod-python python-mysqldb.

  2. Phpmyadmin: sudo apt-get install libapache2-mod-auth-mysql phpmyadmin.

    Configure it to use apache2 (if you made a mistake you can reconfigure using sudo dpkg-reconfigure phpmyadmin. Visit http://localhost/phpmyadmin to log into phpmyadmin (username will be root and password that chosen during the install of the server).

  3. Python packages: sudo apt-get install python-dev python-setuptools.

  4. Django packages: sudo apt-get install python-django python-django-doc.

  5. Python-Markdown: sudo apt-get install python-markdown (Markdown, Showdown Markdown viewer, python-markdown).

  6. Smartypants: sudo easy_install smartypants (SmartyPants).

  7. django-reversion: download; Add APP and MIDDLEWARE (instructions).

Install DMCM Application

  1. Download application from http://ahernp.com/download/dmcm-0-02.zip.

  2. Use http://localhost/phpmyadmin to create a database dmcm.

  3. Copy /site_media directory and contents from the dmcm download into the dmcm-site directory.

  4. In the dmcm-site directory, create django project: django-admin startproject dmcm.

  5. In the dmcm-site/dmcm directory create django application: python manage.py startapp cm.

  6. Copy contents of equivalent directories from the dmcm download file into the new dmcm and dmcm/cm directories.

  7. Update the settings.py:

    1. Use the correct DATABASE ENGINE, NAME, USER & PASSWORD.
    2. The FTP USERID & PASSWORD should be those of your PC.
    3. Adjust the other settings if necessary.
  8. Validate application: python manage.py validate.

  9. To see SQL equivalent to model definitions: python manage.py sqlall cm.

  10. Create SQL tables on database: python manage.py syncdb.

    The first time this is run for a project you will be prompted to create Superuser details.

  11. Add initial data to database using initial.sql from the dmcm download file.

  12. Create a source directory in dmcm-site: mkdir /home/userid/dmcm-site/source.

Set Apache to use Django

  1. Edit the Apache configuration file, gksudo geany /etc/apache2/sites-available/dmcm-site to add PythonPath and Location where Django application is to be run (‘**’ denote changes):

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName dmcm-site
    
        DocumentRoot /home/userid/dmcm-site/
    
        **PythonPath "['/home/userid/dmcm-site'] + sys.path"
        <Location "/dmcm">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
            PythonOption django.root /dmcm
        SetEnv DJANGO_SETTINGS_MODULE dmcm.settings
        PythonDebug Off
        </Location>**
    
        <Directory />
    . . .
  2. Restart Apache: sudo /etc/init.d/apache2 restart

  3. Visit http://dmcm-site/dmcm to access dmcm application.

  4. Look at Apache log in the event of errors: geany /var/log/apache2/error.log.

(source of Apache-Django configuration instructions).

Version control: Package mercurial (Mercurial Version Control, tips).

Live Deployment

To an Apache shared hosting server.

Deploy

  1. Use SSH to log in to shared host Apache server: ssh <userid>@<domain>

    (FTP Userid and password should work).

  2. In order to avoid impacting other users you need to install your own python:

    1. Download ActivePython from <http://www.activestate.com/activepython>.
    2. Unzip: tar xzf ActivePython-2.6.5.12-linux-x86_64.tar.gz.
    3. Install: cd ActivePython-2.6.5.12-linux-x86_64 and ./install.sh.
    4. Place ActivePython on your path (see Route Requests to Django).
  3. Install Django:

    1. Download Django from <http://www.djangoproject.com/download/>.
    2. Unzip tar xzvf Django-1.2.1.tar.gz.
    3. Install: cd django-1.2.1 and python setup.py install.
  4. Install MySQLDB:

    1. Download from <http://sourceforge.net/projects/mysql-python/>.
    2. Unzip: tar xzvf MySQL-python-1.2.3c1.tar.gz.
    3. Install: cd MySQL-python-1.2.3c1 and python setup.py install.
  5. Install MySQLDB:

    1. Download from <http://pypi.python.org/pypi/flup>.
    2. Unzip: tar xzvf flup-1.0.3.dev-20100525.tar.gz.
    3. Install: cd flup-1.0.3.dev-20100525 and python setup.py install.
  6. Install Markdown:

    1. Download from <http://pypi.python.org/packages/source/M/Markdown/>.
    2. Unzip: tar xzvf Markdown-2.0.3.tar.gz.
    3. Install: cd Markdown-2.0.3 and python setup.py install.
  7. Install smartypants:
    1. Download from <http://web.chad.org/projects/smartypants.py/> (bottom of page).
    2. Copy smartypants.py to somewhere on your python sys.path.
    3. E.g. ‘/home/ahernp/lib/ActivePython-2.6/lib/python2.6/site-packages’.
  8. Install django-reversion:

    1. Download from http://code.google.com/p/django-reversion/downloads/list.
    2. Unzip: tar xzvf django-reversion-1.3.1.tar.gz.
    3. Install: cd django-reversion-1.3.1 and python setup.py install.
  9. Setup Django application:

    1. Create a directory for your projects and in it run django-admin.py startproject <project> to create project.
    2. Copy project files from development environment.
    3. Run python manage.py syncdb to create database tables.

Route Requests to Django

  1. Route requests to the Django application using FastCGI.

  2. In the directory that the application is run from on the server create a .htaccess file which tells Apache to route requests to fcgi:

    AddHandler fastcgi-script .fcgi
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ service.fcgi/$1 [QSA,L]
  3. Create the service.fcgi file:

    #!/home/ahernp/lib/ActivePython-2.6/bin/python
    import sys, os
    
    # Add a custom Python path.
    sys.path.insert(0, "/home/ahernp/lib/ActivePython-2.6")
    sys.path.insert(0, "/home/ahernp/projects/django")
    
    # Set the DJANGO_SETTINGS_MODULE environment variable.
    os.environ['DJANGO_SETTINGS_MODULE'] = "ahernp.settings"
    
    from django.core.servers.fastcgi import runfastcgi
    runfastcgi(method="prefork", daemonize="false", maxrequests=5)
    
  4. Make this file executable.

Troubleshooting

Check error log of server using a text editor (e.g. emacs /var/log/httpd/ahernp.com.error_log).

If you get “Unhandled Exception” then run your .fcgi file manually, one command at a time, on the python command line to get diagnostics.

If the CREATE INDEX commands don’t work then:

  1. Login to MySQL using mysql -u <userid> -D <database> -p.
  2. Add indexes using ALTER TABLE <table_name> ADD INDEX <index_name> (<column_names>);.
  3. Check using SHOW INDEX FROM <table_name>G.

Cardgen

Use cardgen to create the ALTER TABLE commands.

Data:

#Index,#Table,#Column
booking_room_d8572d9d,booking_room,hotel_id
booking_booking_d8572d9d,booking_booking,hotel_id
booking_booking_199461f6,booking_booking,start_date
booking_bookingdotcomreservation_75b3adaa,booking_bookingdotcomreservation,booking_id
booking_bookingdotcomroom_6f3ce47,booking_bookingdotcomroom,res_id
booking_bookingdotcompricing_6f3ce47,booking_bookingdotcompricing,res_id

Template:

ALTER TABLE #Table ADD INDEX #Index (#Column);

Result:

ALTER TABLE booking_room ADD INDEX booking_room_d8572d9d (hotel_id);
ALTER TABLE booking_booking ADD INDEX booking_booking_d8572d9d (hotel_id);
ALTER TABLE booking_booking ADD INDEX booking_booking_199461f6 (start_date);
ALTER TABLE booking_bookingdotcomreservation ADD INDEX booking_bookingdotcomreservation_75b3adaa (booking_id);
ALTER TABLE booking_bookingdotcomroom ADD INDEX booking_bookingdotcomroom_6f3ce47 (res_id);
ALTER TABLE booking_bookingdotcompricing ADD INDEX booking_bookingdotcompricing_6f3ce47 (res_id);

Table Of Contents

Previous topic

Processes

Next topic

Code

This Page