- Hombrew
- Python 2.7.5
- Django 1.5.2
- Apache 2.2.25
- Postgres 9.2.4
- R 3.0.1
- Virtualenv
Showing posts with label mod_wsgi. Show all posts
Showing posts with label mod_wsgi. Show all posts
Monday, September 16, 2013
Creating a Mountain Lion development environment
So I had to set up a new dev environment at work on Mountain Lion. It uses the following components
Labels:
Apache,
Django,
Homebrew,
MacOS,
mod_wsgi,
Mountain Lion,
postgres,
python,
R,
RPy2,
Virtualenv
Tuesday, August 20, 2013
How to install mod_wsgi on Mountain Lion
There are apparently changes Apple made in XCode between Lion and Mountain Lion that cause the standard install method to fail. The conventional fix that comes up most often in a Google search at the time of this writing is to create a symlink between the new name of a Toolchain folder and the old name that the installer is supposedly looking for, like this
sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/ /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain
I did this and tried to make mod_wsgi using Homebrew but it throws a cryptic apxs error. Long story short, I eventually compiled mod_wsgi from source myself, but it continued to through various errors, even though things seemed to be configured properly. I went back to a different Mountain Lion machine I had configured earlier using MacPorts. When I did that machine, I had no problems with mod_wsgi or the need for this toolchain symlink. Examining the Portfile for mod_wsgi gives the key. The missing element is adding the --disable-framework flag to the config file. After that, everything works fine.
This flag should be added to the Homebrew Formula for mod_wsgi. I have never made a Formula before, but maybe one day I will do it. Below is the Gist showing what I did and how it worked.
sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/ /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain
I did this and tried to make mod_wsgi using Homebrew but it throws a cryptic apxs error. Long story short, I eventually compiled mod_wsgi from source myself, but it continued to through various errors, even though things seemed to be configured properly. I went back to a different Mountain Lion machine I had configured earlier using MacPorts. When I did that machine, I had no problems with mod_wsgi or the need for this toolchain symlink. Examining the Portfile for mod_wsgi gives the key. The missing element is adding the --disable-framework flag to the config file. After that, everything works fine.
This flag should be added to the Homebrew Formula for mod_wsgi. I have never made a Formula before, but maybe one day I will do it. Below is the Gist showing what I did and how it worked.
Thursday, September 29, 2011
Django, Apache 2 and mod_wsgi
A pain in the neck to set up, but nice to have.
1. Follow installation instructions for mod_wsgi and django
2. Add to httpd.conf
# ----------- Django / WSGI Configuration ----------
WSGIDaemonProcess processes=2 threads=15
WSGIScriptAlias /mgrm "/home/django/var/www/mgrm/apache/django.wsgi"
<Directory "/home/django/var/www/mgrm/">
Order allow,deny
Allow from all
</Directory>
Alias "/static/admin" "/opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/"
<Directory "/opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/">
Order allow,deny
Allow from all
</Directory>
*Note that the alias for "static/admin" must match whatever alias and path are in the main settings.py file in your Django project directory
3. Create a django.wsgi file in the place that is specified by the path you used in the WSGIScriptAlias that contains the following:
import os
import sys
# Option one
#sys.path.append('/home/django/var/www')
#sys.path.append('/home/django/var/www/mgrm')
#os.environ['DJANGO_SETTINGS_MODULE'] = 'mgrm.settings'
#os.environ['DJANGO_ENV'] = 'PRODUCTION'
# Option two
# from http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
sys.path.insert(0,'/home/django/var/www/mgrm')
import settings
import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')
command.validate()
import django.conf
import django.utils
django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)
# Common to both options
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
*Note that this file goes inside your django project folder, preferably in an apache folder.
5. Edit main urls.py so that you can use files with both the django server and apache like this:
urlpatterns = patterns('',
# mod_wsgi does NOT pass the '/mgrm' mount point to this application. However,
# the django development server does. So in order to get these urls.py to
# work correctly with both, I created a match group that doesn't create a
# back reference. That match group is this: (?:mgrm/)?
url(r'^(?:mgrm/)?polls/',include('polls.urls')),
# Admin sites are doing some reverse url lookup, and the match group trick
# doesn't work with them. To resolve this issue we create two references:
# one for mod_wsgi, and the other for the development server.
url(r'^admin/',include(admin.site.urls)),
url(r'^mgrm/admin/', include(admin.site.urls)),
)
6. May need to edit templates to add the application name to each url in the template.
1. Follow installation instructions for mod_wsgi and django
2. Add to httpd.conf
# ----------- Django / WSGI Configuration ----------
WSGIDaemonProcess processes=2 threads=15
WSGIScriptAlias /mgrm "/home/django/var/www/mgrm/apache/django.wsgi"
<Directory "/home/django/var/www/mgrm/">
Order allow,deny
Allow from all
</Directory>
Alias "/static/admin" "/opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/"
<Directory "/opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media/">
Order allow,deny
Allow from all
</Directory>
*Note that the alias for "static/admin" must match whatever alias and path are in the main settings.py file in your Django project directory
3. Create a django.wsgi file in the place that is specified by the path you used in the WSGIScriptAlias that contains the following:
import os
import sys
# Option one
#sys.path.append('/home/django/var/www')
#sys.path.append('/home/django/var/www/mgrm')
#os.environ['DJANGO_SETTINGS_MODULE'] = 'mgrm.settings'
#os.environ['DJANGO_ENV'] = 'PRODUCTION'
# Option two
# from http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
sys.path.insert(0,'/home/django/var/www/mgrm')
import settings
import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')
command.validate()
import django.conf
import django.utils
django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)
# Common to both options
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
*Note that this file goes inside your django project folder, preferably in an apache folder.
5. Edit main urls.py so that you can use files with both the django server and apache like this:
urlpatterns = patterns('',
# mod_wsgi does NOT pass the '/mgrm' mount point to this application. However,
# the django development server does. So in order to get these urls.py to
# work correctly with both, I created a match group that doesn't create a
# back reference. That match group is this: (?:mgrm/)?
url(r'^(?:mgrm/)?polls/',include('polls.urls')),
# Admin sites are doing some reverse url lookup, and the match group trick
# doesn't work with them. To resolve this issue we create two references:
# one for mod_wsgi, and the other for the development server.
url(r'^admin/',include(admin.site.urls)),
url(r'^mgrm/admin/', include(admin.site.urls)),
)
6. May need to edit templates to add the application name to each url in the template.
Subscribe to:
Posts (Atom)