1 | #!/bin/bash |
---|
2 | echo "This script will: |
---|
3 | 1) install all modules need to run web2py on Ubuntu 14.04 |
---|
4 | 2) install web2py in /home/www-data/ |
---|
5 | 3) create a self signed ssl certificate |
---|
6 | 4) setup web2py with mod_wsgi |
---|
7 | 5) overwrite /etc/apache2/sites-available/default |
---|
8 | 6) restart apache. |
---|
9 | |
---|
10 | You may want to read this script before running it. |
---|
11 | |
---|
12 | Press a key to continue...[ctrl+C to abort]" |
---|
13 | |
---|
14 | read CONFIRM |
---|
15 | |
---|
16 | |
---|
17 | # optional |
---|
18 | # dpkg-reconfigure console-setup |
---|
19 | # dpkg-reconfigure timezoneconf |
---|
20 | # nano /etc/hostname |
---|
21 | # nano /etc/network/interfaces |
---|
22 | # nano /etc/resolv.conf |
---|
23 | # reboot now |
---|
24 | # ifconfig eth0 |
---|
25 | |
---|
26 | echo "installing useful packages" |
---|
27 | echo "==========================" |
---|
28 | apt-get update |
---|
29 | apt-get -y install ssh |
---|
30 | apt-get -y install zip unzip |
---|
31 | apt-get -y install tar |
---|
32 | apt-get -y install openssh-server |
---|
33 | apt-get -y install build-essential |
---|
34 | apt-get -y install python3 |
---|
35 | apt-get -y install ipython3 |
---|
36 | apt-get -y install python3-dev |
---|
37 | apt-get -y install postgresql |
---|
38 | apt-get -y install apache2 |
---|
39 | apt-get -y install libapache2-mod-wsgi |
---|
40 | apt-get -y install python3-psycopg2 |
---|
41 | apt-get -y install postfix |
---|
42 | apt-get -y install wget |
---|
43 | apt-get -y install python3-matplotlib |
---|
44 | apt-get -y install python3-reportlab |
---|
45 | apt-get -y install mercurial |
---|
46 | /etc/init.d/postgresql restart |
---|
47 | |
---|
48 | # optional, uncomment for emacs |
---|
49 | # apt-get -y install emacs |
---|
50 | |
---|
51 | # optional, uncomment for backups using samba |
---|
52 | # apt-get -y install samba |
---|
53 | # apt-get -y install smbfs |
---|
54 | |
---|
55 | echo "downloading, installing and starting web2py" |
---|
56 | echo "===========================================" |
---|
57 | cd /home |
---|
58 | mkdir www-data |
---|
59 | cd www-data |
---|
60 | rm web2py_src.zip* |
---|
61 | wget http://web2py.com/examples/static/web2py_src.zip |
---|
62 | unzip web2py_src.zip |
---|
63 | mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py |
---|
64 | chown -R www-data:www-data web2py |
---|
65 | |
---|
66 | echo "setting up apache modules" |
---|
67 | echo "=========================" |
---|
68 | a2enmod ssl |
---|
69 | a2enmod proxy |
---|
70 | a2enmod proxy_http |
---|
71 | a2enmod headers |
---|
72 | a2enmod expires |
---|
73 | a2enmod wsgi |
---|
74 | a2enmod rewrite # for 14.04 |
---|
75 | mkdir /etc/apache2/ssl |
---|
76 | |
---|
77 | echo "creating a self signed certificate" |
---|
78 | echo "==================================" |
---|
79 | openssl genrsa 1024 > /etc/apache2/ssl/self_signed.key |
---|
80 | chmod 400 /etc/apache2/ssl/self_signed.key |
---|
81 | openssl req -new -x509 -nodes -sha1 -days 365 -key /etc/apache2/ssl/self_signed.key > /etc/apache2/ssl/self_signed.cert |
---|
82 | openssl x509 -noout -fingerprint -text < /etc/apache2/ssl/self_signed.cert > /etc/apache2/ssl/self_signed.info |
---|
83 | |
---|
84 | echo "rewriting your apache config file to use mod_wsgi" |
---|
85 | echo "=================================================" |
---|
86 | echo ' |
---|
87 | WSGIDaemonProcess web2py user=www-data group=www-data |
---|
88 | |
---|
89 | <VirtualHost *:80> |
---|
90 | |
---|
91 | WSGIProcessGroup web2py |
---|
92 | WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py |
---|
93 | WSGIPassAuthorization On |
---|
94 | |
---|
95 | <Directory /home/www-data/web2py> |
---|
96 | AllowOverride None |
---|
97 | Require all denied |
---|
98 | <Files wsgihandler.py> |
---|
99 | Require all granted |
---|
100 | </Files> |
---|
101 | </Directory> |
---|
102 | |
---|
103 | AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \ |
---|
104 | /home/www-data/web2py/applications/$1/static/$2 |
---|
105 | |
---|
106 | <Directory /home/www-data/web2py/applications/*/static/> |
---|
107 | Options -Indexes |
---|
108 | ExpiresActive On |
---|
109 | ExpiresDefault "access plus 1 hour" |
---|
110 | Require all granted |
---|
111 | </Directory> |
---|
112 | |
---|
113 | CustomLog /var/log/apache2/access.log common |
---|
114 | ErrorLog /var/log/apache2/error.log |
---|
115 | </VirtualHost> |
---|
116 | |
---|
117 | <VirtualHost *:443> |
---|
118 | SSLEngine on |
---|
119 | SSLCertificateFile /etc/apache2/ssl/self_signed.cert |
---|
120 | SSLCertificateKeyFile /etc/apache2/ssl/self_signed.key |
---|
121 | |
---|
122 | WSGIProcessGroup web2py |
---|
123 | WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py |
---|
124 | WSGIPassAuthorization On |
---|
125 | |
---|
126 | <Directory /home/www-data/web2py> |
---|
127 | AllowOverride None |
---|
128 | Require all denied |
---|
129 | <Files wsgihandler.py> |
---|
130 | Require all granted |
---|
131 | </Files> |
---|
132 | </Directory> |
---|
133 | |
---|
134 | AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \ |
---|
135 | /home/www-data/web2py/applications/$1/static/$2 |
---|
136 | |
---|
137 | <Directory /home/www-data/web2py/applications/*/static/> |
---|
138 | Options -Indexes |
---|
139 | ExpiresActive On |
---|
140 | ExpiresDefault "access plus 1 hour" |
---|
141 | Require all granted |
---|
142 | </Directory> |
---|
143 | |
---|
144 | CustomLog /var/log/apache2/ssl-access.log common |
---|
145 | ErrorLog /var/log/apache2/error.log |
---|
146 | </VirtualHost> |
---|
147 | ' > /etc/apache2/sites-available/default.conf # FOR 14.04 |
---|
148 | |
---|
149 | sudo rm /etc/apache2/sites-enabled/* # FOR 14.04 |
---|
150 | sudo a2ensite default # FOR 14.04 |
---|
151 | |
---|
152 | # echo "setting up PAM" |
---|
153 | # echo "================" |
---|
154 | # sudo apt-get install pwauth |
---|
155 | # sudo ln -s /etc/apache2/mods-available/authnz_external.load /etc/apache2/mods-enabled |
---|
156 | # ln -s /etc/pam.d/apache2 /etc/pam.d/httpd |
---|
157 | # usermod -a -G shadow www-data |
---|
158 | |
---|
159 | echo "restarting apache" |
---|
160 | echo "================" |
---|
161 | |
---|
162 | /etc/init.d/apache2 restart |
---|
163 | cd /home/www-data/web2py |
---|
164 | sudo -u www-data python -c "from gluon.widget import console; console();" |
---|
165 | sudo -u www-data python -c "from gluon.main import save_password; save_password(raw_input('admin password: '),443)" |
---|
166 | echo "done!" |
---|