2
votes

I have spent the last two days trying to deploying a Django project with mezzanine on Mac 10.9 running Server.app. I've learned a lot, but had no luck so far. I have read several posts on this topic:

https://apple.stackexchange.com/questions/151388/can-i-deploy-my-django-site-to-os-x-server Deploying Django on OS 10.9 Server

But the aproaches didn't work for me.

I went through the docs on djangoproject over and over, but I can't find a solution. So please bear with me, I'm sure there is a solution.

I am trying to do this as simple as possible, even left out virtualenv for the sake of Apple's Server.app For sure I am missing something here...

This is my setup: Mac OS X 10.9 with Server App 3 Python 2.7.9 (installed via brew) django 1.6.10 Apache 2.2.26 mod_wsgi 4.4.8 (express version via pip)

The Project code itself resides in /Users/_dev/MyProject/MyProject

The conf files: I renamed wsgi.py to MyProject.wsgi, that just listed the MyProject in the Server.app/Advanced settings, but nothing more. Worth to mention: Apples defaut "hello world python app" doesn't work either, well I never saw it, but thought its different from the deafult splash screen Apple provided.

httpd_wsgi2.conf in /Library/Server/Web/Config/apache2/

WSGIScriptAlias / /Users/_dev/MyProject/MyProject/MyProject.wsgi

<Directory /Users/_dev/MyProject/MyProject>
<Files MyProject.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>

com.apple.webapp.wsgi2.plist in /Library/Server/Web/Config/apache2/webapps/

/Users/_dev/MyProject/MyProject/MyProject.wsgi<?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.apple.webapp.wsgi2</string>
        <key>displayName</key>
        <string>Hot Club Setup at /</string>
        <key>launchKeys</key>
        <array/>
        <key>proxies</key>
        <dict/>
        <key>installationIndicatorFilePath</key>
        <string>/Users/_dev/MyProject/MyProject/MyProject.wsgi</string>
        <key>includeFiles</key>
        <array>
                <string>/Library/Server/Web/Config/apache2/httpd_wsgi2.conf</string>
        </array>
        <key>requiredModuleNames</key>
        <array>
                <string>wsgi_module</string>
        </array>
</dict>
</plist>

At least Django and Mezzanine run fine with Development Server python manage.py runserver

mod_wsgi seems to be activated in /private/etc/apache2/httpd.conf : LoadModule wsgi_module libexec/apache2/mod_wsgi.so And mod_wsgi-express start-server works fine, at least for the Malt whyskey splash.

But when I enter mod_wsgi-express start-server MyProject.wsgi all I get an Internal Server Error the log at /tmp/mod_wsgi-localhost:8000:507/error_log says:

ImportError: Could not import settings 'MyProject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named MyProject.settings

Than added

PYTHONPATH="/Users/_dev/MyProject/MyProject/:$PYTHONPATH"
export PYTHONPATH

to /User/_dev/.bash_profile

And echo $PYTHONPATH says

/Users/_dev/MyProject/MyProject/:

What am I doing wrong? Any help is very welcome.

cheers Jörg

1

1 Answers

2
votes

just a quick note... with great help of a friend I managed to get it done. This is my the setup:

/Library/Server/Web/Config/apache2/httpd_wsgi2.conf

Alias /robots.txt /Users/_dev/hotclub/hotclub/static/robots.txt
Alias /favicon.ico /Users/_dev/hotclub/hotclub/static/img/favicon.ico

Alias /media/ /Users/_dev/hotclub/hotclub/static/media/
Alias /static/ /Users/_dev/hotclub/hotclub/static/

<Directory /Users/_dev/hotclub/hotclub/static>
Order allow,deny
Allow from all
</Directory>

<Directory /Users/_dev/hotclub/hotclub/static/media>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias / /Users/_dev/hotclub/hotclub/hotclub.wsgi

<Directory /Users/_dev/hotclub/hotclub>
Order allow,deny
Allow from all
</Directory>

/Library/Server/Web/Config/apache2/webapps/com.apple.webapp.wsgi2.plist

<?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.apple.webapp.wsgi2</string>
        <key>displayName</key>
        <string>Hot Club Setup at /</string>
        <key>launchKeys</key>
        <array/>
        <key>proxies</key>
        <dict/>
        <key>installationIndicatorFilePath</key>
        <string>/Users/_dev/hotclub/hotclub/hotclub.wsgi</string>
        <key>includeFiles</key>
        <array>
                <string>/Library/Server/Web/Config/apache2/httpd_wsgi2.conf</string>
        </array>
        <key>requiredModuleNames</key>
        <array>
                <string>wsgi_module</string>
        </array>
</dict>
</plist>

/Users/_dev/MyProject/MyProject/MyProject.wsgi

from future import unicode_literals

import os
import sys

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
#PROJECT_ROOT = "/Users/_dev/hotclub/hotclub"
settings_module = "%s.settings" % PROJECT_ROOT.split(os.sep)[-1]
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)

sys.path.append('/Users/_dev/hotclub')
sys.path.append('/Users/_dev/hotclub/hotclub')

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

cheers, Jörg