On 24/01/2008, Lukasz Szybalski <[EMAIL PROTECTED]> wrote: > Hello, > I run into small probablems in my configuration/placement. > > - I have compiled and enabled mod_wsgi 1.8 with apache2 on debian. > http://lucasmanual.com/mywiki/TurboGears#head-36b7eef1526da4fe58c73738c925f34f6bc93c1d
Did you also check: http://code.google.com/p/modwsgi/wiki/IntegrationWithTurboGears > I have a basic turbogears app that turbogears created using > quickstart. I am trying to run it in mod_wsgi. > > I have installed my app using egg deploy. > > easy_install myfirstapp-1.0-py2.4.egg > > It put my turbogears app in > /usr/lib/python2.4/site-packages/myfirstapp-1.0-py2.4.egg/myfirstapp Manually, or did you properly install it using appropriate Python tools? > I put my myfirstapp.wsgi in /etc/myfirstapp That is a really bad place to put it, as it means you would have had to allow Apache to serve up files in /etc. With a bit more Apache misconfiguration and you could accidentally expose import system files from your machine. You are better off putting stuff under /usr/local or even in a subdirectory of your personal account. > /etc/myfirstapp# ls -l > total 8 > -rw-r--r-- 1 root root 1157 2008-01-23 16:20 myfirstapp.wsgi > -rw-r--r-- 1 root root 2045 2008-01-22 00:22 prod.cfg > > myfirstapp.wsgi looks like this: > ----------------------------- > import sys > sys.path.append('/usr/lib/python2.4/site-packages/myfirstapp-1.0-py2.4.egg/myfirstapp') See comments below. > sys.stdout = sys.stderr > > import os > os.environ['PYTHON_EGG_CACHE'] = > '/usr/lib/python2.4/site-packages/myfirstapp-1.0-py2.4.egg/myfirstapp' See comments below. > import atexit > import cherrypy > import cherrypy._cpwsgi > import turbogears > > turbogears.update_config(configfile="/etc/myfirstapp/prod.cfg", > modulename="myfirstapp.config") > turbogears.config.update({'global': {'server.environment': 'production'}}) > turbogears.config.update({'global': {'autoreload.on': False}}) > turbogears.config.update({'global': {'server.log_to_screen': False}}) > > #For non root mounted wiki: > turbogears.config.update({'global': {'server.webpath': '/myfirstapp'}}) > > import myfirstapp.controllers > > cherrypy.root = myfirstapp.controllers.Root() > > if cherrypy.server.state == 0: > atexit.register(cherrypy.server.stop) > cherrypy.server.start(init_only=True, server_class=None) > > #For root mounted app > #application = cherrypy._cpwsgi.wsgiAppi > > #For none-root mounted app > def application(environ, start_response): > environ['SCRIPT_NAME'] = '' > return cherrypy._cpwsgi.wsgiApp(environ, start_response) > > > -------------- > My apache file in: > /etc/apache2/conf.d/myfirstapp looks like: > WSGIScriptAlias /myfirstapp /etc/myfirstapp/myfirstapp.wsgi Bad as noted above. > <Directory > /usr/lib/python2.4/site-packages/myfirstapp-1.0-py2.4.egg/myfirstapp> > Order deny,allow > Allow from all > </Directory> Not necessary. That you haven't got a Directory block for /etc indicates the default for your server maybe to allow access to everything, which is really bad as Apache insecure by default. > This is the error I am getting in my logs: > cat /var/log/apache2/error.log > -- resuming normal operations > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] mod_wsgi > (pid=4177): Target WSGI script '/etc/myfirstapp/myfirstapp.wsgi' > cannot be loaded as Python module. > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] mod_wsgi > (pid=4177): Exception occurred within WSGI script > '/etc/myfirstapp/myfirstapp.wsgi'. > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] Traceback (most > recent call last): > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] File > "/etc/myfirstapp/myfirstapp.wsgi", line 13, in ? > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] > turbogears.update_config(configfile="/etc/myfirstapp/prod.cfg", > modulename="myfirstapp.config") > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] File > "/var/lib/python-support/python2.4/turbogears/config.py", line 207, in > update_config > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] > configure_loggers(configdict) > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] File > "/var/lib/python-support/python2.4/turbogears/config.py", line 143, in > configure_loggers > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] > _get_handlers(handlers, formatters) > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] File > "/var/lib/python-support/python2.4/turbogears/config.py", line 50, in > _get_handlers > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] raise > ConfigError("Missing or wrong argument to " > [Wed Jan 23 16:23:02 2008] [error] [client 127.0.0.1] ConfigError: > Missing or wrong argument to FileHandler in handler access_out -> > [Errno 13] Permission denied: 'server.log' > > -What is wrong with this configuration? What in your configuration mentions 'server.log'? Because you are running in embedded mode, files and directories must be accessible to user that Apache runs as. In this case, because it is trying to write to the file, the directory actually needs to be writable to Apache user. See section 'Access Rights Of Apache User' of: http://code.google.com/p/modwsgi/wiki/ApplicationIssues You may want to consider using mod_wsgi daemon mode and running application as specific user. Also, make sure you also read section 'Application Working Directory' of the document above, as you need to also ensure you use absolute path names, not relative path names. > -Configuration mentions writable cache folder? Where is that at? Do I need it? Are you talking about Python egg cache? See section 'User HOME Environment Variable' of above document. I would not recommend using: os.environ['PYTHON_EGG_CACHE'] = '/usr/lib/python2.4/site-packages/myfirstapp-1.0-py2.4.egg/myfirstapp' as it pollutes your site-packages directory. Have it go somewhere else if required. > - Is /usr/lib/python2.4/site-packages/myfirstapp-1.0-py2.4.egg/myfirstapp > prefered folder to link in apache? Hmmm, if an egg version of application requires adding that subdirectory of egg to sys.path explicitly, that is a bit of a pain. If this is really required, may be better to use something like: import myfirstapp.myfirstapp sys.path.append(os.path.dirname(myfirstapp.myfirstapp.__file__)) Can some one on TG list explain the requirement here. Don't have access to a TG installation at the moment to check. > - Is there a different way I should deploy my app? (not with > easy_install or some parameter for easy_install?) You might investigate using virtual environments for a start so you are installing your application into your OS Python installation. See: http://code.google.com/p/modwsgi/wiki/VirtualEnvironments > - What should be the permissions on each of these files ,wsgi, prod.cfg, See discussion about file permissions in the thread: http://groups.google.com/group/modwsgi/browse_frm/thread/8b8f17d6b8bb8b59/f1eedcea6f43ea25?lnk=gst&q=rwx-----x#f1eedcea6f43ea25 Important things thus are, don't put stuff in /etc like you are. Fix your Apache configuration so it doesn't allow access to all files on your box by default. Then have a better read of documentation on mod_wsgi site. Graham --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

