Sunday, January 20, 2013

EC2 Django MySQL phpmyadmin

Here are some notes for getting Django/MySQL/phpmyadmin stack up and running on an EC2 instance. Instructions here are for Django 1.3, and Ubuntu 12.04 LTS.

Django is an excellent framework for building database backed websites, sites are largely built using python, and it takes care of a lot of stuff you'd otherwise have to write by hand (as I did in php years ago). I don't know about you, I'd rather use someone else's user authentication and session management packages: it was ok rolling my own in php (I learned a lot), but I am done with that. Plus, python is without question a much better language than php (all due credit to the php folks). Lots of other advantages as well (rich python libraries, django and otherwise; database tables and forms described as classes).

mysql is an excellent database, of course.

And phpmyadmin is an excellent  tool for configuring and managing MySQL databases.

So, it is natural to want to use them together. Django supports MySQL of course. But django wants to own / on apache, and to get phpmyadmin, you would need to set up virtual hosts. Maybe not a big deal (I did it once before), but I found an easier way. Let django own Apache, fine. Just run phpmyadmin on a different web server (lighttpd) that's listening on port 81. If you search the web a bit, you'll see that it's pretty common to do this. And you can put all your non-Django served content off of lighttpd (docs, etc..), and get some isolation between the two as well.

First, get Django up:
  • Make sure when you create the EC2 instance that you create a security group that enables TCP port 81. This allows you to run two web servers - apache for Django, and lighttpd for phpmyadmin. 
  • Install apache2, django, mysql packages using apt-get. Plenty of resources on the web describe this step. You will be prompted for an admin password when installing MySQL. Remember it, as this is your login to myphpadmin
  • Create an empty django project (plenty of docs on that too).
  • Hack on the settings file to enable MySQL for the django project.
  • Visit and follow instructions.
  • Make sure you can see the default Django page on port 80.
 Next, set up lighttpd and phpmyadmin:
  • Install lighttpd package
  • Install php5 package
    • apt-get install php5-fpm php5
  • Hack on /etc/lighttpd/lighttpd.conf 
  • Install phpmyadmin package
  • system mysql start
  • system lighttpd force-restart
  • Visit http://server:81/phpmymyadmin - it should be running
  • Login using the user and password configured when you installed the MySQL package.

No comments:

Post a Comment