Book Image

web2py Application Development Cookbook

By : Mariano Reingart, Bruno Cezar Rocha, Jonathan Lundell, Pablo Martin Mulone, Michele Comitini, Richard Gordon, Massimo Di Pierro
Book Image

web2py Application Development Cookbook

By: Mariano Reingart, Bruno Cezar Rocha, Jonathan Lundell, Pablo Martin Mulone, Michele Comitini, Richard Gordon, Massimo Di Pierro

Overview of this book

<p><undefined:p>web2py is a free open source full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applications. It is written and programmable in Python, and straightforward to run. web2py implements Model-View-Controller design, server-side form validation, and postbacks that make the code more readable, scalable, and maintainable. Are you familiar with web2py, and interested in gaining more advanced knowledge?<undefined:br><undefined:br><undefined:i>web2py Application Development Cookbook</undefined:i> gives you the necessary knowledge to make you a web2py expert. Right from teaching you about the database abstraction layer to adding AJAX effects to recipes about recipe, the book will make you a master of web2py through advanced practical recipes without any drudgery or straining the brain.<undefined:br><undefined:br><undefined:i>web2py Application Development Cookbook</undefined:i> is the tool you will need to expand and enhance your web2py skills.<undefined:br><undefined:br>This book begins with teaching you running web2py in various different systems followed by building simple applications. It focuses on database abstraction layer next and then explains building advanced forms. Adding stunning AJAX effects, using third party libraries and recipes on web services follow. Advanced recipes on authentication and authorization are taught and then routing and reporting recipes claim your attention. There is a final wrap-up with useful, interesting tips and tricks which you will really enjoy.<undefined:br><undefined:br>In short, this book will make you an expert in web2py in a trouble-free, quick, and easy manner.</undefined:br></undefined:br></undefined:br></undefined:br></undefined:br></undefined:br></undefined:br></undefined:br></undefined:p></p>
Table of Contents (18 chapters)
web2py Application Development Cookbook
Credits
About the Authors and Reviewers
About the Reviewer
www.PacktPub.com
Preface
Index

Running web2py with Cherokee


This recipe explains how to run web2py behind a Cherokee web server using uWSGI.

Cherokee is a webserver written in C, similar in intent to Lighttpd: fast, compact, and modular. Cherokee comes with an administrative interface that allows one to manage its configuration, which is difficult to read and modify otherwise. uWSGI is described in its website as a fast (pure C), self-healing, developer/sysadmin-friendly application container server. Cherokee has an included module to talk to uWSGI servers.

How to do it...

  1. Install the package or download, compile, and install the required components. Create the following file in the installation root of web2py, and call it uwsgi.xml:

    <uwsgi> 
      <pythonpath>/home/web2py</pythonpath> 
      <module>wsgihandler</module> 
      <socket>127.0.0.1:37719</socket>
      <master/>
      <processes>8</processes>
      <memory-report/>
    </uwsgi> 
    

    This configuration spawns eight processes to manage multiple requests from the HTTP server. Change it as needed, and configure <pythonpath> to the installation root of web2py.

  2. As the user that owns the web2py installation, start the uWSGI server:

    $ uWSGI -d uwsgi.xml
    
  3. Now launch the Cherokee administrative interface to create a new configuration:

    $ cherokee-admin
    
  4. Connect to the admin interface with the browser at the following link: http://localhost:9090/.

  5. Go to the Sources section - (A), then click on the + button - (B).

  6. Select Remote Host on (C), then fill the text field at (D) with the IP address, and port to match the configuration in the previous uswgi.xml file.

    Having configured the uWGI source, it is now possible to configure a Virtual Host, and redirect requests through it. In this recipe, we choose the default Virtual Host that is used when no other Virtual Host has a better match for the incoming request.

  7. Click on button (C) to go to Rule Management.

  8. Delete all rules listed on the left. Only the default rule will remain.

  9. Configure the default rule with a uWSGI Handler. Leave the other values unchanged.

  10. If you want Cherokee to serve static files directly from web2py folders, you can add a Regular Expression rule. Click button (A), and select Regular Expression from the drop-down menu at (B). Be aware that this configuration works only if the web2py directory is on the same file system, and is accessible to Cherokee.

  11. Configure the Regular Expressions:

  12. Now you can configure the Static Handler pointing to the applications subdirectory of your web2py installation:

    Remember to save the configuration, and reload or restart Cherokee from the administrative interface; then you are ready to start the uWSGI server.

  13. Change to the correct user ID that was used to install web2py; be aware that using root is not recommended.

  14. Go into the root directory of web2py installation, where you saved the configuration file uwsgi.xml.

  15. Run uWSGI with the -d <logfile> option, so that it runs in the background:

    $ su - <web2py user>
    $ cd <web2py root>
    $ uwsgi -x uwsgi.xml -d /tmp/uwsgi.log
    

Enjoy the speed!

Getting ready

You should have the following: