apache2_install.sh 4.52 KB
Newer Older
1
#!/bin/sh
Marc Duez's avatar
Marc Duez committed
2
CWD=$(pwd)
3

Marc Duez's avatar
Marc Duez committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
echo "installing useful packages"
echo "=========================="
apt-get update
apt-get -y install ssh
apt-get -y install zip unzip
apt-get -y install tar
apt-get -y install openssh-server
apt-get -y install build-essential
apt-get -y install python
apt-get -y install ipython
apt-get -y install python-dev
apt-get -y install postgresql
apt-get -y install apache2
apt-get -y install libapache2-mod-wsgi
apt-get -y install python2.5-psycopg2
apt-get -y install postfix
apt-get -y install wget
apt-get -y install python-matplotlib
apt-get -y install python-reportlab
apt-get -y install mercurial
/etc/init.d/postgresql restart

echo "downloading, installing and starting web2py"
echo "==========================================="
28 29 30
wget https://github.com/web2py/web2py/archive/R-2.9.5.zip 
unzip -d $(dirname $0) -n R-2.9.5.zip
cp -nR web2py-R-2.9.5/* web2py
Marc Duez's avatar
Marc Duez committed
31
mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py
32 33
rm -rf web2py-R-2.9.5/
rm -f R-2.9.5.zip
Marc Duez's avatar
Marc Duez committed
34
chown -R www-data:www-data web2py
35

Marc Duez's avatar
Marc Duez committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
echo "setting up apache modules"
echo "========================="
a2enmod ssl
a2enmod proxy
a2enmod proxy_http
a2enmod headers
a2enmod expires
a2enmod wsgi
a2enmod rewrite  # for 14.04
mkdir /etc/apache2/ssl

echo "creating a self signed certificate"
echo "=================================="
openssl genrsa 1024 > /etc/apache2/ssl/self_signed.key
chmod 400 /etc/apache2/ssl/self_signed.key
openssl req -new -x509 -nodes -sha1 -days 365 -key /etc/apache2/ssl/self_signed.key > /etc/apache2/ssl/self_signed.cert
openssl x509 -noout -fingerprint -text < /etc/apache2/ssl/self_signed.cert > /etc/apache2/ssl/self_signed.info

echo "rewriting your apache config file to use mod_wsgi"
echo "================================================="
Marc Duez's avatar
Marc Duez committed
56
echo "
Marc Duez's avatar
Marc Duez committed
57 58 59 60
WSGIDaemonProcess web2py user=www-data group=www-data processes=1 threads=1

<VirtualHost *:80>

61 62 63 64 65
    DocumentRoot /var/www
    <Directory />
      Options FollowSymLinks
      AllowOverride None
    </Directory>
66

67 68 69 70 71 72
    <Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride all
      Order allow,deny
      allow from all
    </Directory>
Marc Duez's avatar
Marc Duez committed
73

Marc Duez's avatar
Marc Duez committed
74
    ScriptAlias /cgi/ /usr/lib/cgi-bin/
75 76 77 78 79 80 81

    <Directory /usr/lib/cgi-bin/>
      Options Indexes FollowSymLinks
      Options +ExecCGI
      #AllowOverride None
      Require all granted
      AddHandler cgi-script cgi pl
82 83
    </Directory>

84 85 86 87
  <Directory /home/vidjil/server/../browser>
    AllowOverride None
  </Directory>

Marc Duez's avatar
Marc Duez committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
  CustomLog /var/log/apache2/access.log common
  ErrorLog /var/log/apache2/error.log
</VirtualHost>

<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/self_signed.cert
  SSLCertificateKeyFile /etc/apache2/ssl/self_signed.key

  WSGIProcessGroup web2py
  WSGIScriptAlias / $CWD/web2py/wsgihandler.py
  WSGIPassAuthorization On

  <Directory $CWD/web2py>
    AllowOverride None
    Require all denied
    <Files wsgihandler.py>
      Require all granted
    </Files>
  </Directory>

Marc Duez's avatar
Marc Duez committed
109 110 111 112
  <Directory $CWD/../browser>
    AllowOverride None
  </Directory>

Marc Duez's avatar
Marc Duez committed
113
  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \\
Marc Duez's avatar
Marc Duez committed
114
        $CWD/web2py/applications/\$1/static/\$2
Marc Duez's avatar
Marc Duez committed
115 116 117 118

  <Directory $CWD/web2py/applications/*/static/>
    Options -Indexes
    ExpiresActive On
Marc Duez's avatar
Marc Duez committed
119
    ExpiresDefault \"access plus 1 hour\"
Marc Duez's avatar
Marc Duez committed
120 121 122 123 124 125
    Require all granted
  </Directory>

  CustomLog /var/log/apache2/ssl-access.log common
  ErrorLog /var/log/apache2/error.log
</VirtualHost>
Marc Duez's avatar
Marc Duez committed
126
" > /etc/apache2/sites-available/default.conf  # FOR 14.04
Marc Duez's avatar
Marc Duez committed
127 128 129

sudo rm /etc/apache2/sites-enabled/*    # FOR 14.04
sudo a2ensite default                   # FOR 14.04
130
sudo a2enmod cgi
131
sudo ln -s $CWD/../browser /var/www/browser
132
sudo ln -s $CWD/../browser/cgi/align.cgi /usr/lib/cgi-bin
Marc Duez's avatar
Marc Duez committed
133

134 135 136 137 138
echo "config browser"
echo "=============="
echo "
var config = {
    /*cgi*/
139
    \"cgi_address\" : \"default\",
140 141 142 143 144 145 146 147 148
    
    /*database */
    \"use_database\" : true,
    \"db_address\" : \"default\",
    
    \"debug_mode\" : false  
}
" > $CWD/../browser/js/conf.js 

149 150 151 152 153 154 155 156 157 158
echo "install simple worker"
echo "====================="

echo "
description \"web2py vidjil task scheduler\"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
respawn limit 8 60 # Give up if restart occurs 8 times in 60 seconds.
exec sudo -u www-data python $CWD/web2py/web2py.py -K vidjil
respawn" > /etc/init/web2py-scheduler.conf
159

Marc Duez's avatar
Marc Duez committed
160 161
echo "restarting apache"
echo "================"
162

Marc Duez's avatar
Marc Duez committed
163 164 165 166 167
/etc/init.d/apache2 restart
cd $CWD/web2py
sudo -u www-data python -c "from gluon.widget import console; console();"
sudo -u www-data python -c "from gluon.main import save_password; save_password(raw_input('admin password: '),443)"
echo "done!"