* * * * * 1 votes

Setting up Django w/ Python2.3 on FCGI


  • Please log in to reply
39 replies to this topic

#1 Waylan

Waylan

    Small Orange

  • Members
  • PipPip
  • 26 posts

Posted 23 November 2005 - 04:23 PM

I almost have Django working on my tiny shared account. Actually, I think it works right, but I don't have the rewrite rules correct and that's causing the problem. Anyway, I'll step you through what I have so far.

First of all, you need to make sure you have Python2.3 for FCGI (and I think Django) to work. For more details about getting fcgi working, see this thread. You also need to have shell access. If you don't, submit a ticket to ASO support.

First, open your shell and confirm your version of Python (be sure to use a Capital V):
QUOTE
-jailshell-2.05b$ python -V
Python 2.3.4

If you have anything prior to 2.3.x you'll have to see about getting your server upgraded. (I'm told the new servers are at 2.3.x while the old are 2.2.x - if you just signed up for a new account, you should be good)
  • Ok, assuming your on one of the new servers, it's time to get started. Although Django is now offered both as a tarball and from svn, I chose to install from subversion as its easier to update to latest trunk etc. In your shell, make sure you're in your HOME dir and do:
    CODE
    cd ~
    svn co http://code.djangoproject.com/svn/django/trunk/ django_src
  • Edit your PYTHONPATH and PATH vars so that Django is available from your shell.
    CODE
    export PATH=$PATH:$HOME/django_src/django/bin
    export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects
  • Create a Django projects directory and create your first Django project.
    CODE
    mkdir django_projects
    cd django_projects
    django-admin.py startproject myproject
  • If you don't want other users on your shared host to have access to your DB settings, change the permissions on your myproject.settings file so that ONLY YOUR USER can read them.  
    CODE
    chmod 600 myproject/settings.py
  • Edit the myproject.settings (myproject/settings.py) file to add your database connection parameters.
  • Initialize the database.
    CODE
    django-admin.py init --settings=myproject.settings
  • Create a superuser account for use with the admin interface (follow the prompts).
    CODE
    django-admin.py createsuperuser --settings=myproject.settings
  • Now its time to create the publicly available directory. Whether you set that up as a sub domain through CPanel or just create a sub-dir under ~/public_html (which you can always point to with a sub domain of the same name later) is your choice. For this exersize, we'll assume your just creating a sub-dir, which needs to have the fcgi.py script.
    CODE
    cd ~/www
    mkdir myproject
    cd myproject
    wget http://svn.saddi.com/py-lib/trunk/fcgi.py
    chmod 755 fcgi.py
  • Now you need to create a file named django.fcgi in the same dir, which should contain the following (replace 'username' with your username on lines 3 and 4 and 'myproject' with the name of your project if it differs from the example used above):
    CODE
    #!/usr/bin/python
    import sys
    sys.path += ['/home/username/django_src']
    sys.path += ['/home/username/django_projects']
    from fcgi import WSGIServer
    from django.core.handlers.wsgi import WSGIHandler
    import os
    os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
    WSGIServer(WSGIHandler()).run()
  • Set the correct permissions on django.fcgi.
    CODE
    chmod 755 django.fcgi
At this point you should be able to go to http://yourdomain.com/myproject/django.fcgi/admin/ and http://yourdomain.com/myproject/django.fcgi/. I'm getting some python errors regarding the url which is most likely because there are no rewrite rules yet. However, when I try anything that makes sense, I get a 403 Forbidden error - which indicates a problem with the rewrite rules, not Django. I'm still working on it.

So that credit is made where credit it due, I copied most of this directly from the Dreamhost wiki making a few minor adjustments for differences in the server setup here at ASO.

When I get the rewrite rules etc worked out, I'll post them here as well. Of course, if someone has any insight, that would be great. In case your wondering, I'm tried many variations on the rules suggested on the Dreamhost wiki page I linked to above.

#2 -ASO- Tim

-ASO- Tim

    Former Head Orange

  • Members
  • PipPipPipPipPipPipPip
  • 5,239 posts

Posted 23 November 2005 - 07:16 PM

Pretty useful information. I'll pin this for others to see. Thanks, Waylan!
Former Owner/Manager
timdorr.com

#3 Waylan

Waylan

    Small Orange

  • Members
  • PipPip
  • 26 posts

Posted 25 November 2005 - 11:46 PM

You may have noted that after logging out of your shell, when you log back in, the PATH and PYTHONPATH vars lose the extra values pointing to your project. To get django-admin.py to work, you have to re-export the values. To avoid this, edit ~/.bash_profile and add the following 2 lines to the end:
CODE
export PATH=$PATH:$HOME/django_src/django/bin
export PYTHONPATH=$PYTHONPATH:$HOME/django_src:$HOME/django_projects

Now, whenever you log back in, the values will be set automaticly and you can go to work.

#4 Coppertone Studios Photography

Coppertone Studios Photography

    Small Orange

  • Members
  • PipPip
  • 11 posts

Posted 27 December 2005 - 05:11 PM




Any luck on the rewrite bit?

#5 Waylan

Waylan

    Small Orange

  • Members
  • PipPip
  • 26 posts

Posted 28 December 2005 - 01:46 PM

QUOTE(Coppertone Studios Photography @ Dec 27 2005, 5:11 PM) View Post

Any luck on the rewrite bit?


Actually, it occured to me after posting, that the problem was that I didn't have any apps in my project. As I understand it, Django should be returning the HTTP Responce headers according to the url mod-rewrite passes to it. Seeing that http://yourdomain.com/myproject/django.fcgi/ works fine (I get a welcome page) but nothing else does (remember the admin needs to be activated - which I did not do), I think thats the problem. After all, Unfortunetly, my time has been consumed with higher priorities so I haven't played with it further.

I suggest using the rewrite rules suggested on the Dreamhost page I linked to and installing an app. Let me know how it goes.

#6 Poromenos

Poromenos

    Small Orange

  • Members
  • PipPip
  • 17 posts

Posted 16 January 2006 - 09:20 PM

Django is working sad.gif
http://django.poromenos.org

I am using a shared host, and I am THIS <--> close to not wanting to ever see the name Django again. I was going to tell you how I did it but I am too exhausted. Ask me later.

#7 Waylan

Waylan

    Small Orange

  • Members
  • PipPip
  • 26 posts

Posted 22 January 2006 - 10:28 PM

QUOTE(Poromenos @ Jan 16 2006, 9:20 PM) View Post

Django is working sad.gif
http://django.poromenos.org

I am using a shared host, and I am THIS <--> close to not wanting to ever see the name Django again. I was going to tell you how I did it but I am too exhausted. Ask me later.

Please, do tell.

#8 Poromenos

Poromenos

    Small Orange

  • Members
  • PipPip
  • 17 posts

Posted 23 January 2006 - 12:09 PM

Ah yes, sorry. Basically, you follow the instructions at Dreamhost, but with a few twists that almost drove me mad. First and foremost, before I forget, make sure that your files have 2-3 empty lines at the end. I was frustrated for an hour before I thought to try that, when my page wasn't working.

Where the guide says /home/username/django.mydomain.com is just the (publicly accessible) directory where you want django to reside. Put the fcgi script there. Where it says "myproject.settings" use the format "projectname/settings". I don't know if this is the folder or the module (I think it's the folder), but it works.

My urls.py file looks like this:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
     (r'^$', 'poromenos.default.views.index'),
     (r'^admin/', include('django.contrib.admin.urls.admin')),
)

Somehow it took me quite a few tries to make this to work. My MEDIA_URL is the url of my django site (http://django.poromenos.org/) and the ADMIN_MEDIA_PREFIX is "/media/". ROOT_URLCONF is 'poromenos.urls'
(my project name is poromenos) and INSTALLED_APPS are

INSTALLED_APPS = (
    "django.contrib.admin",
    "poromenos.default",
)

Ask here if you can't make something work.

#9 twaddler

twaddler

    Tiny Orange

  • Members
  • Pip
  • 2 posts

Posted 10 February 2006 - 02:34 PM

When I followed the above instructions I got the error that the python mysqldb module which Django uses for mysql connection is not installed.

Atleast not on the server I am on. So do not expect Django to work with mysql as simple as this. unsure.gif

Wonder what db option Poromenos use.

#10 jaseone

jaseone

    Massive Orange

  • Members
  • PipPipPipPipPipPipPip
  • 2,193 posts

Posted 10 February 2006 - 02:43 PM

Just raise a support ticket to have the module installed.
Jason Bainbridge
An Aussie geek stuck in Texas
Road Show Blondes - Follow the Road Show as we drive from Houston to New York City to raise awareness and money for suicide prevention with The Jed Foundation.

#11 Poromenos

Poromenos

    Small Orange

  • Members
  • PipPip
  • 17 posts

Posted 10 February 2006 - 04:14 PM

I'm using the "mysql" setting and it's working, but I don't remember if I've actually created any databases in my projects, so I can't help you there. The overall installation works though, as you can see.

#12 twaddler

twaddler

    Tiny Orange

  • Members
  • Pip
  • 2 posts

Posted 11 February 2006 - 08:12 AM

The nice people here at asmallorange installed mysql-python at request - this I am very thanksful for. It seems I should have asked for mysql-python with a version 1.1 or above since 1.0 doesn't support mysql 4.1 smile.gif

Be careful of what you ask for, you might get it.

This line creates django db tables:
django-admin.py init --settings=myproject.settings

Poromenos: so yes you created some tables

EDIT: got this response - so it doesn't seem to with the mysql-python version either - but my core still dumps.
We have version MySQL-python-1.0.0-1 which is compatable with mysql 4.1. Are you having problems?

If I get this to work I will post more.

Edited by twaddler, 11 February 2006 - 09:03 AM.


#13 Hero Lint

Hero Lint

    Tiny Orange

  • Members
  • Pip
  • 1 posts

Posted 13 February 2006 - 12:03 AM

Just a dumb question:  Why are you trying to use Django with fcgi?  Doesn't A Small Orange support mod_python?  Django is the easiest thing in the world to set up with mod_python, but it is a pain in the butt with fcgi, I think.

There does seem to be a problem with some Apache setups that causes mod_php and mod_python to conflict.  Is that the issue here?

Just curious.

Edited by Hero Lint, 13 February 2006 - 12:04 AM.


#14 Poromenos

Poromenos

    Small Orange

  • Members
  • PipPip
  • 17 posts

Posted 13 February 2006 - 05:58 AM

Nope, sadly it doesn't :/

#15 kemical

kemical

    Small Orange

  • Members
  • PipPip
  • 33 posts

Posted 05 April 2006 - 10:47 PM

after several attempts looks like django on shared hosting is more trouble than its worth sad.gif and without having access to the rewrite rules everything needs to be passed through the fast cgi script bleh tongue.gif
adam stokes, pimp extraordinare.

#16 Poromenos

Poromenos

    Small Orange

  • Members
  • PipPip
  • 17 posts

Posted 06 April 2006 - 03:15 AM

Why don't you have access to the rewrite rules?

#17 kemical

kemical

    Small Orange

  • Members
  • PipPip
  • 33 posts

Posted 06 April 2006 - 07:20 AM

ah .htaccess file shows ive never used rewrite rules before tongue.gif


@poromenos

Using your urls.py setup :

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^$','imbored.default.views.index'),
     (r'^admin/', include('django.contrib.admin.urls.admin')),
)

Im getting "Could not import imbored.default.views. Error was: No module named default.views"

any ideas?

Edited by kemical, 06 April 2006 - 07:33 AM.

adam stokes, pimp extraordinare.

#18 Poromenos

Poromenos

    Small Orange

  • Members
  • PipPip
  • 17 posts

Posted 06 April 2006 - 12:27 PM

Eh, no idea sad.gif I'm not a Django expert, I was just able to set it up sad.gif.

#19 patrickj

patrickj

    Small Orange

  • Members
  • PipPip
  • 28 posts

Posted 15 May 2006 - 12:06 AM

alright this all sounds sort of easy, but one main question, how do I get a shell on a shared server?

#20 Waylan

Waylan

    Small Orange

  • Members
  • PipPip
  • 26 posts

Posted 15 May 2006 - 11:42 AM

QUOTE(patrickj @ May 15 2006, 1:06 AM) View Post

alright this all sounds sort of easy, but one main question, how do I get a shell on a shared server?


Submit a ticket.

I also suggest you aviod the java applet available from the CPanel and use a terminal app like putty.

Edited by Waylan, 15 May 2006 - 11:47 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users