Tuesday, June 30, 2009

Last (?) post about MediaTemple (dv) and Django

This is a refinement of a previous post on the topic of Django integration into a MediaTemple (dv) account. Following a talk with MT and reading some knowledgebase info, here is the quick route to Django configuration happiness - now more better.

This is how we do it:

Add to base config aka /etc/httpd/conf/httpd.conf the following in the appropriate section:
LoadModule wsgi_module modules/mod_wsgi.so
And in the appropriate section, add this too:
NameVirtualHost *:80

#Add a VirtualHost Section for each Name-based virtual server

<VirtualHost>
ServerAdmin email@email.com
ServerName www.URL.com
ServerAlias URL.com *.URL.com

DocumentRoot /var/www/vhosts/URL/httpdocs

<Directory /var/www/vhosts/URL/httpdocs>
Order allow,deny
Allow from all
</Directory>

</VirtualHost>


then save the file and exit the editor.

In the directory of path '/var/www/vhosts/(DOMAIN NAME)/conf' there is a file called 'httpd.include.' It holds unique config info for each virtual domain. It is rebuilt automatically from time to time based on Plesk. Instead of editing that file, make a new one called 'vhost.conf' (if it doesn't already exist) and add the following info to this file:

WSGIDaemonProcess URL.com processes=1 threads=1 display-name=%{GROUP}
WSGIProcessGroup URL.com
WSGIScriptAlias /myapp /home/username/django/scripts/URL.com.wsgi

<Directory /home/username/django/scripts>
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/URL.com-error_log
CustomLog /var/log/URL.com-access_log common
Notes on the above, in brief
  1. LoadModule is in httpd.conf
  2. NameVirtualHost declaration is in httpd.conf
  3. virtualhosts make use of /virtualhostname/conf/vhost.conf
  4. WSGIScriptAlias declarations are in respective vhost.conf, not in httpd.conf*
* This is because WSGIScriptAlias in httpd.conf didn't work

Once that is configured as you like, simply restart the server in this manner:
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=mt-example.com 
service httpd graceful

Now test your django. With any luck, you will see a screen confirming a correct installation.

4 comments:

Unknown said...

Thank you, I was able to alter this to work for web2py on (dv).

jasonthewolf said...

You are welcome! Glad to hear it helped.

I posted more info on using python frameworks with an ISP called Slicehost. Each has its advantages, the main difference being MT uses Plesk and Slicehost does not.

Good luck.

Unknown said...

Yes, This I have noticed. Plesk is pesky!

I might move over to Slicehost, mainly because I can't get SSL to work with WSGI on CentOS.

Any Ideas?

jasonthewolf said...

Not having plesk was a lot better for me. You do have to know more commands but there are plenty of walkthrus to help. The how-to's at Slicehost are incredible.

And SSL should work regardless, there must be a way!