Community site: login faq

I'm trying to setup a very simple http://bottlepy.org application with no dependencies. What is the recommended way to deploy this application such that it runs from the root of the site and all site urls are handled by the application?

I've created a mod_wsgi application, but that appears map everything to python scripts by name such as index.py, rather than starting a persistent application. BottlePy does have a cherrypy adapter, might that be a better solution, and if so how to go about setting that up?


asked 10 Jun '11, 01:37

accept rate: 0%

You actually have quite a few different options here.

Firstly, Bottlepy includes its own development server. That means you could run it without a front-end server at all. This is a great way to test the waters and ensure that the application is handling requests and URLs the way you expect it to. You can set this up through a "Custom Application (listening on port)". In a nutshell, that works like this:

  1. Create a new Custom Application (listening on port) from the Control Panel
  2. The application assigns you a port number to use.
  3. Configure your application to bind to localhost on the port specified in Step 2
  4. Set up a website record to point a domain at the application created in Step 1

That's basically it. This will route incoming requests on your domain to your Bottlepy application.

Now, more robust than the internal development server is something like mod_wsgi. This is a good configuration for a live, production site. The "mod_wsgi" application you installed from the Control Panel installs a local Apache server into your home directory under the ~/webapps/app_name directory. You would follow the Bottlepy instructions (or standard WSGI config) to get the WSGI application to run your Bottlepy application. This is usually done in a .wsgi file.

Lastly, you can use the Cherrypy adapter if you prefer. This would also run under the Custom Application (listening on port). Cherrypy has its own webserver and can be configured to bind to localhost:port exactly as you would have done for the Bottlepy development server. The only difference is that CherryPy is completely at-home and capable in a production environment.

If you have any trouble with any of these configurations, just reply in a Comment to this response and we'll try to point you in the right direction. Hope that helps!

permanent link

answered 10 Jun '11, 01:47

ryans ♦♦
accept rate: 43%

Question on the last option mentioned above. Are you suggesting that it is possible to use Cherrypy as the backend for Bottle? Or are you saying that at some point someone should move to Cherrypy?

It seems that you are saying that CHerrypy adapter can be used for Bottle. Could you elaboate?

(30 Aug '11, 11:12) mumin

Yes, you can use the CherryPy server as the backend for Bottle. This is a fully-stable server that speaks HTTP and can be used directly behind the front-end Nginx server under a Custom Application (listening on port). The Cherrypy integration is already built into Bottle. First, install cherrypy if you haven't already:

easy_install-2.7 cherrypy

Then run your Bottle app with something like this in your app code:

run(host='localhost', port=36086, server='cherrypy')

where "36086" is the port assigned to you by the Control Panel for your Custom Application (listening on port) that you are using for this application.

(30 Aug '11, 21:25) ryans ♦♦

hi, ryans

I've install cherrypy via easy_install and setup a custom app . then add run(host='localhost', port=36086, server='cherrypy') to my app..

There is a 502 bad gate way error . When I run this app via ssh : python2.7 XXXX.py

the webapp works fine .. Could you pls kindly help ?

Isn't there should be some configuration at Cherrypy ? other than wsgi_mod ,there is apache folder under webapp_name folder that I can confiugre to tell apache to run my py app. but how cherrypy know there is an app need to run ?

(24 Sep '11, 08:52) MOY

I have a project where I wish to use Apachi_WSGI. I checked the Bottle documentation and the configuration seems to bear no resemblence to the files available to me from the WSGI set up by WebFaction. Does anybody have a step-by-step guide to setting up Bottle?

Closest I could find was a three year old Web2Py guide which still gives me Internal Server Errors.

(11 Jan '12, 09:41) zilog8bit


First, create a mod_wsgi/Python2.7 app in the control panel and make a note of the app name and port assignment. For example, we'll call the app "yourapp" and assume that it was assigned port 54321.

Next, SSH into your server and run the following commands:

cd ~/webapps/yourapp
mkdir -p bin lib/python2.7
PYTHONPATH=$PWD/lib/python2.7 easy_install-2.7 -s $PWD/bin -d $PWD/lib/python2.7 bottle

Next, create your WSGI script. This is a Bottle app that uses the default_app method instead of the run method. For example, my script will be named app.wsgi and is a simple app that serves "Hello World!" on /hello:

import sys

from bottle import route, default_app

def hello():
    return "Hello World!"

application = default_app()

Next, edit your httpd.conf to configure Apache to serve the app via WSGI:

ServerRoot "/home/your_username/webapps/yourapp/apache2"

LoadModule dir_module        modules/mod_dir.so
LoadModule env_module        modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module       modules/mod_mime.so
LoadModule rewrite_module    modules/mod_rewrite.so
LoadModule setenvif_module   modules/mod_setenvif.so
LoadModule wsgi_module       modules/mod_wsgi.so

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/your_username/logs/user/access_yourapp.log combined
DirectoryIndex index.py
DocumentRoot /home/your_username/webapps/yourapp/htdocs
ErrorLog /home/your_username/logs/user/error_yourapp.log
KeepAlive Off
Listen 54321
NameVirtualHost *:54321
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 5
WSGIRestrictEmbedded On
WSGILazyInitialization On

<VirtualHost *:54321>
    ServerName your_username.webfactional.com

    WSGIDaemonProcess yourapp user=your_username group=your_username processes=1 threads=5 python-path=/home/your_username/webapps/yourapp/lib/python2.7
    WSGIProcessGroup yourapp
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptAlias / /home/your_username/webapps/yourapp/app.wsgi


Note that you'll need to make the following changes:

  • change '54321' to your actual assigned port number
  • change 'your_username' to your actual username
  • change 'yourapp' to your actual app name
  • change the domain used for ServerName to whatever domain you'll be using for your site

Once you've done all of that, restart your Apache and you should be good to go.

(11 Jan '12, 20:12) seanf

@seanf, thank you ever so much. This actually helps with understanding the deployment of other frameworks not just Bottle.

(11 Jan '12, 23:37) zilog8bit
showing 5 of 6 show 1 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 10 Jun '11, 01:37

question was seen: 17,967 times

last updated: 11 Jan '12, 23:39