So I am going to talk about what I needed to do get the lastest django (1.4) working on site5.
1. Lets setup our little sandbox area for placing the source to compile and the actually compiled instance
cd ~
mkdir installed
cd installed
mkdir compile
cd compile
2. Download Python 2.7 (Currently django doesn't work with python 3)
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar -xvf Python-2.7.3.tar.bz2
Note: This is specific for version 2.7.3 which was the stable release at the time this article was written, but in theory this should work with any future releases as well.
3. Compiling and install Python 2.7 (non root user)
cd Python-2.7.3
./configure PREFIX=
make install DESTDIR=/home/<username>/installed/python2.7
4. Add python to the PATH for simplicity, to do this we will add an entry to the .bash_profile file located in our home directory
cd ~
vim .bash_profile
add $HOME/installed/pythong2.7/bin to the PATH defined in .bash_profile
PATH=$HOME/installed/python2.7/bin:$PATH
export PATH
5. Reload the .bash_profile so that python will be on the path.
source .bash_profile
6. Verify that the new python is found in the path
python --version
(should print Python 2.7.3)
7. Install PIP (I followed instructions found here)
cd ~/installed/compile
curl http://python-distribute.org/distribute_setup.py | python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
*Note if the last command fails with certificate issue, run with curl -k
8. Install django using pip
pip install django
pip install flup
pip install pysqlite (only sometimes required and only if you are doing sqlite db)
9. Create directory for website and add necessary files to get apache to pick it up
.htaccess
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(static/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(django.fcgi)
RewriteRule ^(.*)$ django.fcgi/$1 [L]
django.fcgi
#!/home/<username>/installed/python2.7/bin/python
import sys, os
# Add a custom Python path.
sys.path.insert(0, "/home/<username>/<website-location>")
# Switch to the directory of your project. (Optional.)
#os.chdir("/home/<username>/<website-location>")
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "<projectname>.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
So hopefully after following this little tutorial, you too can get the newest version of django up and running on a hosted machine with no root access ;-)
hey...! i think i wrote you a comment a while ago, and i know this is a long shot... but i have thanks to this tutorial managed to finally setup django as non root! :) so thank you so much for that! the last part is setting up the fcgi re-rooting... i managed to setup normal cgi and it works fully, but it is unbelievably slow... i keep getting 404 errors or 500 apache errors with trying the .htaccess file and .fcgi file here in this tutorial...
ReplyDelete