Changes between Version 1 and Version 2 of InstallationGuidelines/Linux/Server/ApacheMySQL


Ignore:
Timestamp:
10/22/11 07:26:38 (13 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • InstallationGuidelines/Linux/Server/ApacheMySQL

    v1 v2  
    22 * [wiki:InstallationGuidelinesApacheModWSGI Apache] is a well-supported & flexible web server which can run Sahana well through mod_WSGI
    33 * [wiki:InstallationGuidelinesMySQL MySQL] is a well-supported database with an easy-to-use Admin UI (phpMyAdmin)
     4
     5The simplest way to install is using our attached installation scripts.
     6
     7This is split into 2 halves, as the 1st script can create a base image which is then customised per-instance using the configure script.
     8
     9Before Imaging: install-eden-apache-mysql.sh
     10{{{
     11#!/bin/sh
     12
     13# Script to turn a generic Debian Squeeze box into an Eden server
     14# with Apache & MySQL
     15
     16# Update system
     17apt-get update
     18apt-get upgrade -y
     19
     20# Install Admin Tools
     21apt-get install -y unzip psmisc mlocate telnet lrzsz vim elinks-lite rcconf htop sudo
     22# Email
     23apt-get -y install exim4-config exim4-daemon-light
     24
     25########
     26# MySQL
     27########
     28apt-get -y install mysql-server python-mysqldb phpmyadmin mytop
     29
     30#########
     31# Apache
     32#########
     33apt-get -y install libapache2-mod-wsgi
     34a2enmod rewrite
     35a2enmod deflate
     36a2enmod headers
     37a2enmod expires
     38
     39# Enable Basic Authentication for WebServices
     40sed -i 's|</IfModule>|WSGIPassAuthorization On|' /etc/apache2/mods-enabled/wsgi.conf
     41echo "</IfModule>" >> /etc/apache2/mods-enabled/wsgi.conf
     42
     43apache2ctl restart
     44
     45# Holding Page for Maintenance windows
     46cat << EOF > "/var/www/maintenance.html"
     47<html><body><h1>Site Maintenance</h1>Please try again later...</body></html>
     48EOF
     49
     50#########
     51# Python
     52#########
     53# Install Libraries
     54apt-get -y install libgeos-c1
     55
     56# Install Python 2.6
     57apt-get -y install python2.6 python-dev ipython
     58apt-get -y install python-lxml python-setuptools python-shapely python-dateutil
     59apt-get -y install python-serial
     60apt-get -y install python-imaging python-reportlab
     61apt-get -y install python-xlwt python-xlrd
     62apt-get -y install bzr
     63
     64#########
     65# Web2Py
     66#########
     67# Install Web2Py
     68adduser --system --disabled-password web2py
     69addgroup web2py
     70cd /home
     71bzr branch lp:~mdipierro/web2py/devel web2py --use-existing-dir
     72ln -s /home/web2py ~
     73cat << EOF > "/home/web2py/routes.py"
     74#!/usr/bin/python
     75default_application = 'eden'
     76default_controller = 'default'
     77default_function = 'index'
     78routes_onerror = [
     79        ('eden/400', '!'),
     80        ('eden/401', '!'),
     81        ('eden/*', '/eden/errors/index'),
     82        ('*/*', '/eden/errors/index'),
     83    ]
     84EOF
     85
     86##############
     87# Sahana Eden
     88##############
     89# Install Sahana Eden
     90cd web2py
     91cd applications
     92bzr branch lp:sahana-eden eden
     93# Fix permissions
     94chown web2py ~web2py
     95chown web2py ~web2py/applications/admin/cache
     96chown web2py ~web2py/applications/admin/cron
     97chown web2py ~web2py/applications/admin/databases
     98chown web2py ~web2py/applications/admin/errors
     99chown web2py ~web2py/applications/admin/sessions
     100chown web2py ~web2py/applications/eden
     101chown web2py ~web2py/applications/eden/cache
     102chown web2py ~web2py/applications/eden/cron
     103chown web2py ~web2py/applications/eden/databases
     104chown web2py ~web2py/applications/eden/errors
     105chown web2py ~web2py/applications/eden/models
     106chown web2py ~web2py/applications/eden/sessions
     107chown web2py ~web2py/applications/eden/static/img/markers
     108chown web2py ~web2py/applications/eden/uploads
     109mkdir -p ~web2py/applications/eden/uploads/gis_cache
     110mkdir -p ~web2py/applications/eden/uploads/images
     111mkdir -p ~web2py/applications/eden/uploads/tracks
     112chown web2py ~web2py/applications/eden/uploads/gis_cache
     113chown web2py ~web2py/applications/eden/uploads/images
     114chown web2py ~web2py/applications/eden/uploads/tracks
     115ln -s /home/web2py/applications/eden ~
     116
     117#####################
     118# Management scripts
     119#####################
     120cat << EOF > "/usr/local/bin/backup"
     121#!/bin/sh
     122NOW=$(date +"%Y-%m-%d")
     123mysqldump sahana > /root/backup-$NOW.sql
     124OLD=$(date --date='7 day ago' +"%Y-%m-%d")
     125rm -f /root/backup-$OLD.sql
     126EOF
     127chmod +x /usr/local/bin/backup
     128
     129cat << EOF > "/usr/local/bin/compile"
     130#!/bin/sh
     131cd ~web2py
     132python web2py.py -S eden -R applications/eden/static/scripts/tools/compile.py
     133apache2ctl restart
     134EOF
     135chmod +x /usr/local/bin/compile
     136
     137cat << EOF > "/usr/local/bin/maintenance"
     138#!/bin/sh
     139if [ "" != "off" ]
     140then
     141    a2dissite maintenance
     142    a2ensite production
     143    cd ~web2py && sudo -H -u web2py python web2py.py -K eden -Q >/dev/null 2>&1 &
     144else
     145    killall -u web2py python
     146    a2ensite maintenance
     147    a2dissite production
     148fi
     149apache2ctl restart
     150EOF
     151chmod +x /usr/local/bin/maintenance
     152
     153cat << EOF > "/usr/local/bin/pull"
     154#!/bin/sh
     155cd ~web2py/applications/eden
     156sed -i 's/deployment_settings.base.migrate = False/deployment_settings.base.migrate = True/g' models/000_config.py
     157bzr pull
     158/usr/local/bin/maintenance
     159rm -rf compiled
     160cd ~web2py
     161sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
     162cd ~web2py/applications/eden
     163sed -i 's/deployment_settings.base.migrate = True/deployment_settings.base.migrate = False/g' models/000_config.py
     164/usr/local/bin/compile
     165/usr/local/bin/maintenance off
     166EOF
     167chmod +x /usr/local/bin/pull
     168
     169# Change the value of prepopulate, if-necessary
     170cat << EOF > "/usr/local/bin/clean"
     171#!/bin/sh
     172/usr/local/bin/maintenance
     173cd ~web2py/applications/eden
     174rm -f databases/*
     175rm -f errors/*
     176rm -f sessions/*
     177rm -f uploads/*
     178sed -i 's/deployment_settings.base.migrate = False/deployment_settings.base.migrate = True/g' models/000_config.py
     179sed -i 's/deployment_settings.base.prepopulate = 0/deployment_settings.base.prepopulate = 1/g' models/000_config.py
     180rm -rf compiled
     181mysqladmin -f drop sahana
     182mysqladmin create sahana
     183cd ~web2py
     184sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
     185cd ~web2py/applications/eden
     186sed -i 's/deployment_settings.base.migrate = True/deployment_settings.base.migrate = False/g' models/000_config.py
     187sed -i 's/deployment_settings.base.prepopulate = 1/deployment_settings.base.prepopulate = 0/g' models/000_config.py
     188/usr/local/bin/maintenance off
     189/usr/local/bin/compile
     190EOF
     191chmod +x /usr/local/bin/clean
     192
     193cat << EOF > "/usr/local/bin/w2p"
     194#!/bin/sh
     195cd ~web2py
     196python web2py.py -S eden -M
     197EOF
     198chmod +x /usr/local/bin/w2p
     199
     200# END
     201}}}
     202
     203After Imaging: configure-eden-apache-mysql.sh
     204{{{
     205#!/bin/sh
     206
     207# Script to configure an Eden server
     208# - assumes that install-eden-apache-mysql.sh has been run
     209
     210BRANCH="~flavour/sahana-eden/trunk"
     211
     212if [ "$BRANCH" != "~flavour/sahana-eden/trunk" ]; then
     213    echo "parent_location = http://bazaar.launchpad.net/$BRANCH" > /home/web2py/applications/eden/.bzr/branch/branch.conf
     214fi
     215
     216echo -e "What domain name should we use? : \c "
     217read DOMAIN
     218
     219echo -e "What is host name should we use? : \c "
     220read hostname
     221sitename=$hostname".$DOMAIN"
     222
     223echo -e "What is the current root MySQL password: \c "
     224read rootpw
     225
     226# @ToDo: Generate a random password
     227echo -e "What should be the MySQL password for user 'sahana': \c "
     228read password
     229
     230echo "Now reconfiguring system"
     231
     232cd /etc
     233filename="hosts"
     234sed -i "s|localdomain localhost|localdomain localhost $hostname|" $filename
     235
     236cd /etc
     237filename="hostname"
     238echo $hostname > $filename
     239
     240cd /etc
     241filename="mailname"
     242echo $sitename >  $filename
     243
     244# Update system (in case run at a much later time than the install script)
     245apt-get update
     246apt-get upgrade -y
     247cd ~web2py
     248bzr pull
     249cd ~web2py/applications/eden
     250bzr pull
     251
     252# -----------------------------------------------------------------------------
     253# MySQL Database
     254# -----------------------------------------------------------------------------
     255echo "Setting up Database"
     256
     257# Allow root user to access database without entering password
     258cat << EOF > "/root/.my.cnf"
     259[client]
     260user=root
     261EOF
     262
     263echo "password='$rootpw'" >> "/root/.my.cnf"
     264
     265# Create database
     266mysqladmin create sahana
     267
     268# Create user for Sahana application
     269echo "CREATE USER 'sahana'@'localhost' IDENTIFIED BY '$password';" > "/tmp/mypass"
     270echo "GRANT ALL PRIVILEGES ON *.* TO 'sahana'@'localhost' WITH GRANT OPTION;" >> "/tmp/mypass"
     271mysql < /tmp/mypass
     272rm -f /tmp/mypass
     273
     274# Schedule backups for 02:01 daily
     275echo "1 2   * * * * root    /usr/local/bin/backup" >> "/etc/crontab"
     276
     277# -----------------------------------------------------------------------------
     278# Email
     279# -----------------------------------------------------------------------------
     280echo configure for Internet mail delivery
     281dpkg-reconfigure exim4-config
     282
     283# -----------------------------------------------------------------------------
     284# Sahana Eden
     285# -----------------------------------------------------------------------------
     286echo "Setting up Sahana"
     287
     288# Copy Templates
     289cp ~web2py/applications/eden/deployment-templates/cron/crontab ~web2py/applications/eden/cron
     290cp ~web2py/applications/eden/deployment-templates/models/000_config.py ~web2py/applications/eden/models
     291
     292sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' ~web2py/applications/eden/models/000_config.py
     293sed -i "s|akeytochange|$sitename$password|" ~web2py/applications/eden/models/000_config.py
     294sed -i "s|127.0.0.1:8000|$sitename|" ~web2py/applications/eden/models/000_config.py
     295sed -i 's|base.cdn = False|base.cdn = True|' ~web2py/applications/eden/models/000_config.py
     296
     297# Configure Database
     298sed -i 's|deployment_settings.database.db_type = "sqlite"|deployment_settings.database.db_type = "mysql"|' ~web2py/applications/eden/models/000_config.py
     299sed -i "s|deployment_settings.database.password = \"password\"|deployment_settings.database.password = \"$password\"|" ~web2py/applications/eden/models/000_config.py
     300
     301# Create the Tables & Populate with base data
     302sed -i 's|deployment_settings.base.prepopulate = 0|deployment_settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
     303sed -i 's|deployment_settings.base.migrate = False|deployment_settings.base.migrate = True|' ~web2py/applications/eden/models/000_config.py
     304cd ~web2py
     305sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
     306
     307# Configure for Production
     308sed -i 's|deployment_settings.base.prepopulate = 1|deployment_settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
     309sed -i 's|deployment_settings.base.migrate = True|deployment_settings.base.migrate = False|' ~web2py/applications/eden/models/000_config.py
     310cd ~web2py
     311sudo -H -u web2py python web2py.py -S eden -R applications/eden/static/scripts/tools/compile.py
     312
     313# Add Scheduler
     314sed -i 's|exit 0|cd ~web2py \&\& python web2py.py -K eden -Q >/dev/null 2>\&1 \&|' /etc/rc.local
     315echo "exit 0" >> /etc/rc.local
     316
     317#read -p "Press any key to Reboot..."
     318echo "Now rebooting.."
     319reboot
     320
     321# END
     322}}}