wiki:InstallationGuidelines/Linux/Server/RedHat

Version 8 (modified by Fran Boon, 10 years ago) ( diff )

--

RedHat

We normally recommend users to install on Debian servers wherever possible as those scripts are the best maintained.

If you need to install on a RedHat-based system then you may find the notes on this page useful:

Fedora

We have no Sahana-specific documentation, however this Web2Py script could be useful:

Also see:

CentOS 5

CentOS 5.x comes with just Python 2.4.3, so need to add the EPEL repository to upgrade to Python26

yum install -y lrzsz
yum install -y sqlite-devel zlib-devel bzip2-devel libxslt-devel
yum install -y gcc

wget https://fedoraproject.org/static/217521F6.txt
rpm --import 217521F6.txt

vim /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1


yum install -y python26 python26-devel
yum install -y python26-imaging

yum install -y httpd-devel
wget http://dl.fedoraproject.org/pub/epel/5/SRPMS/python26-mod_wsgi-3.3-1.el5.src.rpm
rpm -ivh python26-mod_wsgi-3.3-1.el5.src.rpm
yum install -y redhat-rpm-config
rpmbuild -bb /usr/src/redhat/SPECS/python26-mod_wsgi.spec
rpm -ivh /usr/src/redhat/RPMS/x86_64/python26-mod_wsgi-3.3-1.x86_64.rpm
cat << EOF > "/etc/httpd/conf.d/python26-mod_wsgi.conf"
<IfModule !python_module>
    <IfModule !wsgi_module>
        LoadModule wsgi_module modules/python26-mod_wsgi.so
        WSGISocketPrefix /var/run
    </IfModule>
</IfModule>
EOF

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
/usr/bin/python26 setup.py install
cd ..

wget http://pypi.python.org/packages/source/l/lxml/lxml-2.3.4.tar.gz
tar zxvf lxml-2.3.4.tar.gz
cd lxml-2.3.4
/usr/bin/python26 setup.py install
cd ..

yum install -y rpm-build
wget http://pkgs.repoforge.org/geos/geos-3.2.2-1.rf.src.rpm
rpm -ivh geos-3.2.2-1.rf.src.rpm
rpmbuild -bb /usr/src/redhat/SPECS/geos.spec
rpm -ivh /usr/src/redhat/RPMS/x86_64/geos*.rpm

wget http://pypi.python.org/packages/source/S/Shapely/Shapely-1.2.14.tar.gz
tar zxvf Shapely-1.2.14.tar.gz
cd Shapely-1.2.14
/usr/bin/python26 setup.py install
cd ..

yum install -y python26-numpy python26-numpy-devel
yum install -y libpng-devel
wget http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.1.0/matplotlib-1.1.0.tar.gz
tar zxvf matplotlib-1.1.0.tar.gz
cd matplotlib-1.1.0
/usr/bin/python26 setup.py install
cd ..

wget http://pypi.python.org/packages/source/x/xlwt/xlwt-0.7.4.tar.gz
tar zxvf xlwt-0.7.4.tar.gz
cd xlwt-0.7.4
/usr/bin/python26 setup.py install
cd ..

wget http://pypi.python.org/packages/source/x/xlrd/xlrd-0.7.7.tar.gz
tar zxvf xlrd-0.7.7.tar.gz
cd xlrd-0.7.7
/usr/bin/python26 setup.py install
cd ..

yum install -y freetype-devel
wget http://www.reportlab.com/ftp/reportlab-2.5.tar.gz
tar zxvf reportlab-2.5.tar.gz
cd reportlab-2.5
/usr/bin/python26 setup.py install
cd ..

wget http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz
tar zxvf python-dateutil-1.5.tar.gz
cd python-dateutil-1.5
/usr/bin/python26 setup.py install
cd ..

wget http://ipython.scipy.org/dist/0.10.2/ipython-0.10.2.tar.gz
tar zxvf ipython-0.10.2.tar.gz
cd ipython-0.10.2
/usr/bin/python26 setup.py install
cd ..

yum install -y mysql-server
yum install -y phpMyAdmin
yum install -y python26-mysqldb
/etc/init.d/mysqld start
chkconfig --level 3 mysqld on
chkconfig --level 4 mysqld on
chkconfig --level 5 mysqld on
mysqladmin -u root -p password new-password
<Enter - default password is blank>

yum install -y git

adduser -rd /var/www/web2py web2py
cd /var/www
git clone git://github.com/web2py/web2py.git
cat << EOF > "/var/www/web2py/routes.py"
#!/usr/bin/python26
default_application = 'eden'
default_controller = 'default'
default_function = 'index'
routes_onerror = [
        ('eden/400', '!'),
        ('eden/401', '!'),
        ('eden/*', '/eden/errors/index'),
        ('*/*', '/eden/errors/index'),
    ]
EOF
sed -i 's|python|python26|' /var/www/web2py/wsgihandler.py
ln -s /var/www/web2py /home/web2py
ln -s /var/www/web2py ~
cd web2py
cd applications
git clone git://github.com/flavour/eden.git
# Fix permissions
chown web2py ~web2py/
chown web2py ~web2py/applications/admin/cache
chown web2py ~web2py/applications/admin/cron
chown web2py ~web2py/applications/admin/databases
chown web2py ~web2py/applications/admin/errors
chown web2py ~web2py/applications/admin/sessions
chown web2py ~web2py/applications/eden
chown web2py ~web2py/applications/eden/cache
chown web2py ~web2py/applications/eden/cron
mkdir -p ~web2py/applications/eden/databases
chown web2py ~web2py/applications/eden/databases
chown web2py ~web2py/applications/eden/errors
chown web2py ~web2py/applications/eden/models
chown web2py ~web2py/applications/eden/sessions
chown web2py ~web2py/applications/eden/static/img/markers
mkdir -p ~web2py/applications/eden/static/cache/chart
chown web2py -R ~web2py/applications/eden/static/cache
chown web2py ~web2py/applications/eden/uploads
mkdir -p ~web2py/applications/eden/uploads/gis_cache
mkdir -p ~web2py/applications/eden/uploads/images
mkdir -p ~web2py/applications/eden/uploads/tracks
chown web2py ~web2py/applications/eden/uploads/gis_cache
chown web2py ~web2py/applications/eden/uploads/images
chown web2py ~web2py/applications/eden/uploads/tracks
ln -s /home/web2py/applications/eden ~

cat << EOF > "/usr/local/bin/backup"
#!/bin/sh
NOW=\$(date +"%Y-%m-%d")
mysqldump sahana > /root/backup-\$NOW.sql
OLD=\$(date --date='7 day ago' +"%Y-%m-%d")
rm -f /root/backup-\$OLD.sql
EOF
chmod +x /usr/local/bin/backup
cat << EOF > "/usr/local/bin/compile"
#!/bin/sh
cd ~web2py
python26 web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
service httpd restart
EOF
chmod +x /usr/local/bin/compile

cat << EOF > "/usr/local/bin/pull"
#!/bin/sh
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
git pull

# Maintenance
ln -sf /etc/httpd/conf/maintenance.conf /etc/httpd/conf/vhosts.conf
service httpd reload
killall -u web2py python

rm -rf compiled
cd ~web2py
sudo -H -u web2py python26 web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py

cd ~web2py
python26 web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
ln -sf /etc/httpd/conf/production.conf /etc/httpd/conf/vhosts.conf
cd ~web2py && sudo -H -u web2py python web2py.py -K eden -Q >/dev/null 2>&1 &
service httpd reload
EOF
chmod +x /usr/local/bin/pull

cat << EOF2 > "/usr/local/bin/clean"
#!/bin/sh
# Maintenance
ln -sf /etc/httpd/conf/maintenance.conf /etc/httpd/conf/vhosts.conf
service httpd reload
killall -u web2py python

cd ~web2py/applications/eden
rm -f databases/*
rm -f errors/*
rm -f sessions/*
rm -rf uploads/*
sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
sed -i 's/settings.base.prepopulate = 0/#settings.base.prepopulate = 0/g' models/000_config.py
rm -rf compiled
mysqladmin -f drop sahana
mysqladmin create sahana
cd ~web2py
sudo -H -u web2py python26 web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/g' models/000_config.py

cd ~web2py
python26 web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
ln -sf /etc/httpd/conf/production.conf /etc/httpd/conf/vhosts.conf
cd ~web2py && sudo -H -u web2py python web2py.py -K eden -Q >/dev/null 2>&1 &
service httpd reload
EOF2
chmod +x /usr/local/bin/clean

cat << EOF > "/usr/local/bin/w2p"
#!/bin/sh
cd ~web2py
python26 web2py.py -S eden -M
EOF
chmod +x /usr/local/bin/w2p
#!/bin/sh
# Script to configure an Eden server
# - assumes that install-eden-apache-mysql.sh has been run
echo -e "What domain name should we use? : \c "
read DOMAIN
echo -e "What host name should we use? : \c "
read hostname
sitename=$hostname".$DOMAIN"
echo -e "What is the current root MySQL password: \c "
read rootpw
# @ToDo: Generate a random password
echo -e "What should be the MySQL password for user 'sahana': \c "
read password
echo "Now reconfiguring system to use the hostname: $hostname"
cd /etc
filename="hosts"
sed -i "s|localdomain localhost|localdomain localhost $hostname|" $filename
cd /etc
filename="hostname"
echo $hostname > $filename
cd /etc
filename="mailname"
echo $sitename >  $filename
# -----------------------------------------------------------------------------
# Update system
#   in case run at a much later time than the install script
# -----------------------------------------------------------------------------
yum update
# If using the bleeding edge Web2py:
cd ~web2py
git pull
cd ~web2py/applications/eden
git pull
# -----------------------------------------------------------------------------
# Email
# -----------------------------------------------------------------------------
#echo configure for Internet mail delivery
#dpkg-reconfigure exim4-config
# -----------------------------------------------------------------------------
# Apache Web server
# -----------------------------------------------------------------------------
echo "Setting up Web server"
sed -i 's|#NameVirtualHost \*:80|NameVirtualHost \*:80|' /etc/httpd/conf/httpd.conf
cat << EOF >> "/etc/httpd/conf/httpd.conf"
Include conf/vhosts.conf
EOF
cat << EOF > "/etc/httpd/conf/production.conf"
<VirtualHost *:80>
  ServerName $hostname.$DOMAIN
  ServerAdmin webmaster@$DOMAIN
  DocumentRoot /var/www/web2py/applications
  WSGIScriptAlias / /var/www/web2py/wsgihandler.py
  ## Edit the process and the maximum-requests to reflect your RAM
  WSGIDaemonProcess web2py user=web2py group=web2py home=/var/www/web2py processes=4 maximum-requests=100
  RewriteEngine On
  # Stop GoogleBot from slowing us down
  RewriteRule .*robots\.txt$ /eden/static/robots.txt [L]
  # extract desired cookie value from multiple-cookie HTTP header
  #RewriteCond %{HTTP_COOKIE} registered=([^;]+)
  # check that cookie value is correct
  #RewriteCond %1 ^yes$
  #RewriteRule ^/$ /eden/ [R,L]
  #RewriteRule ^/$ /eden/static/index.html [R,L]
  RewriteCond %{REQUEST_URI}    !/phpmyadmin(.*)
  RewriteCond %{REQUEST_URI}    !/eden/(.*)
  RewriteRule /(.*) /eden/$1 [R]
  ### static files do not need WSGI
  <LocationMatch "^(/[\w_]*/static/.*)">
    Order Allow,Deny
    Allow from all
    SetOutputFilter DEFLATE
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    Header append Vary User-Agent env=!dont-vary
    ExpiresActive On
    ExpiresByType text/html "access plus 1 day"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType text/css "access plus 2 weeks"
    ExpiresByType image/ico "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
  </LocationMatch>
  ### everything else goes over WSGI
  <Location "/">
    Order deny,allow
    Allow from all
    WSGIProcessGroup web2py
  </Location>
  ErrorLog /var/log/httpd/$hostname_error.log
  LogLevel warn
  CustomLog /var/log/httpd/$hostname_access.log combined
</VirtualHost>
EOF
ln -sf /etc/httpd/conf/production.conf /etc/httpd/conf/vhosts.conf
service httpd restart
cat << EOF > "/etc/httpd/conf/maintenance.conf"
<VirtualHost *:80>
  ServerName $hostname.$DOMAIN
  ServerAdmin webmaster@$DOMAIN
  DocumentRoot /var/www
  RewriteEngine On
  RewriteCond %{REQUEST_URI} !/phpmyadmin(.*)
  RewriteRule ^/(.*) /maintenance.html
  <Location "/">
    Order deny,allow
    Allow from all
  </Location>
  ErrorLog /var/log/httpd/maintenance_error.log
  LogLevel warn
  CustomLog /var/log/httpd/maintenance_access.log combined
</VirtualHost>
EOF
# -----------------------------------------------------------------------------
# MySQL Database
# -----------------------------------------------------------------------------
echo "Setting up Database"
# Allow root user to access database without entering password
cat << EOF > "/root/.my.cnf"
[client]
user=root
EOF
echo "password='$rootpw'" >> "/root/.my.cnf"
# Create database
mysqladmin create sahana
# Create user for Sahana application
echo "CREATE USER 'sahana'@'localhost' IDENTIFIED BY '$password';" > "/tmp/mypass"
echo "GRANT ALL PRIVILEGES ON *.* TO 'sahana'@'localhost' WITH GRANT OPTION;" >> "/tmp/mypass"
mysql < /tmp/mypass
rm -f /tmp/mypass
# Schedule backups for 02:01 daily
echo "1 2   * * * * root    /usr/local/bin/backup" >> "/etc/crontab"
# -----------------------------------------------------------------------------
# Sahana Eden
# -----------------------------------------------------------------------------
echo "Setting up Sahana"
# Copy Templates
cp ~web2py/applications/eden/modules/templates/000_config.py ~web2py/applications/eden/models
sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' ~web2py/applications/eden/models/000_config.py
sed -i "s|akeytochange|$sitename$password|" ~web2py/applications/eden/models/000_config.py
sed -i "s|127.0.0.1:8000|$sitename|" ~web2py/applications/eden/models/000_config.py
sed -i 's|base.cdn = False|base.cdn = True|' ~web2py/applications/eden/models/000_config.py
# Configure Database
sed -i 's|#settings.database.db_type = "mysql"|settings.database.db_type = "mysql"|' ~web2py/applications/eden/models/000_config.py
sed -i "s|#settings.database.password = \"password\"|settings.database.password = \"$password\"|" ~web2py/applications/eden/models/000_config.py
# Create the Tables & Populate with base data
sed -i 's|settings.base.prepopulate = 0|settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
sed -i 's|settings.base.migrate = False|settings.base.migrate = True|' ~web2py/applications/eden/models/000_config.py
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
# Configure for Production
sed -i 's|settings.base.prepopulate = 1|settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
sed -i 's|settings.base.migrate = True|settings.base.migrate = False|' ~web2py/applications/eden/models/000_config.py
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -R applications/eden/static/scripts/tools/compile.py
# Add Scheduler
sed -i 's|exit 0|cd ~web2py \&\& python26 web2py.py -K eden -Q >/dev/null 2>\&1 \&|' /etc/rc.local
echo "exit 0" >> /etc/rc.local
#read -p "Press any key to Reboot..."
echo "Now rebooting.."
reboot
# END

@ToDo: matplotlib config (/etc/matplotlibrc not found)

Next

Administration Guide

CentOS alternate options

These are notes on some possible alternate options

Install a local version of Python27:

mkdir -p /opt/python2.7
wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar -jxvf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --prefix=/opt/python2.7 --with-threads --enable-shared
make && make install
cd ..
ln -s /opt/python2.7/lib/libpython2.7.so /usr/lib
ln -s /opt/python2.7/lib/libpython2.7.so.1.0 /usr/lib
ln -s /opt/python2.7/bin/python /usr/local/bin/python
ln -s /opt/python2.7/bin/python /usr/bin/python2.7
ln -s /opt/python2.7/lib/python2.7.so /opt/python2.6/lib/python2.7/config/
/sbin/ldconfig

wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
tar -xzf mod_wsgi-3.3.tar.gz
cd mod_wsgi-3.3
./configure --with-python=/usr/local/bin/python
make &&  make install
cd ..
echo "LoadModule wsgi_module modules/mod_wsgi.so" > /etc/httpd/conf.d/wsgi.conf

Use:
/opt/python2.7/bin/python

wget http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.3.tar.gz
tar zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
/opt/python2.7/bin/python setup.py install
cd ..

# PostgreSQL 8.1.x in CentOS 5! Better to use MySQL
#wget http://pkgs.repoforge.org/proj/proj-4.7.0-1.el5.rf.i386.rpm
#wget http://pkgs.repoforge.org/postgis/postgis-1.3.6-1.el5.rf.i386.rpm
#rpm -ivh proj-4.7.0-1.el5.rf.i386.rpm
#rpm -ivh postgis-1.3.6-1.el5.rf.i386.rpm
#yum install postgresql postgresql-server postgresql-devel
#wget http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz
#tar zxvf psycopg2-2.4.2.tar.gz
#cd psycopg2-2.4.2
#/opt/python2.6/bin/python setup.py install
#cd ..
#/etc/init.d/postgresql start
Note: See TracWiki for help on using the wiki.