In case you want to use Django framework in Godaddy’s Linux Economy Host, here is the steps:
1. Godaddy has virtualenv installed, so first, create a virtual environment venv: (I use $HOME/lib/ for all the installed stuff below)
cd ~/ mkdir lib cd lib virtualenv --no-site-packages venv
The python package folder is $HOME/lib/venv/lib/python2.7/site-packages
2. Install the latest Django through pip
pip install Django
3. After successfully installed Django 1.4, create a new project
django-admin.py startproject mysite
4. Because Django 1.4 only support MySQLdb 1.2.1 or above, and Godaddy only has 1.2.0, so we cannot use MySQL. Let’s use sqlite for our database
cd mysite sqlite3 mydatabase.db ""
5. change the database configuration in mysite/setting.py file
(1) when set the path for the database file, please use the absolute path
(2) set the Locale information in $HOME/.bash_profile file, otherwise you cannot set the superuser when you sync the database.
export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8
run $HOME/.bash_profile:
% source ~/.bash_profile
(3) now you should sync the database:
% python2.7 manage.py syncdb
There should be no error if you did (2)
6. Now we setup the dispatch functionality so we can access the webpage without running server through Django, we use flup here
cd ~/lib/venv/lib/python2.7/site-packages wget http://pypi.python.org/packages/source/f/flup/flup-1.0.2.tar.gz#md5=24dad7edc5ada31dddd49456ee8d5254 tar -xvzf flup-1.0.2.tar.gz mv flup-1.0.2/flup/ .
And you can delete the flup-1.0.2 folder if you want.
7. in $HOME/html folder, create dispatch.py and add the following codes:
#!/usr/local/bin/python2.7 import sys, os sys.path += ['/your/home/path/lib/venv/lib/python2.7/site-packages'] sys.path += ['/your/home/path/lib/mysite/'] os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' from flup.server.fcgi import WSGIServer from django.core.handlers.wsgi import WSGIHandler WSGIServer(WSGIHandler()).run()
8. in $HOME/html/.htaccess file, add the following codes:
AddHandler fcgid-script .fcgi Options +FollowSymLinks RewriteEngine On RewriteBase / # everything else sent to django RewriteRule ^(dispatch.py/.*)$ - [L] RewriteRule ^(.*)$ dispatch.py/$1 [L]
9. Access your website http://your.website.com, it should work
addtional
1. add static path in mysite/settings.py, so Godaddy host can read the static folder correctly
from django.conf import settings urlpatterns = patterns('', url(r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT, 'show_indexes': True}), #your other url settings )
Important
Don’t forget to set the STATIC_ROOT and run % python2.7 manage collectstatic
first.
Thanks for this – very helpful!
I’m on GoDaddy Linux Deluxe, and this worked for me too. I noticed, though, my python2.7 has MySQLdb 1.2.3, so I was able to use MySQL rather than sqlite. It might be work checking what version you have:
-bash-3.2$ python2.7 -c “import MySQLdb;print MySQLdb.version_info”
(1, 2, 3, ‘final’, 0)
Thanks for letting me know this, I checked mine but it’s MySQLdb 1.2.0…..:)
Hi,
This is really helpful! I get most of the way there, but at the end I get an internal server error and my error log reads:
[Tue Jul 24 19:38:01 2012] [alert] [client 99.38.144.210] /var/chroot/home/content/40/8381440/html/.htaccess: RewriteRule: bad flag delimiters
Do you know what could be causing this? I have set the paths correctly, as far as I can tell.
can you post your .htaccess?
Sure—it is literally what you said should be pasted in. Thanks for looking into this!:
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# everything else sent to django
RewriteRule ^(dispatch.py/.*)$ – [L]
RewriteRule ^(.*)$ dispatch.py/$1 [L]
No worries…I moved to webfactions. Way easier.
Hi i’ve follow your tutorial, but i have problems whit the .htaccess.
Here is the log:
____________________________________
[Tue Aug 28 21:14:05 2012] [error] [client 190.62.242.211] suexec policy violation: see suexec log for more details
[Tue Aug 28 21:14:05 2012] [error] [client 190.62.242.211] Premature end of script headers: dispatch.py
[Tue Aug 28 21:14:06 2012] [error] [client 190.62.242.211] suexec policy violation: see suexec log for more details
[Tue Aug 28 21:14:06 2012] [error] [client 190.62.242.211] Premature end of script headers: dispatch.py
[Tue Aug 28 21:15:59 2012] [error] [client 190.62.242.211] client denied by server configuration: /var/chroot/home/content/55/8736555/html/rascencio/.htaccess
[Tue Aug 28 21:15:59 2012] [error] [client 190.62.242.211] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a back
_____________________________________
[Sun Aug 26 20:21:53 2012] [error] [client 190.150.47.112] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.
[Mon Aug 27 08:40:27 2012] [error] [client 66.249.68.43] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.
___________________________________
This is the (basically your)htaccess:
_____________________________________
Options +execcgi
AddHandler cgi-script .py
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^(dispatch.py/.*)$ – [L]
RewriteRule ^(.*)$ dispatch.py/$1 [L]
__________________________________
– Wihtout the frist two lines i’ve to changue the .py -> .cgi
anyways it dont works 🙁
– Whitout the /* and / after dispath.py it seems to work :D, but just
for the root url, work for r-ascencio.me but not for r-ascencio.me/foo,
but whit the /* and / i got those logs and a beatifully 500
I search about this, but i don’t get any kind of help of anywhere :/
PD: The persmission for the dispatch.py are “755”
I really appreciate any help, and thanks, really for the tutorial 🙂
/*before i have Django 0.96 when i see i could use MySQL 1.2.3*/
/*i think on chague to Django 1.3 and everything works, but i */
/*was working in a project white Django 1.4 and i fall in love*/
/*whit timezones 😐 and think in upgrade and i messed up whit the*/
/*.cgi script and the .htaccess, but more whit the .htaccess the i delete all*/
/*and start over, but i found your tutorial and here i’am*/
/* :|*/
PD3: the_link: http://r-ascencio.me
What comments engine do you use? 😐
sorry, the comment need to approved then it will show up…I read your previous comment, to sum up, the .htaccess works for r-ascencio.me but not for r-ascencio.me/foo right? So you wanna use r-ascencio.me/foo to access your django project?
I want to use r-ascencio.me/ to access to the django project, and r-ascencio.me/foo, r-ascencio.me/foo/bar as well.
Tanks, for the response 🙂
Problem solved i found the old:
http://web.archive.org/web/20100604074527/http://blurback.com/post/563604002/running-django-on-godaddy-sigh
But anyways it just was the way that the .htaccess run the dispatch.cgi
I just delete the regex and it work 😐
One note!!!Set permissions for the dispatch.py on p.7 on executable before it I see only 500 page.
chmod +x on dispatch.py yes
Another good thing to note is that you can ReWrite URLS if you have current applications isntalled, ie.e dokuwiki.
Add this above "everything else sent to django"
#Below other folders with static content and PHP , etc..
#hosted at yourdomain/dokuwiki
RewriteRule ^(dokuwiki/.*)$ – [L]
#You can also create your "django" project at a different location rather than your domain root by changing the 2nd RewriteRule , i.e.:
# everything else sent to django
RewriteRule ^(dispatch.py/.*)$ – [L]
RewriteRule ^(djangoproj/.*)$ dispatch.py/$1 [L]
#Make sure to create the djangoproj folder inside your html dir, cd html; mkdir djangproj
If you’re using economy Linux then MySQL-Python cannot be installed. pip install MySQL-Python will fail with an error that gcc is not found. I don’t think there is a way to install Development Tools since there seems to be no root access and thus you cannot install any system packages. Is there any work around for this?
One last note, the url pattern for the static url should be like this, otherwise it does not work: r’^static/(.*)$’
Went the extra mile and installed django-cms on top! Everything is working correctly and just followed their basic setup guide: http://docs.django-cms.org/en/2.4.0/getting_started/tutorial.html#configuration-and-setup
I was able to get this going :
https://github.com/lawrencecreates/RHEL5-chroot
you can install gcc and all packages in the chroot and sneak it in.
The problem is that you cannot keep any process running long term with fastcgi and that makes the server really bad. We are going to ditch godaddy hosting.
Pingback: Running Django On Godaddy – Cyber Sun