Home » Blog » Django Gotchas When Moving To A Production Server

Django Gotchas when moving to a Production Server

If you’re a developer learning Python/Django then you’re almost certain to run into some of the same issues that I did. In particular, when deploying to a production server, the admin throws a 500 error and when trying to troubleshoot, your changes have no effect.

One of the key things to know, particularly if you’re coming from a PHP background, is that Apache must be restarted after you make any changes to your code. This happens automatically during the development phase when you use the built in Django server as you’ll know if you have a syntax error in your code. The exceptions here are static files and templates. They’ll work when you change them without restarting. I believe this has to do with Python’s compilation of files to improve performance – Only python files are compiled. On my Ubuntu box Apache can be restarted with:

sudo /etc/init.d/apache2 reload

If you’re using SQLite as your database – and for the vast majority of web apps that’s perfectly reasonable – then you need to make the database file AND it’s parent directory writable by the apache user. Sqlite creates a temporary file in the same directory as itself hence the need for the parent directory to be writable too.

Rather than just giving everyone access to the file, it’s more secure to explicitly grant access to the apache user. On Ubuntu the Apache user is www-data. To do this is to add your own user to the apache group and then assign the user and group read and write permissions on the SQLite database file.

sudo chgrp -R www-data /full/path/to/sqlite-database.db
chmod 660 path/to/sqlite-database.db

0 Comments

Add Your Opinions

Latest Tweet

Recent Posts

Elsewhere