Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In my site2 Django application Apache wsgi don't have writing access for files in /var/www/site2, even if:

I have chown-ed to apache all files from /var/www/site2 directory I give all rights (chmod -R 777). and SELinux is disabled.

Below is a briefing state:

[root@nuc www]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov 19 2015 21:43:13

[root@nuc www]# ls -l
total 4
drwxr-xr-x. 2 root   root      6 Nov 19 23:43 cgi-bin
drwxr-xr-x. 2 root   root      6 Apr  2 15:02 html
drwxrwxrwx. 6 apache apache 4096 Apr  3 16:14 site2

[root@nuc site2]# ls -l
...
drwxrwxrwx. 5 apache apache  4096 Apr  2 15:23 blog
-rwxrwxrwx. 1 apache apache 95232 Apr  3 16:09 db.sqlite3
drwxrwxrwx. 5 apache apache  4096 Apr  2 16:54 home
-rwxrwxrwx. 1 apache apache   248 Mar 19 13:56 manage.py
drwxrwxrwx. 5 apache apache  4096 Apr  3 16:13 pock
drwxrwxrwx. 2 apache apache  4096 Apr  3 14:45 site2


[root@nuc www]# sestatus
SELinux status:                 disabled

httpd.conf ...
#-------------------------------------------------
WSGIScriptAlias / /var/www/site2/site2/wsgi.py
WSGIPythonPath /var/www/site2/

Alias /static/ /var/www/site2/blog/static/
Alias /static2/ /var/www/site2/home/static/
Alias /static3/ /var/www/site2/pock/static/

<Directory /var/www/site2/blog/static/>
Require all granted
</Directory>
<Directory /var/www/site2/home/static/>
Require all granted
</Directory>
<Directory /var/www/site2/pock/static/>
Require all granted
</Directory>

<Directory /var/www/site2/site2/>
<Files wsgi.py>
#Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
#-------------------------------------------------

And still in /var/log/httpd/error_log:

[Sun Apr 03 13:43:17.389404 2016] [:error] [pid 4753] /var/www/site2
[Sun Apr 03 13:43:17.390560 2016] [:error] [pid 4753] Internal Server Error: /pock/test/
[Sun Apr 03 13:43:17.390593 2016] [:error] [pid 4753] Traceback (most recent call last):
[Sun Apr 03 13:43:17.390602 2016] [:error] [pid 4753]   File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
[Sun Apr 03 13:43:17.390609 2016] [:error] [pid 4753]     response = self.process_exception_by_middleware(e, request)
[Sun Apr 03 13:43:17.390634 2016] [:error] [pid 4753]   File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
[Sun Apr 03 13:43:17.390643 2016] [:error] [pid 4753]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Sun Apr 03 13:43:17.390650 2016] [:error] [pid 4753]   File "/var/www/site2/pock/views.py", line 57, in test
[Sun Apr 03 13:43:17.390656 2016] [:error] [pid 4753]     f = open('test.txt', 'w')
[Sun Apr 03 13:43:17.390662 2016] [:error] [pid 4753] IOError: [Errno 13] Permission denied: 'test.txt'

SOLVED

Thanks to suggestions of Volodymyr I did more digging and I find the way finnaly.

Moving project in /home directory was not working for me: getting "Forbidden" from Apache.

The file I was trying to write need absolute path:

f = open('/var/www/site2/test.txt', 'w')

Otherwise wsgi python would try to write it in "/" root file system, so the error above is explained

In the end I did chown -R 744 /var/www/site2 and it worked, writing to files and database.

Seems that I have done other error but, anyway, it works now.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
165 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try to :

chown -R root:apache /Path/To/You/WebSitePackage

I had this problem when deploy Django with httpd on Centos 7. I chose other way : Create WEBSITE Package in home/user/ directory, then

chown -R apache:apache Path/To/WEBSITEPackage
chmod -R 770 Path/To/WEBSITEPackage

After You can try :

chown -R user:root Path/To/WEBSITEPackage
chmod -R 770 Path/To/WEBSITEPackage

chown -R apache:root Path/To/WEBSITEPackage
chmod -R 770 Path/To/WEBSITEPackage

Other words apache on centos 7 need root privelegies


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...