We have answer of your question!

100% solved queries, no empty question

Question: FlaskApp Running with Apache unable to save file on server side can't get permission to work out?


I have a flask app running at /var/www/FlaskApp/FlaskApp/init.py

├── /var/www/FlaskApp
├── FlaskApp
|   ├── flask (This is a virtual environment with python3.4 and packages)
│   ├── __init__.py
├── config.py

My init.py looks like this:

from flask import Flask

app = Flask(__name__)

@app.route('/upload, methods=['GET','POST'])
def upload(machine):
        if request.method == 'POST':
                f = request.files['files']
                filename = '/var/www/FlaskApp/FlaskApp/static/runFiles/myfile.txt

                #Some how there is an error saving the file here...???!!! WHY 

if __name__ == "__main__":

I read the apache error log and I see that it is a permission error:

[Fri Dec 09 12:08:11.371696 2016] [wsgi:error] [pid 3425:tid 1962931248] IOError: [Errno 13] Permission denied: u'/var/www/FlaskApp/FlaskApp/static/runFiles/myfile.txt

So I was thinking that somehow the apache user coulden't get access to this directory. Just to mess around I figured what the heck, lets see if chmod 777 will fix this. So I did this:

sudo chmod 777 /var/www/

However I still got the error when I would try to upload the file. This is how I am trying to upload the file:

curl -i -X POST -F files=@/pathtomyfile.txt myip/upload/

I am wondering how to fix the permission error. I have tried adding absolute paths and I also tried the following:

sudo chown -R www-data:www-data /var/www
chmod go-rwx /var/www

However I haven't been able to get away from this error. Here is my FlaskApp.conf from apache:

WSGIPythonHome /usr/local/bin
WSGIPythonPath /var/www/FlaskApp/FlaskApp/flask/lib/python3.4/site-packages

<VirtualHost *:80>
                ServerName my ip (this is local)
                ServerAdmin my email
                WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Require all granted
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined

I am looking into insight as to why I get the error for permission denied when I try to save the file that I am attempting to upload to my server.

Ok here are some more outputs:

ls -ldg /var/www/
drwxrwxrwx+ 4 www-data 4096 Dec  7 10:31 /var/www/

ls -ldg /var/www/FlaskApp/FlaskApp/static/runFiles
drwxr-xr-x 2 root 0 Nov 23 07:54 /var/www/FlaskApp/FlaskApp/static/runFiles
Question author Str8-struggin | Source



Sorry if you mentioned this but I don't see it: what user is the apache process running as? Are you sure it is the www-data user?

sudo chown -R www-data:www-data /var/www
chmod go-rwx /var/www

By doing that ^ you have locked it down so nobody except www-data user can do anything with the files. Even the www-data group wont be able to access because go-rwx means "Deny rwx permission for group, others".

Finally for troubleshooting, what is the output from these?

ls -ldg /var/www/
ls -ldg /var/www/FlaskApp/FlaskApp/static/runFiles
ls -l /var/www/FlaskApp/FlaskApp/static/runFiles/myfile.txt
Answer author Alex-g-rice

Tickanswer.com is providing the only single recommended solution of the question FlaskApp Running with Apache unable to save file on server side can't get permission to work out? under the categories i.e python , apache , flask , wsgi , . Our team of experts filter the best solution for you.

Related Search Queries:

You may also add your answer

Thanks for contributing an answer to Tick Answer!