Parempaa bisnestä verkossa.

Installing Python with mod_wsgi on OS X Snow Leopard's default Apache

23.5.2011 — 

Most of the instructions here can be found elsewhere on the Internet, but I couldn’t find a comprehensive step-by-step guide that covered everything needed. So, here goes; this should cover everything you need to do to get going with Python, when starting with a stock OS X Snow Leopard Apache:

  • Download mod_wsgi from http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2, and save it to your Desktop.
  • Untar the archive, and install mod_wsgi:
    # cd ~/Desktop
    # tar xvfz mod_wsgi-3.3.tar.gz
    # cd mod_wsgi-3.3
    # ./configure
    # make
    # sudo make install
  • Then, edit your Apache main configuration file:
    # cd /etc/apache2
    # sudo nano httpd.conf

    Add the following line after the other LoadModule lines:

    LoadModule wsgi_module libexec/apache2/mod_wsgi.so
  • Go back to the directory where you untarred the mod_wsgi source:
    # cd ~/Desktop/mod_wsgi-3.3
    # make clean
  • Create new directories outside your webroot for storing the script files, and to be used as a separate webroot for python apps:
    # cd ~
    # mkdir wsgi_source
    # mkdir wsgi_web
  • Save a test script in the new wsgi_source directory as test.wsgi:
    def application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'
        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)
        return [output]
  • Create a new virtual host for your Python applications. Add this to your /etc/apache2/users/YOURUSERNAME.conf :
    <VirtualHost *:80>
        ServerName localpython
    DocumentRoot /Users/YOURUSERNAME/wsgi_web
    <Directory /Users/YOURUSERNAME/wsgi_web> Order allow,deny Allow from all </Directory>
    WSGIScriptAlias /myapp /Users/YOURUSERNAME/wsgi_source/test.wsgi
    <Directory /Users/YOURUSERNAME/wsgi_source> Order allow,deny Allow from all </Directory> </VirtualHost>
  • Add this to your /etc/hosts:
    127.0.0.1 localpython
  • Restart Apache:
    # sudo apachectl restart
  • Go to http://localpython/myapp , and you should see your “hello world”. If you don’t, something has gone wrong. The easiest way to start debugging is to check your Apache error logs at /var/log/apache2/error_log

More instructions can be found on the mod_wsgi site.

Kirjoita kommentti

 

Esikatselu

1.  18.5.2012 kello 18.12