Ph: 67225128241


Sep 25 2008

Setting up Django on a WHM/cPanel VPS (LiquidWeb)

Tag: Programming & InternetDustin @ 5:55 am

I ordered a new VPS from LiquidWeb for the purpose of using it to host our company’s new product that I’m currently writing in Django. I have another VPS with LiquidWeb and I highly recommend them!

I got Django up and running on my other server with some help of LiquidWeb support. This time I’m going to attempt to do it on my own and document the process as I’m sure this won’t be the last time I need to set this up. Hopefully, it can help someone else out there looking to do the same.

Python 2.4.3 is installed by default. My original plan was to use Python 2.5.2, but I had problems compiling database bindings with 2.5, so I finally gave up and decided to stick with 2.4.

Install PostgreSQL & Python Database Bindings

I’m quite familiar with MySQL, but knowing that Django creators have a fondness for PostgreSQL, I thought I might attempt to use it for this project. (My development so far has been using SQLIte, but I don’t think that it will be adequate for this project). I didn’t have PostgreSQL installed, but installing it was pretty straight forward. cPanal has an installer script (thanks LiquidWeb support for the tip):

 

# /scripts/installpostgres

 

 

After installation, I set the password in WHM and now the database options appeared in cPanel:

image

Just follow the wizard to create your database.

Next, I installed psycopg to bind python to PostgreSQL.

 

# cd /usr/local/src
# wget http://initd.org/pub/software/psycopg/psycopg2-2.0.8.tar.gz
# tar xzvf psycopg2-2.0.8.tar.gz
# cd psycopg2-2.0.8
# python setup.py build
# python setup.py install

 

 

Build and Install WSGI

Basically, here are the commands I ran to download and complie wsgi:

cd /usr/local/src/
wget http://modwsgi.googlecode.com/files/mod_wsgi-2.3.tar.gz
gzip -dc mod_wsgi-2.3.tar.gz | tar xf -
cd mod_wsgi-2.3
./configure
make && make install

After compiling the module, I was given the path to where it was located (/usr/lib/httpd/modules/mod_wsgi.so).

I logged in to WHM -> Server Configuration -> Apache Setup -> Include Editor to add the following line to load the module:
image

LoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so
AddHandler wsgi-script .wsgi

image

If it works for you… Lucky you. Unfortunately I got this error:

Configuration problem detected on line 220 of file /usr/local/apache/conf/httpd.conf: : Syntax error on line 1 of /usr/local/apache/conf/includes/pre_virtualhost_2.conf: API module structure ‘wsgi_module’ in file /usr/lib/httpd/modules/mod_wsgi.so is garbled - expected signature 41503232 but saw 41503230 - perhaps this is not an Apache module DSO, or was compiled for a different Apache version? — /usr/local/apache/conf/httpd.conf — 214 215 216 217# SUEXEC is supported 218 219Include “/usr/local/apache/conf/includes/pre_virtualhost_global.conf” 220 ===> Include “/usr/local/apache/conf/includes/pre_virtualhost_2.conf” <=== 221 222# DO NOT EDIT. AUTOMATICALLY GENERATED. IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES. 223NameVirtualHost * 224 225# Default vhost for unbound IPs 226 — /usr/local/apache/conf/httpd.conf —

My first thought was that I had two versions of Apache installed, but I noticed my ./configure command said it found Apache 2.2.9. I asked LiquidWeb Support and they said that it was likely because I needed FastCGI installed.

So in WHM again, I went to Software -> Apache Update and reinstalled Apache and added fastcgi support.

That didn’t help either.

So I posted to the modwsgi google group and got help from the modwsgi author himself, Graham Dumpleton and was able to install the correct version by specifying the apxs file located in /usr/local/apache/bin/. So back in /usr/local/src/mod_wsgi-2.3, I ran the following commands to rebuild modwsgi:

# make distclean
# ./configure --with-apxs=/usr/local/apache/bin/apxs
# make && make install

The output was more concise this time. Then I when back into WHM -> Server Configuration -> Apache Setup -> Include Editor and loaded the module and restarted apache and it all worked this time! Thank you Graham!

I followed the Quick Configuration Guide to test WSGI to make sure it was working and learn a bit more about how it works. I recommend that you do too. Everything worked by the way. Well come back to modwsgi setup in a moment, but first we need to install Django.

Install Django

Download and installation of Django 1.0 was quite simple really - the easiest part of the gig.

cd /usr/local/src
wget http://www.djangoproject.com/download/1.0/tarball/
tar xzvf Django-1.0.tar.gz
cd Django-1.0
python setup.py install

Run Baby, Run

Now, we attempt to put it all together!

This set up will need to be run per domain/account. First, lets create our wsgi app that will call the Django application.

I already have my account set up on WHM where I will run my Django app. It is fcabi.net and the username is fcabi, so where every you see this, be mindful to replace it with your specifics.

Create a file in /home/fcabi/public_html with the following python code:

 

import os, sys
sys.path.append('/home/fcabi/public_html')
sys.path.append('/home/fcabi/public_html/fcabinet')
os.environ['DJANGO_SETTINGS_MODULE'] = ‘fcabinet.settings’

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

 

 

Next I create a file to add my virtual host directives in.

 

# mkdir -p /usr/local/apache/conf/userdata/std/2/fcabi/fcabi.net/
# vi /usr/local/apache/conf/userdata/std/2/fcabi/fcabi.net/wsgi.conf

 

 

I enter the following:

 

<IfModule mod_alias.c>
Alias /robots.txt /home/fcabi/public_html/fcabinet/media/robots.txt
Alias /favicon.ico /home/fcabi/public_html/fcabinet/media/favicon.ico
Alias /media /home/fcabi/public_html/fcabinet/media
Alias /adminmedia /home/fcabi/public_html/fcabinet/media/adminmedia
</IfModule>

<IfModule mod_wsgi.c>
WSGIScriptAlias / /home/fcabi/public_html/django.wsgi
WSGIDaemonProcess django threads=15 display-name=%{GROUP}
WSGIProcessGroup django
WSGIApplicationGroup %{GLOBAL}
</IfModule>

 

 

Next I run the cPanel script to add the include file to the main httpd.conf file and make sure the changes stick, then I restart apache.

 

# /usr/local/cpanel/bin/build_apache_conf

 

 

After running this command, I should see the Include to the file I just created:

 


    ServerName fcabi.net
    ServerAlias www.fcabi.net
    DocumentRoot /home/fcabi/public_html
    ServerAdmin webmaster@fcabi.net
    UseCanonicalName Off
    CustomLog /usr/local/apache/domlogs/fcabi.net combined
    CustomLog /usr/local/apache/domlogs/fcabi.net-bytes_log "%{%s}t %I .\n%{%s}t %O ."
    ## User fcabi # Needed for Cpanel::ApacheConf
    <IfModule !mod_disable_suexec.c>
        SuexecUserGroup fcabi fcabi
    </IfModule><VirtualHost 67.227.189.54:80>

Include “/usr/local/apache/conf/userdata/std/2/fcabi/fcabi.net/*.conf”

</VirtualHost>

 

 

It’s there, so I restart apache.

 

# /usr/sbin/apachectl restart

Notice that I added an alias to adminmedia. To get this to work, I also had to add a symbolic link to to the contrib/admin/media files:

# ln -s /usr/local/lib/python2.4/site-packages/django/contrib/admin/media/ /home/fcabi/public_html/fcabinet/media/adminmedia

 

Bonus: Wildcard Subdomains

My application makes use of wildcard sub-domains, so I also needed this to work as well. This was fairly easy to implement.

Log in to cPanel and click on Subdomains:
image

For the subdomain, enter “*” and click create (Document Root may autopopulate with “/public_html”, this is normal).

Now, set up virtual host directives for this subdomain like you did with your original domain.

 

# mkdir -p /usr/local/apache/conf/userdata/std/2/fcabi/wildcard_safe.fcabi.net/
# vi /usr/local/apache/conf/userdata/std/2/fcabi/wildcard_safe.fcabi.net/wsgi.conf

 

 

Enter the following:

 

<IfModule mod_alias.c>
Alias /robots.txt /home/fcabi/public_html/fcabinet/media/robots.txt
Alias /favicon.ico /home/fcabi/public_html/fcabinet/media/favicon.ico
Alias /media /home/fcabi/public_html/fcabinet/media
</IfModule>

<IfModule mod_wsgi.c>
WSGIScriptAlias / /home/fcabi/public_html/django.wsgi
WSGIDaemonProcess django-sub threads=15 display-name=%{GROUP}
WSGIProcessGroup django-sub
WSGIApplicationGroup %{GLOBAL}
</IfModule>

 

 

* Notice the the WSGIDaemonProcess name is must be different.

Rebuild the config file and restart apache.

# /usr/local/cpanel/bin/build_apache_conf
# /usr/sbin/apachectl restart

PS. If you’re using sub-domains, you might find my sub-domain middleware useful.


Sep 11 2008

Django Accounts on Subdomains

Tag: Programming & InternetDustin @ 11:33 am

*Disclaimer: I’m a Django and Python newbie. Your mileage may vary following my advice.

My Goal is to create an accounts system similar to Unfuddle, where to register for a new account, a user will enter a subdomain and admin login (see Unfuddle registration).

Users can’t really log in from the home page - only from their subdomain. Once they are logged in, administrators can add more users that only have access to that subdomain.

FYI, I’m not competing against Unfuddle. I’m just very familiar with their system as I am a happy paying user. There are a number of other sites using this kind of accounting system. I’m sure I could implement it in PHP, but I really want to learn Django so I’m sticking with it on this project.

I would like to give props to the developers of Unfuddle as they have been more than helpful in reguards to sharing the structure of their application and the way they do things. Thanks guys! I’m sure if I were writing this in Ruby on Rails they would be even more helpful as their application is written in Rails.

Now, back to the show.

I’m trying to use as much pre-existing code as possible so I can take advantage of others knowledge and so I don’t have to reinvent any wheels.

I’m doing my development and testing on Windows. So in order to test this, I’ve edited my hosts files (C:\WINDOWS\system32\drivers\etc\hosts) with my main domain and a few subdomains that I want to test. When I go live, I will likely remove these from the hosts files and set up wildcard dns & subdomains on the server.

Here is an example of my hosts file entries used to test:

127.0.0.1    sample.com
127.0.0.1    www.sample.com
127.0.0.1    test.sample.com
127.0.0.1    company.sample.com
127.0.0.1    django.sample.com
127.0.0.1    nerd.sample.com
127.0.0.1    dork.sample.com

So far, this is what I’ve done to implement:

1. Install django-registration - I just checked out the latest source and plugged the registration folder into my project. Once I got it set up, I added a field to the form.

This is still a work in progress so I’ll have to come update later. Basically my goal is to have a registration form that also asks for the subdomain and title of the user or company. Then I will append the subdomain to the username before saving it to the Users table so that username can be unique within sub-domains.

2. I created a simple middleware inside my application. This basically reads the HTTP_HOST and sets request.domain and request.subdomain. If there is no subdomain, or the subdomain is ‘www’, then it returns and empty string.

3. My main template will have a link to log in. If they are on their subdomain they will see the login screen (I’m using django.contrib.auth for authentication and login forms). If they are on the main site, they will first be asked for their subdomain. After entering their subdomain, they will be redirected.

Here are the contents of my app’s login function.
The subdomain form and template are quite trivial to create.

I hope this helps someone. I hope to expand this post when I get further into it.


Sep 11 2008

Setting up Wildcard DNS & Subdomains on cPanel

Tag: Programming & InternetDustin @ 8:18 am

*** UPDATE: DON’T READ THIS POST… JUST READ COMMENT #2 FROM CPANEL ***

I’ve posted instructions in the past on how to set up wildcard DNS and subdomains on DirectAdmin. DirectAdmin makes it rather trivial, which is quite nice. There is a little bit more effort involved in cPanel - manly because you actually have to make some modifications via SSH. So I would say this tutorial involves and intermediate skill level to accomplish (it can’t be more because this is about the extent of my skill level). You will need access to WHM and root access to your server.

Background: I’m currently learning Django and trying to create a solution for sub-domaining accounts. I’ve been told by a few people that this will be the hardest part to set up. At my currently Django level, this part is trivial. I hope to make more posts when I get the Django parts figured out as well. Stay tuned.

Step 1: DNS: A Record

First we’ll need to log in to WHM. Under DNS Functions, select Edit DNS Zone. Choose the domain for the zone in which you wish to edit. Add an A record mapped to asterisk (wildcard) for the subdomain and the IP Address the site is hosted on. You likely already have A records for ftp, webmail, etc. just model this new one after those.

You should now be able to enter any subdomain on your domain, but it will not likely find your main site. So now we need to set that up.

Step 2: ServerAlias

Log in to your server via SSH and go open /etc/httpd/conf/httpd.conf (I’ll assume you know your way around linux via command line as well as vi or some other editor)

*Note: wherever you see deqb.com you should expect to see your domain name that you are setting up

Now, we could edit this file and make everything work, but there is a problem with that. Look at the top of the document and you should see something like this:

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#   Direct modifications to the Apache configuration file may be lost upon subsequent regeneration of the       #
#   configuration file. To have modifications retained, all modifications must be checked into the              #
#   configuration system by running:                                                                            #
#       /usr/local/cpanel/bin/apache_conf_distiller –update                                                    #
#   To see if your changes will be conserved, regenerate the Apache configuration file by running:              #
#       /usr/local/cpanel/bin/build_apache_conf                                                                 #
#   and check the configuration file for your alterations. If your changes have been ignored, then they will    #
#   need to be added directly to their respective template files.                                               #
#                                                                                                               #
#   It is also possible to add custom directives to the various “Include” files loaded by this httpd.conf       #
#   For detailed instructions on using Include files and the apache_conf_distiller with the new configuration   #
#   system refer to the documentation at: http://www.cpanel.net/support/docs/ea/ea3/customdirectives.html       #
#                                                                                                               #
#   This configuration file was built from the following templates:                                             #
#     /var/cpanel/templates/apache2/main.default                                                                #
#     /var/cpanel/templates/apache2/main.local                                                                  #
#     /var/cpanel/templates/apache2/vhost.default                                                               #
#     /var/cpanel/templates/apache2/vhost.local                                                                 #
#     /var/cpanel/templates/apache2/ssl_vhost.default                                                           #
#     /var/cpanel/templates/apache2/ssl_vhost.local                                                             #
#                                                                                                               #
#  Templates with the ‘.local’ extension will be preferred over templates with the ‘.default’ extension.        #
#  The only template updated by the apache_conf_distiller is main.default.                                      #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Basically what it’s saying is don’t edit this file directly because you’re changes may be lost.

Do a search for the domain you are adding the wildcard to. You should find the VirtualHost set up for your domain. Here is mine:

# DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.


    ServerName<VirtualHost 67.225.128.241:80>
deqb.com
    ServerAlias www.deqb.com
    DocumentRoot /home/deqb/public_html
    ServerAdmin webmaster@deqb.com
    UseCanonicalName Off
        Options -ExecCGI -Includes
        RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
    CustomLog /usr/local/apache/domlogs/deqb.com combined
    CustomLog /usr/local/apache/domlogs/deqb.com-bytes_log “%{%s}t %I .\n%{%s}t %O .”
    ## User deqb # Needed for Cpanel::ApacheConf
    <IfModule !mod_disable_suexec.c>
        SuexecUserGroup deqb deqb
    </IfModule>

    # To customize this VirtualHost use an include file at the following location
    # Include “/usr/local/apache/conf/userdata/std/2/deqb/deqb.com/*.conf”

 

</VirtualHost>

Notice the highlighted lines. This is where we are going to create a file. We are going to create a file at:
/usr/local/apache/conf/userdata/std/2/deqb/deqb.com/ServerAlias_wildcard.conf
(you can give it any name you want really)

*Hint: You may need to create the directories first, run this command:
mkdir -p /usr/local/apache/conf/userdata/std/2/deqb/deqb.com/

So really, you don’t need to edit anything it httpd.conf, we just needed some info.

Inside of the ServerAlias_wildcard.conf file, enter this line:
ServerAlias *.deqb.com

Now, you’ll need to rebuild the httpd.conf file per the instructions at the top of that file by running the following command:
/usr/local/cpanel/bin/build_apache_conf

If you open your /etc/httpd/conf/httpd.conf file again you should see that your VirtualHost for your domain as changed slightly:


    ServerName<VirtualHost 67.225.128.241:80>
deqb.com
    ServerAlias www.deqb.com
    DocumentRoot /home/deqb/public_html
    ServerAdmin webmaster@deqb.com
    UseCanonicalName Off
        Options -ExecCGI -Includes
        RemoveHandler cgi-script .cgi .pl .plx .ppl .perl
    CustomLog /usr/local/apache/domlogs/deqb.com combined
    CustomLog /usr/local/apache/domlogs/deqb.com-bytes_log “%{%s}t %I .\n%{%s}t %O .”
    ## User deqb # Needed for Cpanel::ApacheConf
    <IfModule !mod_disable_suexec.c>
        SuexecUserGroup deqb deqb
    </IfModule>

    Include “/usr/local/apache/conf/userdata/std/2/deqb/deqb.com/*.conf”

</VirtualHost>

 

Step 3: Restart Apache

The last step required is to restart apache. I suppose there are a number of ways to do this. As long as we are logged in to SSH, we might as well just run the command:
/usr/sbin/apachectl restart

Now, give it a try. you should be aby to access something like http://itworked.deqb.com and still see your main page.

Technorati Tags: dns, wildcard dns, subdomain, django, cpanel, whm


Sep 10 2008

Gmail + Thunberbird = WOW

Tag: Programming & InternetDustin @ 6:12 am

I’ve been using Gmail as my main email client for about the past 4 years or so. I currently have Thunderbird set up with SMTP to use for certain situations - mainly when I want to copy and past images in - like showing screenshots to people. (I still prefer the speed of the web app - and being able to make it look like an app with Google Chrome/Google Gears is just that much sweeter)

Today I noticed something really cool. I got an email request from a client for updates to his website. I was composing a reply in Thunderbird with screenshots and all. In the process, I had a Gmail client open (in Google Chrome) and I was reading his initial email again to make sure there wasn’t something I missed.

At the bottom of the screen it said there was a new message with a link to update the conversation. I’ve seen this before on rare occassions. I figured he had sent me a follow up email. When I clicked the update link I saw the draft of the message I was composing in Thunderbird - screenshots and all. How cool is that?

Ok, maybe I’m over dramatic. But I thought it was neato!

Technorati Tags: gmail, thunderbird


Aug 20 2008

Backing Up

Tag: Products, Programming & InternetDustin @ 4:23 am

You’ve all heard the horror stories. You go to boot up you computer, nothing happens… perhaps you hear a click… click… click…

This actually happened to me a couple years ago. Luckily my hard drive started working again just long enough for me to get a back-up before replacing it.

I recently heard of an acquaintance that had this happen to them. It reminded me of how vulnerable I am. I have no back-up plan!

I do however have a plan now. I’m signing up for mozy. Yeah, I’ve heard about about the great claims with Carbonite from all the radio shows (Rush, Dr. Laura, etc. etc.). We’ve even used Carbonite at work. I think its great, but when I did a search to see what other players are out there, I found mozy.

Why mozy?

I recognized their name. There are here it Utah. A couple years ago they sponsored a coding competition with a cash prize of $10,000. It was basically a recruiting effort to expose some of the best local talent.

But it is not just name recognition alone. I’ve done my homework and they are the real deal. Check out these videos:

This page contained an embedded video. Click here to view it.

So what are you waiting for? Get backing up! You’ll thank yourself someday. It’s only $4.95 for unlimited storage. If you can’t afford it, start with the free plan and back up your most important 2 GB (like your My Documents folder)

Mozy Online Backup. 2GB Free or $4.95/mo for Unlimited Backup. It’s simple, automatic and secure!

Oh, and one tip… If you are going to sign up for unlimited and decide to pay for a 1 year or 2 year plan, save 10% by entering “AUGUST” in the promo code (good until the end of August obviously!).
[image]


Aug 11 2008

Django Model Style Guide

Tag: Programming & InternetDustin @ 11:58 am

(This post is mostly for my own reference)

James Bennett mentions a Django style guide in his book Practical Django Projects. I couldn’t find reference to it, but the following is the order of things when it comes to models:

Any constants and/or lists of choices The full list of fields The Meta class if present The Admin class if present The __unicode__() method The save() method, if its being overridden The get_absolute_url() method, if present Any additional custom methods

Aug 01 2008

I Love Cool Tools

Tag: Internet Marketing, Programming & InternetDustin @ 6:07 am

I love cool tools! I wanted to start a new blog. So I registered domain, set up an account on my cPanel VPS, used Fantastico to create a WordPress blog, found a theme and modified some settings. Viola! - a new blog in less than an hour. Now I just have to wait for 1&1 to update the DNS servers. I think if I registered the domain at Godaddy I really could have the site live and ready to go in under an hour. (I use 1&1 simply because they are cheaper.)

Oh, and by the way. I made this post using ScribeFire, which is also one cool tool!

Technorati Tags: blog, wordpress, fantastico, cpanel, 1&1, godaddy, scribefire


Jul 08 2008

Web Frameworks Rock

Tag: Programming & InternetDustin @ 10:39 am

After doing maintenance on a few PHP projects, I’ve come to the conclusion that I really need to use frameworks for medium to big projects. After looking at a few frameworks in a few different languages, I’ve run across a pretty cool website at sucks-rocks.com.

I plugged in a number of popular web languages and frameworks just to get an idea of what people are saying about them. The results are pretty interesting. First take a look at some language comparisons. Then, look at some framework comparisons. And finally, I thought I’d check out some Javascript libraries.

Conclusion: With Web 2.0 design, you can’t go wrong by picking a good framework and throwing in some ajax.


Jul 01 2008

Liquidweb Rocks

Tag: Programming & InternetDustin @ 5:12 am

I just need to give some props to Liquidweb. I have a cPanel VPS account there. I have been impressed with their “Heroic Support”. Recently though, they went above and beyond.

I’ve been having PHP mid career crisis of sorts and been looking at other languages and frameworks. Django and Python have caught my eye. I started developing an application, but I wanted to first see if I could deploy it to my server before I got too far into it.

I strugged for 3 or 4 days trying. I spent a lot on time on IRC and they guys there were quite helpful, but they couldn’t figure out why my deployment was not working either. Finally, after hitting a brick wall, I submitted a support ticket. Because it was 3 party software I wasn’t expecting much.

I was blown away by the level of service I got. The first person had never heard of Django, but she read the documentation on how to install it and pointed me to the right files to edit. Later she passed me on to someone else who was more familiar with Django. In all I got responses from 4 different people who worked on this issue. They got it up and running and explained what they did. Kudos to Liquidweb.


Jun 19 2008

Update Windows Path Without Rebooting

Tag: Programming & InternetDustin @ 4:38 am

I find it quite annoying that whenever I read instructions that include adding an environment path variable you are asked to reboot your machine for changes to take effect. I know there has GOT to be a way to do it. Well, I know a way, but it’s someway kludgy.

Here is how I do it (I’m really hoping someone will comment and tell me a better way)

Continue reading “Update Windows Path Without Rebooting”


Next Page »


ss_blog_claim=4973c51f5e7bec57951f995fed1b85f3ss_blog_claim=4973c51f5e7bec57951f995fed1b85f3


You are viewing a mobilized version of this site...
View original page here

How do you rate mobile version of this page?

Mobilized by Mowser Mowser