views:

799

answers:

10

I'm running Leopard and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the future.

EDIT: I've been trying to get mod_wsgi installed and configured to work with Django and have a headache now. Are there any web hosts that currently use mod_wsgi besides Google so I could just develop there?

A: 

What you're looking for is Mod_Python. It's an Apache-based interpreter for Python. Check it out here:

http://www.modpython.org/

Robert Elwell
more like mod_wscgi. mod_python is generally considered too low-level for web development.
Javier
+2  A: 

Most python apps are moving away from mod_python. It can vary by framework or provider, but most development effort is going into mod_wsgi.

Using the WSGI standard will make you python app server agnostic, and allow for other nice additions like WSGI middleware. Other providers may only provide cgi (which won't scale well performance wise), or fastcgi.

JimB
Agree, built it with WSGI and you can happily run it on all the interfaces mentioned so far, mod_wsgi, mod_python, CGI, even GAE with limitations.
bobince
A: 

Google App Engine has done it for you. Some limitations but it works great, and it gives you a path to hosting free.

slf
+1  A: 

I've worked with django using only the included server in the manager.py script and have not had any trouble moving to a production environment.

If you put your application in a host that does the environment configuration for you (like webfaction) you should not have problems moving from development to production.

Null303
A: 

Of course Mac OS X, in recent versions, comes with Python and Apache. However you may want to have more flexibility in the versions you use, or you may not like the tweaks Apple has made to the way they are configured. A good way to get a more generic set of tools, including MySQL, is to install them anew. This will help your portability issues. The frameworks can be installed relatively easily with one of these open source package providers.

Glenn
I've looked into MAMP before, is there any way to get mod_wsgi to work with it?
I don't know. Someone else?
Glenn
+1  A: 

FWIW, we've found virtualenv [http://pypi.python.org/pypi/virtualenv] to be an invaluable part of our dev setup. We typically work on multiple projects that use different versions of Python libraries etc. It's very difficult to do this on one machine without some way to provide a localized, customized Python environment, as virtualenv does.

psj
A: 

You may want to look into web2py It includes an admin interface to develop via your browser. All you need in one package, including python.

massimo
+1  A: 

I run a linux virtual machine on my mac laptop, this allows me to keep my development environment and production environments perfectly in sync (and make snapshots for easy experimentation / rollback). I've found VMWare Fusion works the best, but there are free open source alternatives such as VirtualBox if you just want to get your feet wet.

I share the source folders from the guest linux operating system on my mac and edit them with the mac source editor of my choosing (I use eclipse / pydev because the otherwise excellent textmate doesn't deal well with Chinese text yet). I've documented the software setup for the guest linux operating system here, it's optimized for serving multiple django apps (including geodjango).

For extra added fun, you can edit your mac's /etc/hosts file to make yourdomainname.com resolve to your guest linux boxes internal IP and have a simple way to work on / test multiple web projects online or offline without too much hassle.

Prairiedogg
A: 

Check out webfaction—although I don't use them (nor am I related to / profit from their business in any way) I've read over and over how great their service is and particularly how django-friendly they are. There's a specific post in their forums about getting up and running with django and mod_wsgi.

Like others before me in this thread, I highly recommend using Ian Bicking's virtualenv to isolate your development environment; there's a dedicated page in the mod_wsgi docs for exactly that sort of setup.

I'd also urge you to check out pip, which is basically a smarter easy_install which knows about virtualenv. Pip does two really nice things for virtualenv-style development:

  • knows how to install from source control (svn, git, etc...)
  • knows how to "freeze" an existing development environement's requirements so that you can create that environment somewhere else—very very nice for multiple developers or deployment.
Idan Gazit
A: 

mod_wsgi is really, really simple.

Pyerweb is a really simple (~90 lines including comments/whitespace) WSGI-compliant routing-framework I wrote. Basically the WSGI API is just a function that gets passed environ, and wsgi_start_response, and it returns a string.

envrion is a dict with the request info, for example environ['PATH_INFO'] is the request URI)

wsgi_start_response which is a callable function which you execute to set the headers,:

wsgi_start_response(output_response, output_headers)

output_response is the string containing the HTTP status you wish to send (200 OK etc), and output_headers is a list-of-tuples containing your headers (for example, [("Content-type", "text/html")] would set the content-type)

Then the function returns a string containing your output.. That's all there is to it!

To run it, using spawning you can just do spawn scriptname.my_wsgi_function_nae and it will start listening on port 8080.

To use it via mod_wsgi, it's documentation is good, http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide and there is a django specific section

The up-side to using mod_wsgi is it's the standard for serving Python web-applications. I recently decided to play with Google App Engine, and was surprised when Pyerweb (which I linked to at the start of this answer) worked perfectly on it, completely unintentionally. I was even more impressed when I noticed Django applications run on it too.. Standardisation is a good thing!

dbr