Django-无法在settings.py中创建目录-Apache2

时间:2018-10-11 10:06:04

标签: django apache2 centos7

我致力于将生产方式设置为Django网站。 我被我的settings.py困在了创建文件夹的错误权限中。

我无法在settings.py中创建目录...为什么? =(

错误日志

(我删除了无用的信息)

 mod_wsgi (pid=440685): Failed to exec Python script file '/PATHMYSITE/wsgi.py'.
 mod_wsgi (pid=440685): Exception occurred processing WSGI script '/PATHMYSITE/wsgi.py'.
 Traceback (most recent call last):
   File "/PATHMYSITE/wsgi.py", line 21, in <module>
     application = get_wsgi_application()
   File "/PATHMYENV/lib64/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
     django.setup(set_prefix=False)
   File "/PATHMYENV/lib64/python3.6/site-packages/django/__init__.py", line 19, in setup
     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
   File "/PATHMYENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
     self._setup(name)
   File "/PATHMYENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
     self._wrapped = Settings(settings_module)
   File "/PATHMYENV/lib64/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
     mod = importlib.import_module(self.SETTINGS_MODULE)
   File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
   File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
   File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
   File "/PATHMYSITE/MYSITE/__init__.py", line 5, in <module>
      from .settings import DEBUG
   File "/PATHMYSITE/MYSITE/settings.py", line 333, in <module>
      os.mkdir(FILE_UPLOAD_TEMP_DIR)
PermissionError: [Errno 13] Permission denied: '/PATHMYSITE/media/tmp'

Django“ settings.py”

#### many things ######

FILE_UPLOAD_TEMP_DIR = os.path.join(MEDIA_ROOT, "tmp")

if not os.path.exists(FILE_UPLOAD_TEMP_DIR):
    os.mkdir(FILE_UPLOAD_TEMP_DIR)

Apache Httpd“ django.conf”

LoadModule wsgi_module /PATHMYENV/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so

CustomLog logs/MYSITE-access_log common
ErrorLog logs/MYSITE-error_log


#<VirtualHost *:80>


        # ServerName www.DNS.com:80

        WSGIDaemonProcess MYSITE python-home=/PATHMYENV python-path=/PATHMYSITE
        WSGIProcessGroup MYSITE

        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptAlias / /PATHMYSITE/MYSITE/wsgi.py

        Alias /static/ /PATHMYSITE/static/
        <Directory /PATHMYSITE/static>
                Require all granted
        </Directory>

        <Directory /PATHMYSITE>
                Require all granted
        </Directory>

        <Directory /PATHMYSITE/MYSITE>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

#</VirtualHost>

编辑1-权限SITE文件夹

[ME@web PATHTOMYPARENTFOLDERSITE]$ ls -Z 
drwxrwxr-x. apache  apache  unconfined_u:object_r:httpd_sys_content_t:s0 MYSITE
drwxr-xr-x. apache  apache  unconfined_u:object_r:httpd_sys_rw_content_t:s0 MYENV

2 个答案:

答案 0 :(得分:0)

将docroot所在目录的所有权更改为运行apache的用户。如果您与“ apache2”用户一起运行apache,请执行以下操作

# chown -R apache2:apache /PATHMYSITE/MYSITE/

然后重新启动

# service apache2 restart

答案 1 :(得分:0)

使用以下命令行通过Manish R的注释来解决:

sudo setenforce Permissive

它关闭SELinux。