Deployment Recipes Part 2 – Python, Web2py, Apache and Debian

We continue here from where we left off, In case you did not read the first part, feel free to visit this link [Deployment Recipes Part 1 – Python, Web2py, Apache and Debian – LearnXYZ] and have a look at it. So lets jumpin.

Today we look at installing all the necessary packages on debian that you need for your python project to run successfully. Note there are paths and other things like passwords etc that you might need to specify for you vps installation. It is assumed that you will take care of these things at your end. It is advisable that you change the path and other things while executing the below commands.

Again, it is a good practice to always have a backup of your system and things you want to get rid of so make the changes in your production system with caution.

Install Apache

Install Apache 2 , install apache2-dev

apt-get install apache2

apt-get install apache2-dev

Debian and ubuntu use apache2.conf instead of http.d file

Commands

/etc/init.d/apache2 start

/etc/init.d/apache2 stop

/etc/init.d/apache2 restart

Other commands for apache

systemctl start apache2.service

systemctl stop apache2.service

systemctl restart apache2.service

Install postgres sql 9.3.2

apt-get install postgresql  OR

follow below steps (Check dependency section in reference if you have trouble)

7. postgres changing password (I did it after logging in as root)

sudo -u postgres psql postgres

\password postgres

Enter password twice and you are all set : Example  abcde12345

Install mod wsgi

apt-get install libapache2-mod-wsgi

8. Added the line in wsgi.conf like below LoadModule line – 

WSGIScriptAlias / /home/www-data/web2py/wsghandler.py

OR

Routes

routes.py must only reside in the web2py\ directory.

(fix imports if errors come like import gluon.fileutils or

import gluon.languages)

routers = dict(

          #base router

          BASE=dict(

                   default_application=’Target’,

                   domains= {‘www.targetsoft.co.in‘:’Target’}

),

)

Example:

One stop setup

1] Run – setup-web2py-debian-sid.sh

This is found in web2py\scripts folder

This script will:

1) Install latest version of web2py (in /home/rahul/www-data/web2py). Copy your applications in the applications sub folder in web2py.
2) Install all modules need to run web2py on Ubuntu/Debian including Apache and its modules
3) Install web2py in /home/www-data/
4) Creates a self signed ssl certificate
5) Setup web2py with mod_wsgi
6) Overwrite /etc/apache2/sites-available/default
7) Restarts apache.

Dhakate Rahul

Dhakate Rahul

Leave a Reply

Your email address will not be published. Required fields are marked *