Setting up Apache2, mod_python, MySQL, and Django on Debian Lenny or Ubuntu Hardy Heron

posted on October 15th, 2008 by Greg Allard in Greg's Posts on Code Spatter

Both Debian and Ubuntu make it really simple to get a server up and running. I was trying a few different Machine Images on Amazon and I found myself repeating a lot of things so I wanted to put them here for reference for those who might find it useful.

With a fresh image, the first thing to do is update apt-get.

apt-get update && apt-get upgrade -y

Then grab all of the software to use.

apt-get install -y xfsprogs mysql-server  apache2  libapache2-mod-python  python-mysqldb  python-imaging  python-django  subversion php5  phpmyadmin

xfsprogs is for formatting an Elastic Block Store volume and may not be needed in all cases.

I like to check out the latest version of Django from their repository, it makes it easier to update it later. This also starts a project named myproject (this name is used later).

cd /usr/lib/python2.5/site-packages
svn co django
ln -s /usr/lib/python2.5/site-packages/django/bin/ /usr/local/bin
cd /var/www startproject myproject

Now to edit the apache config to tell it about our project.

cd /etc/apache2
nano httpd.conf

Add the following to set up python to run the django files and php to run the phpmyadmin files. There is also an example of serving static files. Change where it says myproject if you used a different name.

<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE myproject.settings
    PythonOption django.root /myproject
    PythonDebug On
    PythonPath "['/var/www'] + sys.path"
Alias /adm_media/ /usr/lib/python2.5/site-packages/django/contrib/admin/media/
<Location "/adm_media/">
    SetHandler None
Alias /files/ /var/www/myproject/files/
<Location "/files/">
    SetHandler None
Alias /phpmyadmin/ /usr/share/phpmyadmin/
<Location "/phpmyadmin/">
    SetHandler None

Restart apache for it to use the new configuration.

/etc/init.d/apache2 restart

The only thing left to do is set up the database. If Ubuntu had you set up a root password already, add -p to the end of the following command to use it.


There are some users in mysql without username, it is best to remove those.

drop user ''@'localhost';

Do that for each host that has a blank username. Use the following to see all users.

SELECT user, host FROM mysql.user;

Create a database and add a user.

GRANT ALL ON db_name.* to user_name WITH GRANT OPTION;
SET PASSWORD FOR user_name = password('psswdhere');

If root doesn’t have a password yet, use the above commant with root as the username.

Amazon has a page about
how to use EBS with MySQL, but
there are reported issues with using Debian Lenny and EBS.

Code Spatter

posted on April 1st, 2008 by Greg in Personal Projects

Code Spatter is a personal project that I started when I thought it would be useful to have a Weblog about projects and other things involving web development to be used by myself and other co-workers. It was also a chance to use CyTE for a practical application and start development on MorfU. Both are open source projects that I develop for.

Read the rest of this entry »

Tragedy Guild Website

posted on April 1st, 2008 by Greg in Personal Projects

The Guild

Tragedy was a guild in World of Warcraft that had up to 40 members in a single raid event as often as 4-5 nights a week. There was a lot of information that needed to be saved from the raids. It was important to know which members attended them and which monsters were defeated that evening. The monsters would drop loot and it was necessary to know who received the loot. There was a game modification that would store all of this data, but there wasn’t an easy way to get this information onto the website.

Read the rest of this entry »

TechStream (aka ToBeDone 2.0)

posted on April 1st, 2008 by Greg in CDWS Projects

Workflow Management

To Be Done is a Web-based workflow tool that manages the collection, tracking, and processing of work requests. It is written in PHP and uses a MySQL database. It facilitates the collaboration between teams by enabling team members to create requests for other teams’ members to complete. Time-to-completion data is stored when a user completes a request and can be used to display totals, percentages, and averages of requests and hours in a report that can be generated automatically. The report that is generated can also display specific information per user and per course.

Read the rest of this entry »

Study Session Scheduler

posted on April 1st, 2008 by Greg in Class Projects

SSS is designed to help students schedule study sessions by allowing them to input their available times and to view available times of students in their courses. A student can start a session at a time that the most people are available and other students can sign up to the study session. This was a project for Software Engineering I and originally suggested by Chris Havreberg. I collaborated with coworker and classmate, Thomas Welfley to develop this site in a surprisingly short amount of time. This was the first test of a new version of a template engine that Thomas and I had been working on (CyTE).

Pyrodius, Inc

posted on April 1st, 2008 by Greg in Personal Projects

All of my web development experience started with I learned PHP and MySQL to allow the website to dynamically add movie reviews to the website and allow users to post their own reviews. I created a blog to display the news of the website before I even heard the word “blog”.

At the moment the site doesn’t have any activity, but I will still use it to learn and test out new software or ideas. I have installed a few versions of phpBB and MediaWiki to test out various ideas. CyTE is also installed there for testing.

There are many things I aspire to do with the site, however other projects have taken priority for the time being.


posted on April 1st, 2008 by Greg in Personal Projects

MorfU is a project that I conceived that will combine all of the features of wikis, blogs, and forums. The name is an anagram of forum and is pronounced like morph you.

Current the only development that has been done on it is with Codespatter which only has limited blog functionalities.

This is a module for CyTE that should be able to be packaged with any installation seamlessly. There hasn’t been much else to test this with as of yet.

UCF Life

posted on March 24th, 2008 by Greg in Freelance Projects

This site was originally created by a freelance web developer and I have helped in a few areas to improve load/execution time and added a few sections. The site is written in PHP and uses a MySQL database.

I developed a section to allow users to sell books to each other. It used an API to Amazon’s book database to get accurate and up-to-date information regarding book details. At first, the section would charge a percentage of the expected sale before listing a user’s books. The fee was later removed to encourage more use of the section.

Another section of the site that I developed was the Nightlife section. For unknown reasons, this section was never made live. Businesses had their own interface in which they could change information about their weekly promotions. Users could use a simple search to browse through nightclubs, or browse by night, as well as indicate that they were attending a specific nightclub on a specific night.

I have also mentored another developer in PHP and MySQL to allow him to be able to complete additions to the site.


posted on March 24th, 2008 by Greg in CDWS Projects

Valhalla, which is implemented with PHP and a MySQL database, powers the Techranger Web site. It provides the Techranger team with the ability to manage all aspects of the site including: image galleries, user biographies, job applications, XHTML templates, multiple cascading style sheets and other site features.

For this project I created the data access classes as well as designing the database itself. I also wrote the job application, image gallery, project showcase, and user biography features.

Python and Django

posted on March 24th, 2008 by Greg in Personal Projects

I’ve gone through part of the Django tutorial. I installed the latest copy of Django, Python, and MySQL on my desktop (windows environment) and followed the tutorial through the first three sections. I’ve started to become familiar with the data models and the admin interface.

At the moment I am liking Django’s admin interface that is created by default a little bit more than the scaffolding that can be used with Ruby on Rails. As far as comparing Ruby and Python I still don’t know enough about either language to make a decision.

Update 7/24/8

Going outside of the tutorial, I created a few views and templates to get the basic idea. Using the Django Authentication module’s User model, I displayed a few things and plowed through a few of my own mistakes. I’m enjoying learning this.

Update 7/30/8

Finished the tutorial and moved on to create my own interface for Django’s Authentication. The app can create users, log them in and out, and list them. Simple enough, but I got the hang of the templates and form helpers.

More in this later post.