Friday, June 28, 2013

Re: configure apache for shared hosting using fcgi

please take steps bellow, for understand what is going on.

for run django app on shared host
where we have apache2 and fcgi module installed
like hostgator.com

step 01 - create symbolic link for static (css, img, js) 
========================================================

1.1 if in your provider there is a 
/usr/local/lib/pythonx.y/dist-packages/django/contrib/admin/static

try

ex a: 

ln -s /usr/local/lib/pythonx.y/dist-packages/django/contrib/admin/static /home/your-user/public_html/static

or use your own instaled version of python/django static files

ex b:
 
ln -s /home/your-user/django/v16a1/django/contrib/admin/static /home/your-user/public_html/static


this solve style,css etc for admin app of django


step 02 - .htacces for directory main app http
==============================================

folder ex:  /home/your-user/public_html/rundjango/
what url is: http://your-url-dot/rundjango/admin

AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]


step 03 - index.fcgi (like index.html or index.php)
===================================================

because we use pytz (for handle datetime) it is installed with "easy_install pytz",
so it may be declared on sys.path.

this is my index.fcgi 
after creation you may chmod +x index.fcgi for allow run mode

#!/usr/local/bin/python

import sys, os, user
sys.path.insert(0, "/home/your-user/mycode/mysite")
sys.path.insert(0, "/home/your-user/python/pytz-2013b-py2.6.egg")


# Switch to the directory of your project.
os.chdir("/home/your-user/mycode/mysite")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "mysite.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")


step 04 - verify environment vars $PATH and $PYTHONPATH
=======================================================

this .bash_profile config your env setup when you login
or your apps runs (ex. apache2, etc)
verify that your PYTHONPATH is correct setup
in this case we could use some different python version
that one is default (ex. 2.6, 2.7, 3.2)

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$HOME/bin:$HOME/my-other-app-dir:$PATH
PYTHONPATH=$HOME/python
export PYTHONPATH
export PATH



step 05 - verify if your env is ok
==================================

please logout and login for verify your env var is ok

issue this commands:

echo $PATH
echo $PYTHONPATH

run this small codes of python for verification

python 



>>> import sys
>>> for whatlocal in sys.path:
...  print whatlocal
... 

Be Happy!

Em quinta-feira, 27 de junho de 2013 07h06min50s UTC-3, Sheila escreveu:
Following the django book https://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache I am trying to deploy my project on shared host. 
To try it first I am using a virtual Ubuntu 10.04 server. In my server user can access http://localhost/~USER/ and if I put any html in /home/user/public_html it can be access. 
But the method in the book using .htacess and fastcgi do not work. I am suspecting that my apache2 configuration is wrong. 
Can someone tell me what do I need to change in my apache2 configuration to set up share hosting?? I am new to apache2 :(

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment