How I can run /myapp/my_app.py by default when accessing `localhost` using Bottle?
Question: **Desired Behaviour**

I want to serve content created by the file at:

    
    
    /myapp/my_app.py
    

when accessing `localhost`.

**Question**

I know that if I add the following to `test.py` and run the file directly, the
results will be accessible at `localhost:8080`:

    
    
    from bottle import route, run
    
    @route('/')
    def hello():
        return "Hello World!"
    
    run(host='localhost', port=8080, debug=True)
    

But how do I trigger this file to run by default when accessing `localhost`?

**Environment**

  * Linux Mint 17
  * MongoDB
  * RockMongo (Apache2, PHP, MongoDB Driver)

**What I've Tried**

I installed `mod_wsgi` and created `/var/www/html/myapp/app.wsgi` with this
content:

    
    
    import bottle
    import os
    
    os.chdir(os.path.dirname(__file__))
    
    @route('/')
    def hello():
        return "Hello World!"
    
    application = bottle.default_app()
    

And then restarted Apache.

But going to `localhost` just shows a file directory.

I then created `/etc/apache2/sites-enabled/mygreatapp.conf` with this content:

    
    
    <VirtualHost *>
        ServerName google.com
    
        WSGIScriptAlias / /var/www/html/myapp/app.wsgi
    
        <Directory /var/www/html/myapp>
        WSGIProcessGroup yourapp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
        </Directory>
    </VirtualHost>
    

But I still just see a file directory.

**Official Instructions**

<http://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi>

**Further Information**

**Troubleshooting**

_See if mod_wsgi is loaded_

    
    
    apache2ctl -M
    ...
    wsgi_module (shared)
    

**Definitions**

For my own reference, I'm trying to fully comprehend several elements that I
think are involved in the process, feel free to correct if my understandings
are wrong:

**WSGI** \- A convention for how applications should communicate with servers.

> It does not exist anywhere else other than as words in the [PEP
> 3333](http://www.python.org/dev/peps/pep-3333/) \-
> [Source](http://webpython.codepoint.net/wsgi_tutorial)

**mod_wsgi** \- An Apache module that allows Python files to communicate with
Apache.

**Web Framework** \- See a list of them here:
<https://wiki.python.org/moin/WebFrameworks>

**Web Server** \- <http://en.wikipedia.org/wiki/Web_server>

**Apache Server** \- <http://en.wikipedia.org/wiki/Apache_HTTP_Server>


Answer: I finally have "Hello World!" displaying in the browser at `localhost`.

I will paste the various required configs and files below.

I'm a newb so I don't know if this is definitive or best practise.

**/var/www/html/myapp/app.wsgi**

    
    
    # view the effect of import method:  
    http://stackoverflow.com/a/2452639/1063287
    
    import bottle 
    import os
    
    os.chdir(os.path.dirname(__file__))
    
    # note i am using bottle.route and not just route
    @bottle.route('/') 
    def hello():
        return "Hello World!"
    
    application = bottle.default_app()
    

**/etc/apache2/sites-available/000-default.conf** (note: this is the default
`.conf` file)

    
    
    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        WSGIScriptAlias / /var/www/html/myapp/app.wsgi # just added this
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

Viewing the Apache error log is what eventually led me to try a few different
things:

    
    
    sudo tail -100 /var/log/apache2/error.log
    

Where I saw things like:

    
    
    Exception occurred processing WSGI script '/var/www/html/myapp/app.wsgi'.
    Traceback (most recent call last):
    File "/var/www/html/myapp/app.wsgi", line 8, in <module>
    @route('/')
    NameError: name 'route' is not defined
    

This was only after I had made the step of not using a new `.conf` file and
just modifying the default one.

So for some reason it didn't like any new `.conf` files.

