Note: I guess the bottle framework is not relevant here. Wsgi is.
I've managed to configure my apache to work with wsgi and one-file web application based on python bottle framework. Below files are what I've got right now - apache uses virtualenv and runs a single wsgi/py file containing everything.
virtual host:
<VirtualHost *:80>
ServerName bottle-test
WSGIDaemonProcess bottle-test user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /home/tducin/Development/Python/bottle-test/src/app.wsgi
<Directory /home/tducin/Development/Python/bottle-test/src>
WSGIProcessGroup bottle-test
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
ErrorLog /var/log/apache2/wsgi/error-bottle.log
CustomLog /var/log/apache2/wsgi/access-bottle.log combined
</VirtualHost>
httpd.conf (this is where my virtualenv resides):
WSGIPythonHome /home/tducin/Development/Python/bottle-test
And finally, this is app.wsgi:
import os
# Change working directory so relative paths (and template lookup) work again
os.chdir(os.path.dirname(__file__))
import bottle
app = bottle.Bottle()
@app.route('/')
def siema():
return bottle.template('<h1>SIEMA {{arg}}!</h1>', arg='Janie')
@app.route('/hello/<name>')
def hello(name):
return bottle.template('<b>Hello {{name}}</b>!', name=name)
application = app
What I want to do is to separate the wsgi layer from the rest of the application. I've tried few times to import the application from another file, but I was getting Failed to import module error each time. Does anyone know how to separate wsgi from application?
edit: I moved httpd.conf to wsgi.conf (it is loaded) and now I've got the following:
WSGIPythonHome /home/tducin/Development/Python/bottle-test
WSGIPythonPath /home/tducin/Development/Python/bottle-test/src
The problem is that now I've got error 500, apache error logs are:
[Wed Feb 05 09:24:32 2014] [error] [client 127.0.0.1] mod_wsgi (pid=4260): Target WSGI script '/home/tducin/Development/Python/bottle-test/src/app.wsgi' cannot be loaded as Python module.
[Wed Feb 05 09:24:32 2014] [error] [client 127.0.0.1] mod_wsgi (pid=4260): Exception occurred processing WSGI script '/home/tducin/Development/Python/bottle-test/src/app.wsgi'.
[Wed Feb 05 09:24:32 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Feb 05 09:24:32 2014] [error] [client 127.0.0.1] File "/home/tducin/Development/Python/bottle-test/src/app.wsgi", line 7, in <module>
[Wed Feb 05 09:24:32 2014] [error] [client 127.0.0.1] import server
[Wed Feb 05 09:24:32 2014] [error] [client 127.0.0.1] ImportError: No module named server
src/server.py contains bottle application stuff. The app.wsgi file has got full executable permissions:
-rwxrwxr-x 1 tducin tducin 377 Feb 5 09:22 app.wsgi
