Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active December 21, 2015 01:48
Show Gist options
  • Save grenade/6230133 to your computer and use it in GitHub Desktop.
Save grenade/6230133 to your computer and use it in GitHub Desktop.
Make web2py run under Apache mod_wsgi on Fedora Core 18
# Dependencies
yum -y install openssh-server python python-devel tkinter sqlite-devel zlib-devel httpd httpd-devel mod_wsgi mod_proxy_html mod_ssl wget
# web2py
rm -rf /var/www/html/web2py
chmod 755 /var/www/html
git clone https://github.com/web2py/web2py.git /var/www/html/web2py
ln -s /var/www/html/web2py/handlers/wsgihandler.py /var/www/html/web2py/wsgihandler.py
chmod 755 /var/www/html/web2py
chown -R apache:apache /var/www/html/web2py
# SSL
mkdir -p /etc/httpd/ssl
openssl genrsa 1024 > /etc/httpd/ssl/self_signed.key
openssl req -new -x509 -nodes -sha1 -days 365 -key /etc/httpd/ssl/self_signed.key > /etc/httpd/ssl/self_signed.cert
openssl x509 -noout -fingerprint -text < /etc/httpd/ssl/self_signed.cert > /etc/httpd/ssl/self_signed.info
chmod 400 /etc/httpd/ssl/self_signed.*
# Apache / mod_wsgi
if [ -e /etc/httpd/conf.d/welcome.conf ]; then
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.disabled
fi
cat > /etc/httpd/conf.d/default.conf <<EOF
NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>
WSGIDaemonProcess web2py user=apache group=apache
WSGIProcessGroup web2py
WSGIScriptAlias / /var/www/html/web2py/handlers/wsgihandler.py
WSGIPassAuthorization On
<Directory /var/www/html/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>
AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) /var/www/html/web2py/applications/\$1/static/\$2
<Directory /var/www/html/web2py/applications/*/static>
Options -Indexes
Order Allow,Deny
Allow from all
</Directory>
Redirect permanent /admin https://hostname/admin
<Location /admin>
Deny from all
</Location>
<LocationMatch ^/([^/]+)/appadmin>
Deny from all
</LocationMatch>
CustomLog /var/log/httpd/access_log common
ErrorLog /var/log/httpd/error_log
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/self_signed.cert
SSLCertificateKeyFile /etc/httpd/ssl/self_signed.key
WSGIProcessGroup web2py
WSGIScriptAlias / /var/www/html/web2py/wsgihandler.py
WSGIPassAuthorization On
<Directory /var/www/html/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>
AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) /var/www/html/web2py/applications/\$1/static/\$2
<Directory /var/www/html/web2py/applications/*/static>
Options -Indexes
ExpiresActive On
ExpiresDefault "access plus 1 hour"
Order Allow,Deny
Allow from all
</Directory>
CustomLog /var/log/httpd/web2py_access_log common
ErrorLog /var/log/httpd/web2py_error_log
</VirtualHost>
EOF
echo "WSGISocketPrefix run/wsgi" >> /etc/httpd/conf.d/wsgi.conf
cd /var/www/html/web2py
sudo -u apache python -c "from gluon.main import save_password; save_password(raw_input('admin password: '),443)"
service httpd restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment