Search This Blog

Thursday, February 24, 2011

Deploying web page in python using PYLONS.

This approach is simple and painless. (It differs from the one on pylonsbooks much)  It doesn’t use python environment (pyt-env) embedded in userspace etc. ROOT access is required to install pylons in this manner.
Ubuntu version: 10.10 Server
  1. Install apache server

    aptitude install apache2

  2. Check if it works:  127.0.0.1  should give you: “It works!”
  3. Install  Python WSGI adapter module for Apache

    aptitude install libapache2-mod-wsgi


  4. Disable the default apache site:

    a2dissite 000-default

    (or any other site in: /etc/apache2/sites-enabled)
  5. Install easy_install for python
    apt-get install python-setuptools python-dev build-essential

  6. Set the proxy if necessary:

    export HTTP_PROXY=http://user:pass@10.60.30.248:8080/

  7. easy_install paste
  8. aptitude install python-pastedeploy
  9. easy_install SQLAlchemy
  10. easy_install Pylons
  11. add www-data user to your user group

    usermod -a -G simplesite www-data

  12. set debug = false in your development.ini

    [DEFAULT]
    debug = false

  13. move you application to: /usr/lib/pymodules/python2.6
/etc/apache2/sites-available/OBIAD:

<VirtualHost *>
    ServerName etiopia
    ServerAlias etiopia

    # Logfiles
    ErrorLog  /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log combined

    # Setup mod_wsgi
    WSGIScriptAlias / /home/ubuntu/OBIAD/dispatch.wsgi

    <Directory /home/ubuntu/OBIAD>
    Order deny,allow
    Allow from all
    </Directory>

</VirtualHost>



  • a2ensite OBIAD


OBIAD is the site name. It can be any name instead of OBIAD.
/home/ubuntu/OBIAD/dispatch.wsgi:

#Load the Pylons application
from paste.deploy import loadapp
application = loadapp('config:/home/ubuntu/OBIAD/development.ini')


Place your application in the following directory, so that python can find it: /usr/lib/pymodules/python2.6
Restart apache with:

/etc/init.d/apache2 restart

Look for any errors in: /var/log/apache2/error.log
While starting apache I had the following error. Despite this everything worked fine (There was a bug and we can ignore this error):

[error] Exception KeyError: KeyError(140024401471296,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored
[error] Exception KeyError: KeyError(140024401471296,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored
[notice] caught SIGTERM, shutting down
[warn] mod_wsgi: Compiled for Python/2.6.5.
[warn] mod_wsgi: Runtime using Python/2.6.6.
[notice] Apache/2.2.16 (Ubuntu) mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations




Errors you may encounter:
ImportError: No module named paste.deploy –> install paste with “easy_install paste”
ImportError: No module named deploy –> aptitude install python-pastedeploy
OSError: File '/home/ubuntu/OBIAD/development.ini' not found –> copy your *.ini from you application to the destination directory
DistributionNotFound: dinner –> you haven’t copied your application to destination directory (/usr/lib/pymodules/python2.6/)
DistributionNotFound: SQLAlchemy>=0.5 –>  easy_install SQLAlchemy


Proxy causing errors. If you see any of the messages:

[error] [client 10.60.1.248] IOError: failed to write data
[error] [client 10.60.1.248] mod_wsgi (pid=7892): Exception occurred processing WSGI script '/home/ubuntu/OBIAD/dispatch.wsgi'.

it’s probably your proxy causing problems. Mod_wsgi does not do well with proxies unfortunately.

1 comment:

  1. Hello,
    I have the error DistributionNotFound:SyncServer but I can't understand what is the application...
    I can't find any application called SynServer
    (I am trying to install my own Firefox Sync server (http://docs.services.mozilla.com/howtos/run-sync.html)

    Thanks

    ReplyDelete

If you like this post, please leave a comment :)