简体   繁体   中英

Permission issue when writing file on webserver (flask, apache & wsgi)

I'm trying to deploy my very first web app and I have no knowledge on this. It's fairly interesting but I feel like I have no idea what I am doing when I try to fix an issue.

I created a server on digital ocean which run on ubuntu 18.04 and I've been fighting with it over the past 2 days in order to make my website run smoothly.

I now feel that the end is near but I am stuck on a permission access issue.

My app is working through flask. I'm using wsgi_mod and apache to run it.

I've put down 2 of the setup file that can help you (I think ?) as well as the error log.

I have also tried to apply the following fix:

sudo chown -R www-data:www-data /var/www/website.com

sudo cmod -R 775 /var/www/website.com

I tried to run the wsgi using the WSGIDaemon process (whatever it is used for it didn't work neither).

Please help me !

Let me know if you need more question.

Many thanks in advance !

Error log:

Traceback (most recent call last):
File "/var/www/website.com/wsgi/website.com.wsgi", line 10, in <module>
    from __init__ import app as application
File "/var/www/website.com/akb/__init__.py", line 19, in <module>
    flask_session.Session(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 5$
    self.init_app(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 6$
    app.session_interface = self._get_interface(app)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/__init__.py", line 9$
    config['SESSION_USE_SIGNER'], config['SESSION_PERMANENT'])
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/flask_session/sessions.py", line 3$
    self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
File "/var/www/website.com/akb/env3.7/lib/python3.6/site-packages/werkzeug/contrib/cache.py", line 7$
    os.makedirs(self._path)
File "/usr/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/flask_session'

/var/www/website/wsgi/website.com.wsgi

#!/var/www/website.com/akb/env3.7/bin/python
# -*- coding: utf-8 -*-

import sys
import logging

logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/website.com/akb")

from __init__ import app as application
application.secret_key = 'iuhAqshdad123_&é"_JIHfduh3i123d!!:'

/etc/apache2/sites-available/website.com.conf:

WSGIPythonHome /var/www/website.com/akb/env3.7

<VirtualHost *:80>
    ServerName website.com
    ServerAdmin website.root@gmail.com
    ServerAlias www.website.com

    DocumentRoot /var/www/website.com/akb
    <Directory /var/www/website.com/akb>
        <IfVersion < 2.4>
            Order allow,deny,
            Allow from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
    </Directory>        

    WSGIApplicationGroup %{GLOBAL}

    WSGIScriptAlias / /var/www/website.com/wsgi/website.com.wsgi

    <Directory /var/www/website.com/akb>
        WSGIProcessGroup website.com
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
    </Directory>

    Alias /static /var/www/website.com/akb/static
    <Directory /var/www/website.com/akb/static>
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
    </Directory>

    Alias /templates /var/www/website.com/akb/templates
    <Directory /var/www/website.com/akb/templates>
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
    </Directory>

    ErrorLog /var/www/website.com/errors/error.log
    LogLevel info
    CustomLog /var/www/website.com/errors/access.log combined

I finally fixed the issue:

  • by changing the os directory to the one of my env (os.chdir)
  • using chown/chmod to give edit/create rights to www-data

Can you explain how you did this?

by changing the os directory to the one of my env (os.chdir)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM