.. _Install: ******* Install ******* .. index:: Development Environment (Install) .. _development_install: Development Install =================== Set up like-live environment in Ubuntu using LAMP stack. Setup Test Server ----------------- #. 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):: ServerAdmin webmaster@localhost **ServerName dmcm-site** DocumentRoot **/home/userid/dmcm-site/** Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride **All** Order allow,deny allow from all . . . #. 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: #. Try getting more diagnostics **sudo proftpd -d9 -n**. #. Create directory: **sudo mkdir /var/run/proftpd/**. #. Start FTP server: **sudo proftpd**. (`source of Apache configuration instructions `_) .. index:: Django (Install) Install Django -------------- #. 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 `_). Install DMCM Application ------------------------ #. 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: #. Use the correct DATABASE ENGINE, NAME, USER & PASSWORD. #. The FTP USERID & PASSWORD should be those of your PC. #. Adjust the other settings if necessary. #. 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**. Set Apache to use Django ------------------------ #. 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):: ServerAdmin webmaster@localhost ServerName dmcm-site DocumentRoot /home/userid/dmcm-site/ **PythonPath "['/home/userid/dmcm-site'] + sys.path" SetHandler python-program PythonHandler django.core.handlers.modpython PythonOption django.root /dmcm SetEnv DJANGO_SETTINGS_MODULE dmcm.settings PythonDebug Off ** . . . #. 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 `_). .. index:: Live Deployment (Install) .. _live_deployment: Live Deployment =============== To an Apache shared hosting server. Deploy ------ #. Use SSH to log in to shared host Apache server: **ssh @** (FTP Userid and password should work). #. In order to avoid impacting other users you need to install your own python: #. Download ActivePython from . #. 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 :ref:`route_requests`). #. Install Django: #. Download Django from . #. Unzip `tar xzvf Django-1.2.1.tar.gz`. #. Install: `cd django-1.2.1` and `python setup.py install`. #. Install MySQLDB: #. Download from . #. 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 . #. 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 . #. Unzip: `tar xzvf Markdown-2.0.3.tar.gz`. #. Install: `cd Markdown-2.0.3` and `python setup.py install`. #. Install smartypants: #. Download from (bottom of page). #. Copy smartypants.py to somewhere on your python `sys.path`. #. E.g. `'/home/ahernp/lib/ActivePython-2.6/lib/python2.6/site-packages'`. #. 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 ** to create project. #. Copy project files from development environment. #. Run **python manage.py syncdb** to create database tables. .. _route_requests: Route Requests to Django ------------------------ #. 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. 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: #. Login to MySQL using **mysql -u -D -p**. #. Add indexes using **ALTER TABLE ADD INDEX ();**. #. Check using **SHOW INDEX FROM \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);