How can I deploy a Django application on OS X Server 2.0 without using homebrew or another python flavor than the one that comes with OS X 10.8.1? I use cocoa bindings in a Django application and cannot get it to work with homebrew on my desktop computer (works with OS X 10.8.1); therefore, a request to deploy the application on the installed Python version system.
I have the following OS X Server environment with the following already installed:
- OS X 10.8.1
- OS X Server 2.0
- Python 2.7.2
- Apache 2.2.22
Django 1.4.1 was installed using the following command:
sudo easy_install django
My first attempt is to deploy an empty website, and once that succeeds, deploy the real application that will be used in production. The project was created in /Library/Server/Web/Data/WebApps/mysite/ using the following command
django-admin.py startproject mysite
I launched the application using the following command. He simply confirmed that the application was running. This is the standard "It worked!" when you first created the project.
python manage.py runserver 8080
Then I created the file /Library/Server/Web/Config/apache2/httpd_mysite.conf with the following contents:
WSGIScriptAlias /mysite /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py
I also created the file /Library/Server/Web/Config/apache2/webapps/com.example.mysite.wsgi.plist with the following contents:
<?xml version="1.0" encoding="UTF-7"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>name</key> <string>com.example.mysite.wsgi</string> <key>displayName</key> <string>Python "My Site" app</string> <key>launchKeys</key> <array/> <key>proxies</key> <dict/> <key>installationIndicatorFilePath</key> <string>/Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py</string> <key>includeFiles</key> <array> <string>/Library/Server/Web/Config/apache2/httpd_mysite.conf</string> </array> <key>requiredModuleNames</key> <array> <string>wsgi_module</string> </array> </dict> </plist>
The com.example.mysite.wsgi.plist file was adapted from com.apple.webapp.wsgi.plist and httpd_mysite.conf adapted from httpd_wsgi.conf . Both of these files are used to successfully launch a "stand-alone" python application when configured using the server manager.
Then I created a site with a server manager, confirmed that my application was on the list of web applications. However, when I am http://example.com/mysite , I get a 500 error. The logs have the following entries (IP addresses changed to 1.2.3.4):
[Sat Sep 01 21:49:17 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366) [Sat Sep 01 21:49:17 2012] [notice] Apache/2.2.22 (Unix) PHP/5.3.13 with Suhosin-Patch mod_wsgi/3.3 Python/2.7.2 mod_fastcgi/2.4.6 mod_ssl/2.2.22 OpenSSL/0.9.8r DAV/2 configured
It does not look like the WSGI module is processing the request, but instead the request can be processed using FCGI. However, the log shows that mod_wsgi/3.3 was loaded.
When I created a standard Python application that looks like this:
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]
And update the files to point to /Library/Server/Web/Data/WebApps/helloworld.wsgi , not to /Library/Server/Web/Data/WebApps/mysite/mysite/wsgi.py , after which it will display "Hello World " Therefore, I assume that wsgi is correctly configured and able to run applications, and that something else is wrong with my setup.