Re: Trouble setting up Django and Apache
Hi Ben, On Sun, 2007-03-25 at 14:23 -0700, benrawk wrote: > Hello all, > > With Graham's hint about possible problems caused by SELinux, I > finally figured out what was going on. Django can now serve pages! > Here is what I learned: Firstly, well done for sticking at solving the problem rather than just turning off the SELinux infrastructure. Writing up your conclusions is bound to help other people, too. > SELinux is installed and running by default on Fedora Core 6. This > means that along with the correct file permissions, for files to be > readable by apache they have to have the correct security context. > When you first set up Apache and serve a simple html page from '/var/ > www' there is no problem because SELinux has by default already given > this path the correct security context. When you start creating > projects in Django using the 'django-admin.py startproject [project > name]' files are created that do not have the correct security > context. > > Default security contexts are controlled by files in '/etc/selinux/ > targeted/contexts/files'. If you grep for 'www' in this directory you > will see that '/var/www(/.*)?' has been given the correct security > context, as previously described. Interestingly, directories labeled > 'www' under you home directory will also be given the correct security > context by defaule because of the following regx '/home/[^/]*/((www)| > (web)|(public_html))(/.+)? '. > > Looking at the security conext of files under the /var/www directory > (using 'ls -Z'), I found that files should have the following context > inorder to be served up by Apache: > 'system_u:object_r:httpd_sys_content_t'. This is compared to what my > Django files currently had: 'user_u:object_r:user_home_t'. I had to > change the type of the files, and I did so using the following > command: > > chcon -R -t httpd_used_content_t myproject > > My knowledge of SELinux configuration is still pretty low, and I will > continue to study it if I run into more problems. The references I > used to figure this all out are here: > > http://linux.web.cern.ch/linux/scientific4/docs/rhel-selg-en-4/rhlcommon-chapter-0017.html#RHLCOMMON-SECTION-0066 > http://docs.fedoraproject.org/selinux-apache-fc3/sn-simple-setup.html I'm fairly comfortable with SELinux systems and, for what it's worth, your explanation of the problems, why it isn't a problem for /var/www/ and your solution seem exactly right to me. Nice debugging job. :-) I don't have FC6 installed, but often these systems log access violations to /var/log/secure (or another place), so you might have been able to see a bunch of failures in there. On SELinux-enabled systems, if something isn't working, it's often worth seeing if /var/log/secure is growing or being updated each time you make an attempt (you can run "ls -lrt /var/log/" without being root on many systems, whereas you can't view the file without changing to a more privileged user). Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
Hello all, With Graham's hint about possible problems caused by SELinux, I finally figured out what was going on. Django can now serve pages! Here is what I learned: SELinux is installed and running by default on Fedora Core 6. This means that along with the correct file permissions, for files to be readable by apache they have to have the correct security context. When you first set up Apache and serve a simple html page from '/var/ www' there is no problem because SELinux has by default already given this path the correct security context. When you start creating projects in Django using the 'django-admin.py startproject [project name]' files are created that do not have the correct security context. Default security contexts are controlled by files in '/etc/selinux/ targeted/contexts/files'. If you grep for 'www' in this directory you will see that '/var/www(/.*)?' has been given the correct security context, as previously described. Interestingly, directories labeled 'www' under you home directory will also be given the correct security context by defaule because of the following regx '/home/[^/]*/((www)| (web)|(public_html))(/.+)? '. Looking at the security conext of files under the /var/www directory (using 'ls -Z'), I found that files should have the following context inorder to be served up by Apache: 'system_u:object_r:httpd_sys_content_t'. This is compared to what my Django files currently had: 'user_u:object_r:user_home_t'. I had to change the type of the files, and I did so using the following command: chcon -R -t httpd_used_content_t myproject My knowledge of SELinux configuration is still pretty low, and I will continue to study it if I run into more problems. The references I used to figure this all out are here: http://linux.web.cern.ch/linux/scientific4/docs/rhel-selg-en-4/rhlcommon-chapter-0017.html#RHLCOMMON-SECTION-0066 http://docs.fedoraproject.org/selinux-apache-fc3/sn-simple-setup.html On Mar 23, 2:30 am, "Graham Dumpleton" <[EMAIL PROTECTED]> wrote: > On Mar 23, 6:47 pm, "benrawk" <[EMAIL PROTECTED]> wrote: > > > Thank you again for helping. FYI, I am using Fedora Core 6. I set > > 'PythonHandlermod_python.testhandler' in httpd.conf and got a bunch > > of info. The sys.path appears to be correct...relevant bits, and then > > full text beneath. > > > sys.path containes /home/benrawk > > What is the full path to the directory that Django admin project > created. Is it: > > /home/benrawk/mysite > > What is the output of running: > > ls -las > > inside of that directory. Are all the files in that directory readable > to others. > > > REQUEST_URI /mysite/ > > SCRIPT_NAME /mysite > > PATH_INFO / > > PATH_TRANSLATED /var/www/html/index.html > > ***Is this Path being translated correctly?*** > > That is normal in this case. Because the request was against the > directory Apache tried applying targets listed in DirectoryIndex > directive and first one listed was probably 'index.html'. > > > DOCUMENT_ROOT /var/www/html > > SCRIPT_FILENAME /var/www/html/mysite > > ***There is no "mysite" script under the Document root, is this being > > interpreted correctly?*** > > Nothing to worry about, just part of Apache's strange URL matching > algorithm which is made somewhat more confusing by presence of > mod_python. > > Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
On Mar 23, 6:47 pm, "benrawk" <[EMAIL PROTECTED]> wrote: > Thank you again for helping. FYI, I am using Fedora Core 6. I set > 'PythonHandlermod_python.testhandler' in httpd.conf and got a bunch > of info. The sys.path appears to be correct...relevant bits, and then > full text beneath. > > sys.path containes /home/benrawk What is the full path to the directory that Django admin project created. Is it: /home/benrawk/mysite What is the output of running: ls -las inside of that directory. Are all the files in that directory readable to others. > REQUEST_URI /mysite/ > SCRIPT_NAME /mysite > PATH_INFO / > PATH_TRANSLATED /var/www/html/index.html > ***Is this Path being translated correctly?*** That is normal in this case. Because the request was against the directory Apache tried applying targets listed in DirectoryIndex directive and first one listed was probably 'index.html'. > DOCUMENT_ROOT /var/www/html > SCRIPT_FILENAME /var/www/html/mysite > ***There is no "mysite" script under the Document root, is this being > interpreted correctly?*** Nothing to worry about, just part of Apache's strange URL matching algorithm which is made somewhat more confusing by presence of mod_python. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
Thank you again for helping. FYI, I am using Fedora Core 6. I set 'PythonHandler mod_python.testhandler' in httpd.conf and got a bunch of info. The sys.path appears to be correct...relevant bits, and then full text beneath. sys.path containes /home/benrawk REQUEST_URI /mysite/ SCRIPT_NAME /mysite PATH_INFO / PATH_TRANSLATED /var/www/html/index.html ***Is this Path being translated correctly?*** DOCUMENT_ROOT /var/www/html SCRIPT_FILENAME /var/www/html/mysite ***There is no "mysite" script under the Document root, is this being interpreted correctly?*** ***FULL TEXT* Apache version Apache/2.2.3 (Fedora) Apache threaded MPM No (single thread MPM) Apache forked MPM Yes, maximum 256 processes Apache server root /etc/httpd Apache document root/var/www/html Apache error log/etc/httpd/logs/error_log (view last 100 lines) Python sys.version 2.4.4 (#1, Oct 23 2006, 13:58:00) [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] Python sys.path: /home/benrawk /usr/lib/python2.4/site-packages/setuptools-0.6c1-py2.4.egg /usr/lib/python2.4/site-packages/Django-0.95.1-py2.4.egg /usr/lib/python24.zip /usr/lib/python2.4 /usr/lib/python2.4/plat-linux2 /usr/lib/python2.4/lib-tk /usr/lib/python2.4/lib-dynload /usr/lib/python2.4/site-packages /usr/lib/python2.4/site-packages/Numeric /usr/lib/python2.4/site-packages/gtk-2.0 Python interpreter name www.benrawk.com mod_python.publisher available Yes mod_python.psp availableYes DJANGO_SETTINGS_MODULE mysite.settings GATEWAY_INTERFACE CGI/1.1 SERVER_PROTOCOL HTTP/1.1 REQUEST_METHOD GET QUERY_STRING REQUEST_URI /mysite/ SCRIPT_NAME /mysite PATH_INFO / PATH_TRANSLATED /var/www/html/index.html HTTP_HOST localhost HTTP_USER_AGENT Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.9) Gecko/20061219 Fedora/1.5.0.9-1.fc6 Firefox/1.5.0.9 pango-text HTTP_ACCEPT text/xml,application/xml,application/xhtml+xml,text/ html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_LANGUAGEen-us,en;q=0.5 HTTP_ACCEPT_ENCODINGgzip,deflate HTTP_ACCEPT_CHARSET ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_KEEP_ALIVE 300 HTTP_CONNECTION keep-alive HTTP_CACHE_CONTROL max-age=0 PATH/sbin:/usr/sbin:/bin:/usr/bin SERVER_SIGNATURE Apache/2.2.3 (Fedora) Server at localhost Port 80 SERVER_SOFTWARE Apache/2.2.3 (Fedora) SERVER_NAME localhost SERVER_ADDR ::1 SERVER_PORT 80 REMOTE_ADDR ::1 DOCUMENT_ROOT /var/www/html SCRIPT_FILENAME /var/www/html/mysite REMOTE_PORT 39639 On Mar 22, 10:42 pm, "Graham Dumpleton" <[EMAIL PROTECTED]> wrote: > On Mar 23, 2:49 pm, "benrawk" <[EMAIL PROTECTED]> wrote: > > > Also, when I import and print sys.path into a python session, with > > apache running in the background, sys.path does not include '/home/ > > benrawk'. Is it supposed to? Is there a way I can check the value of > > PythonPath as it is defined in httpd.conf? > > Presuming you are using a recent version of mod_python, change your > PythonHandler directive to: > > PythonHandler mod_python.testhandler > > The result of accessing stuff under /mysite will then be a big page of > information about the request and the environment of Python > interpreter being used. One of the things will be sys.path and you can > then verify it is what you expect. > > BTW, what OS are you using. Are you perhaps using one of the SELinux > enabled variants? These systems can put extra access controls on top > of normal stuff when using Apache such that it may not be enough for > files to be readable by Apache. I don't understand the full > implications of using SELinux or how to set it up but it may be an > issue if you are using it so be clear in stating what environment you > are using. > > Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
On Mar 23, 2:49 pm, "benrawk" <[EMAIL PROTECTED]> wrote: > Also, when I import and print sys.path into a python session, with > apache running in the background, sys.path does not include '/home/ > benrawk'. Is it supposed to? Is there a way I can check the value of > PythonPath as it is defined in httpd.conf? Presuming you are using a recent version of mod_python, change your PythonHandler directive to: PythonHandler mod_python.testhandler The result of accessing stuff under /mysite will then be a big page of information about the request and the environment of Python interpreter being used. One of the things will be sys.path and you can then verify it is what you expect. BTW, what OS are you using. Are you perhaps using one of the SELinux enabled variants? These systems can put extra access controls on top of normal stuff when using Apache such that it may not be enough for files to be readable by Apache. I don't understand the full implications of using SELinux or how to set it up but it may be an issue if you are using it so be clear in stating what environment you are using. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
On Fri, 2007-03-23 at 03:49 +, benrawk wrote: > Also, when I import and print sys.path into a python session, with > apache running in the background, sys.path does not include '/home/ > benrawk'. Is it supposed to? No, they are different processes. Apache will only adjust sys.path for the python interpreter(s) it is starting. > Is there a way I can check the value of > PythonPath as it is defined in httpd.conf? Open up the file django/core/handlers/modpython.py and put in something like print >> sys.stderr, sys.path in a piece of code that is going to be executed. You can see from your traceback that line 163 of that file is executed, so try putting the output just before that. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
I don't know if it's an encouraged practice, but I established a symbolic link to my app folder in site-packages which ensures that the app is in the python path. Until I did that I received the same error from apache as you have. On Mar 22, 10:49 pm, "benrawk" <[EMAIL PROTECTED]> wrote: > Also, when I import and print sys.path into a python session, with > apache running in the background, sys.path does not include '/home/ > benrawk'. Is it supposed to? Is there a way I can check the value of > PythonPath as it is defined in httpd.conf? > > On Mar 22, 8:37 pm, "benrawk" <[EMAIL PROTECTED]> wrote: > > > Hello, thank your for your reply. Tried everything, getting positive > > results, but still can't loadhttp://localhost/mysite/. > > > 1) permissions on both /home, /home/benrawk, and /home/benrawk/mysite > > are 'drwxr-xr-x' > > > 2) I succesfully imported mysite.settings after adding /home/benrawk > > to the sys.path. > > > 3) mysite/ has __init__.py in it. > > > Any other ideas? Would really like to get this to work...any help is > > greatly appreciated. > > > On Mar 22, 1:02 am, Malcolm Tredinnick <[EMAIL PROTECTED]> > > wrote: > > > > On Thu, 2007-03-22 at 07:57 +,benrawkwrote: > > > > Hello, > > > > > Recieving a common error, but have trolled the message boards, and > > > > have not found a solution. My httpd.conf file contains the following > > > > relevant snippet: > > > > > > > > > SetHandler python-program > > > > PythonPath "['/home/benrawk'] + sys.path" > > > > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > > > > PythonHandler django.core.handlers.modpython > > > > PythonDebug On > > > > Allow from localhost > > > > > > > > > The path of my project file with settings.py in it is /home/benrawk/ > > > > mysite. > > > > Is /home/benrawkreadable by the user running Apache (typically, > > > "apache")? Similarly is mysite/ readable by that user? > > > > Does your settings.py file have syntax errors in it? If you start a > > > python prompt, import sys and add /home/benrawkto the front of > > > sys.path, can you import mysite.settings without error? > > > > Does mysite/ have an __init__.py file in it? Actually, this is a > > > redundant question if you passed the previous test, but it might explain > > > why the import failed if you can't even import it from the command line. > > > > Those are the likely causes of problems: apache can't read the files in > > > question, or settings.py has syntax errors. > > > > Regards, > > > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
Also, when I import and print sys.path into a python session, with apache running in the background, sys.path does not include '/home/ benrawk'. Is it supposed to? Is there a way I can check the value of PythonPath as it is defined in httpd.conf? On Mar 22, 8:37 pm, "benrawk" <[EMAIL PROTECTED]> wrote: > Hello, thank your for your reply. Tried everything, getting positive > results, but still can't loadhttp://localhost/mysite/. > > 1) permissions on both /home, /home/benrawk, and /home/benrawk/mysite > are 'drwxr-xr-x' > > 2) I succesfully imported mysite.settings after adding /home/benrawk > to the sys.path. > > 3) mysite/ has __init__.py in it. > > Any other ideas? Would really like to get this to work...any help is > greatly appreciated. > > On Mar 22, 1:02 am, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > On Thu, 2007-03-22 at 07:57 +,benrawkwrote: > > > Hello, > > > > Recieving a common error, but have trolled the message boards, and > > > have not found a solution. My httpd.conf file contains the following > > > relevant snippet: > > > > > > > SetHandler python-program > > > PythonPath "['/home/benrawk'] + sys.path" > > > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > > > PythonHandler django.core.handlers.modpython > > > PythonDebug On > > > Allow from localhost > > > > > > > The path of my project file with settings.py in it is /home/benrawk/ > > > mysite. > > > Is /home/benrawkreadable by the user running Apache (typically, > > "apache")? Similarly is mysite/ readable by that user? > > > Does your settings.py file have syntax errors in it? If you start a > > python prompt, import sys and add /home/benrawkto the front of > > sys.path, can you import mysite.settings without error? > > > Does mysite/ have an __init__.py file in it? Actually, this is a > > redundant question if you passed the previous test, but it might explain > > why the import failed if you can't even import it from the command line. > > > Those are the likely causes of problems: apache can't read the files in > > question, or settings.py has syntax errors. > > > Regards, > > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
Hello, thank your for your reply. Tried everything, getting positive results, but still can't load http://localhost/mysite/. 1) permissions on both /home, /home/benrawk, and /home/benrawk/mysite are 'drwxr-xr-x' 2) I succesfully imported mysite.settings after adding /home/benrawk to the sys.path. 3) mysite/ has __init__.py in it. Any other ideas? Would really like to get this to work...any help is greatly appreciated. On Mar 22, 1:02 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2007-03-22 at 07:57 +,benrawkwrote: > > Hello, > > > Recieving a common error, but have trolled the message boards, and > > have not found a solution. My httpd.conf file contains the following > > relevant snippet: > > > > > SetHandler python-program > > PythonPath "['/home/benrawk'] + sys.path" > > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > > PythonHandler django.core.handlers.modpython > > PythonDebug On > > Allow from localhost > > > > > The path of my project file with settings.py in it is /home/benrawk/ > > mysite. > > Is /home/benrawkreadable by the user running Apache (typically, > "apache")? Similarly is mysite/ readable by that user? > > Does your settings.py file have syntax errors in it? If you start a > python prompt, import sys and add /home/benrawkto the front of > sys.path, can you import mysite.settings without error? > > Does mysite/ have an __init__.py file in it? Actually, this is a > redundant question if you passed the previous test, but it might explain > why the import failed if you can't even import it from the command line. > > Those are the likely causes of problems: apache can't read the files in > question, or settings.py has syntax errors. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Trouble setting up Django and Apache
On Thu, 2007-03-22 at 07:57 +, benrawk wrote: > Hello, > > Recieving a common error, but have trolled the message boards, and > have not found a solution. My httpd.conf file contains the following > relevant snippet: > > > SetHandler python-program > PythonPath "['/home/benrawk'] + sys.path" > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > PythonHandler django.core.handlers.modpython > PythonDebug On > Allow from localhost > > > The path of my project file with settings.py in it is /home/benrawk/ > mysite. Is /home/benrawk readable by the user running Apache (typically, "apache")? Similarly is mysite/ readable by that user? Does your settings.py file have syntax errors in it? If you start a python prompt, import sys and add /home/benrawk to the front of sys.path, can you import mysite.settings without error? Does mysite/ have an __init__.py file in it? Actually, this is a redundant question if you passed the previous test, but it might explain why the import failed if you can't even import it from the command line. Those are the likely causes of problems: apache can't read the files in question, or settings.py has syntax errors. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---