Set up like-live environment in Ubuntu using LAMP stack.
Install LAMP server: sudo tasksel install lamp-server.
Visit http://localhost/ to confirm Apache is running.
Create a directory under your Userid to use as the website (e.g. mkdir /home/userid/dmcm-site).
Add a dummy html file: cd /home/userid/dmcm-site and echo ‘dmcm site works!’ > index.html.
Go to the Apache sites-available directory: cd /etc/apache2/sites-available.
Copy the default site configuration: sudo cp default dmcm-site.
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>
. . .
Enable the new site: sudo a2ensite dmcm-site.
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.
Reload Apache: sudo /etc/init.d/apache2 reload.
Visit http://dmcm-site/ to check that it works.
Install FTP server using proftpd-basic package. Chose ‘standalone’ from configuration option. (User Guide)
If you get Connection Refused following a reboot then:
Mod_python: sudo apt-get install libapache2-mod-python python-mysqldb.
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).
Python packages: sudo apt-get install python-dev python-setuptools.
Django packages: sudo apt-get install python-django python-django-doc.
Python-Markdown: sudo apt-get install python-markdown (Markdown, Showdown Markdown viewer, python-markdown).
Smartypants: sudo easy_install smartypants (SmartyPants).
django-reversion: download; Add APP and MIDDLEWARE (instructions).
Download application from http://ahernp.com/download/dmcm-0-02.zip.
Use http://localhost/phpmyadmin to create a database dmcm.
Copy /site_media directory and contents from the dmcm download into the dmcm-site directory.
In the dmcm-site directory, create django project: django-admin startproject dmcm.
In the dmcm-site/dmcm directory create django application: python manage.py startapp cm.
Copy contents of equivalent directories from the dmcm download file into the new dmcm and dmcm/cm directories.
Update the settings.py:
Validate application: python manage.py validate.
To see SQL equivalent to model definitions: python manage.py sqlall cm.
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.
Add initial data to database using initial.sql from the dmcm download file.
Create a source directory in dmcm-site: mkdir /home/userid/dmcm-site/source.
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 />
. . .
Restart Apache: sudo /etc/init.d/apache2 restart
Visit http://dmcm-site/dmcm to access dmcm application.
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).
To an Apache shared hosting server.
Use SSH to log in to shared host Apache server: ssh <userid>@<domain>
(FTP Userid and password should work).
In order to avoid impacting other users you need to install your own python:
- Download ActivePython from <http://www.activestate.com/activepython>.
- Unzip: tar xzf ActivePython-2.6.5.12-linux-x86_64.tar.gz.
- Install: cd ActivePython-2.6.5.12-linux-x86_64 and ./install.sh.
- Place ActivePython on your path (see Route Requests to Django).
Install Django:
- Download Django from <http://www.djangoproject.com/download/>.
- Unzip tar xzvf Django-1.2.1.tar.gz.
- Install: cd django-1.2.1 and python setup.py install.
Install MySQLDB:
- Download from <http://sourceforge.net/projects/mysql-python/>.
- Unzip: tar xzvf MySQL-python-1.2.3c1.tar.gz.
- Install: cd MySQL-python-1.2.3c1 and python setup.py install.
Install MySQLDB:
- Download from <http://pypi.python.org/pypi/flup>.
- Unzip: tar xzvf flup-1.0.3.dev-20100525.tar.gz.
- Install: cd flup-1.0.3.dev-20100525 and python setup.py install.
Install Markdown:
- Download from <http://pypi.python.org/packages/source/M/Markdown/>.
- Unzip: tar xzvf Markdown-2.0.3.tar.gz.
- Install: cd Markdown-2.0.3 and python setup.py install.
Install django-reversion:
- Download from http://code.google.com/p/django-reversion/downloads/list.
- Unzip: tar xzvf django-reversion-1.3.1.tar.gz.
- Install: cd django-reversion-1.3.1 and python setup.py install.
Setup Django application:
- Create a directory for your projects and in it run django-admin.py startproject <project> to create project.
- Copy project files from development environment.
- Run python manage.py syncdb to create database tables.
Route requests to the Django application using FastCGI.
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]
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)
Make this file executable.
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:
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);