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

Welcome to Deployment Recipes Part 11 – We look into some other aspect of deployment in today’s article. This article is specific to web2py my framework of choice.

Application Deployments

Arptic

  1. Create the application or prepare the application for all the deployment functions

For example:

  1. Once application is on VPS server – provide all appropriate permissions to required folders for example static and its sub folders where we allow to upload images or write files etc.
  2. Rename existing db see this document for details for postgres
  3. Create new db
  4. Edit controllers\default.py and make all numbers are set to 0 for index()
    1. Sellable Imges
    1. Non sellable images
    1. News
    1. Blogs
  5. First – executeSetup ()  — Let it execute as this takes some time. Once it is done and you are able to see the front page. Disable this function
  6. Second – Copy news  Enable install_news_linux() and once it executes and you are able to see front page without errors. Disable this function
  7. Third – Copy blogs Enable install_blogs_linux() and once it executes and you are able to see front page without errors. Disable this function
  8. Finally, Edit controllers\default.py and make all numbers are set as below for index()–
    1. Sellable Imges – 12
    1. Non sellable images -12
    1. News – 3
    1. Blogs – 3
  9. To display this site –  Just add it to routes.py (webserver restart is required)

routers = dict(

#base router

BASE=dict(

       #default_application=’Target’,

                    domains= {

www.targetsoft.co.in‘ : ‘Target’,

‘www.arptic.in’ : ‘arptic’,

 }

     ),

)

Production code for web2py folder for routes.py

routers = dict(

#base router

BASE=dict(

       #default_application=’Target’,

       domains= {

                ‘www.targetsoft.co.in’ : ‘Target’,

                          ‘targetsoft.co.in’ : ‘Target’,

                ‘www.arptic.in’ : ‘artptic’,

                          ‘arptic.in’ : ‘arptic’,

                          },

       #default_application = ‘Target’,

                applications=[‘Target’, ‘arptic’, ‘Aavia9’],

       default_fucntion = ‘index’,

),

        Target = dict(

             default_language = ‘en’,

        languages = [‘en’],

             default_function = ‘index’,

              ),

       artpic = dict(

             default_language = ‘en’,

             languages = [‘en’],

        default_function = ‘index’,

             map_hyphen = True,

              ),

)

  1.  Restart webserver and try pointing your browser to your site, it should work now.
  2. Once the entire setup is completed check your site and also your database to see if you can access everything and if all the data is in the system.
  3. Finally add smtp server and make sure it works
  4. Performance optimizations come for the app later
  5. Check usage statistics from time to time
  6. Check <applicationname>\errors\ folder from time to time for errors

Issue handling

  1. Gevent issues are complex – just comment out all the imports for gevent and the code

<class ‘gevent.exceptions.LoopExit’> This operation would block forever

  • upload issue – check if all the filed values are being saved in the database if not – makesure this is done
  • For email issues make sure the SMTP settings are specified properly

[Errno 111] Connection refused

  • import socket in db.py for fixing this issue

global name ‘socket’ is not defined

Dhakate Rahul

Dhakate Rahul

Leave a Reply

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