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

This series will try to explore how you can deploy your python code written with web2py serving on Apache on a debian system. Debian is a fantastic and fast mother OS that is my personal favourite. The forks like Ubuntu are great but I instead prefer debian. It is stable, it is tough to break in, flexible and has tons and tons of packages. If you want to deploy your code for any other python web framework, I request you to follow the series. It has something for everyone. Python never ceases to amaze me, I am a fan of this language and have been working since the last 12 plus years on it. At the end of this series I would share a pdf more like a scratch book with all of you readers that has my notes.

Currently I am using python 3.9.x as my go to development environment. However when I deployed my three production projects on websites, I was using python 2.7.13. This guide is based on that. With that said, if you have all the packages for your python 3.x project this will certainly work for you.

Configuring python, web2py on vps server

  1. Install sudo if not already done –
    1. apt-get install sudo
  2. Install python if not already installed by default it has 2.7.13
    1. apt-get install python2
  3. sudo apt-get install python3 python3-pip  for python 3
  4. use apt-get upgrade <<packagename>> to upgrade anything
  5. Install pip using get pip script
    1. Then use pip to install python packages
    1. pip install <pagkagename>
    1. pip install reportlab
    1. pip install pygal
    1. pip install razorpay
    1. pip install exifread (for artpic)
    1. pip install pg8000 (for web2py dependency, found in artpic)

Debian packages required

Make sure your sources.list file is configured properly to let you install packages from the internet [/etc/apt/sources.list]

Below is an example of a sources.list for Debian 9/Stretch.

deb http://deb.debian.org/debian stretch main

deb-src http://deb.debian.org/debian stretch main

deb http://security.debian.org/debian-security/ stretch/updates main

deb-src http://security.debian.org/debian-security/ stretch/updates main

deb http://deb.debian.org/debian stretch-updates main

deb-src http://deb.debian.org/debian stretch-updates main

If you also want the contrib and non-free components, add contrib non-free after main:

deb http://deb.debian.org/debian stretch main contrib non-free

deb-src http://deb.debian.org/debian stretch main contrib non-free

deb http://security.debian.org/debian-security/ stretch/updates main contrib non-free

deb-src http://security.debian.org/debian-security/ stretch/updates main contrib non-free

deb http://deb.debian.org/debian stretch-updates main contrib non-free

deb-src http://deb.debian.org/debian stretch-updates main contrib non-free

For resolving errors use – If sudo is not available login using su , password

sudo apt-get clean

or,

sudo apt-get autoclean

sudo apt-get -u dist-upgrade

sudo apt-get -o Debug::pkgProblemResolver=yes dist-upgrade

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install package-name

Debian system update and upgrade

Issue below commands periodically to upgrade and update your debian server. This is necessary so that you receive all the critical security fixes  and package updates every month.

Run:

apt-get update

To update the apt package database

apt-get upgrade

and to install the latest updates (if there are any).

In case of errors use commands specified above on page5

https://askubuntu.com/questions/91543/apt-get-update-fails-to-fetch-files-temporary-failure-resolving-error

There are two parts to your question:

  • fixing temporary resolve messages
  • fixing the package management issues

Temporary resolve

It is likely that this issue is either:

  • temporary due to your Internet Service Provider not correctly forwarding internet naming (DNS) to either its or external DNS servers, or
  • due to a change in your network has similarly blocked this naming – for example, new router/modem, reconfiguring a switch with a new configuration.

Lets look at the possible DNS resolving issues.

First, temporarily add a known DNS server to your system.

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null

Then run sudo apt-get update.

If this fixes your temporary resolving messages then either wait for 24 hours to see if your ISP fixes the issue for you (or just contact your ISP) – or you can permanently add a DNS server to your system:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null

8.8.8.8 is Google’s own DNS server.

source

Another example DNS server you could use is OpenDNS – for example:

echo "nameserver 208.67.222.222" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null

To reboot or restart debian system

To shut down the system from a terminal session, sign in or “su” to the “root” account. Then type “/sbin/shutdown -r now”. It may take several moments for all processes to be terminated, and then Linux will shut down. The computer will reboot itself.

>> Init 6  [Enter] also works

To be continued in the next part

Dhakate Rahul

Dhakate Rahul

25 thoughts on “Deployment Recipes Part 1 – Python, Web2py, Apache and Debian

  1. I think this is among the most vital info for me. And i am glad reading your article.
    But should remark on some general things, The web site
    style is ideal, the articles is really great : D. Good job,
    cheers

  2. My spouse and I stumbled over here by a different website
    and thought I might as well check things out. I like what I see
    so now i’m following you. Look forward to exploring your web page again.

  3. Thank you a bunch for sharing this with all people you actually understand what you are speaking
    approximately! Bookmarked. Please also consult with my web site =).
    We can have a hyperlink exchange arrangement between us

Comments are closed.