Re: [modwsgi] Re: mod_wsgi importError

2016-08-21 Thread Tierprot B.
Hmm and now im more confused, i copied server files from
/home/user/flask_stuff_files
to the new directory /var/www/flask_stuff_files and corrected Apache conf,
now it looks like:

apache-wsgi config:


  ServerName www.example.com
  DocumentRoot /var/www/flask_stuff_files/templates
  WSGIDaemonProcess home=/var/www/wsgi-scripts python-path=/var/www
/flask_stuff_files user=user group=user
  WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi
process-group=app application-group=%{GLOBAL}

  
  Require all granted
  

 

Still main page www.example.com/test renders ok, but on files submission i
get error File does not exist: /var/www/flask_stuff_files/templates/analysis,
referer: http://www.example.com/test


2016-08-22 1:28 GMT+03:00 Graham Dumpleton <graham.dumple...@gmail.com>:

>
> On 22 Aug 2016, at 8:16 AM, Tierprot B. <tierp...@gmail.com> wrote:
>
> Aha! Thanks! Addition of proper user and group options to
> WSGIDaemonProcess solved the ImportError! The last question i have might
> be not related to mod_wsgi directly, but still.
> I have a Flask app, purpose of which to be able to upload files provided
> by user, do some math and return result on a new page. Simplified code
> looks like this:
>
> ...
>
> @app.route('/'):
> def index()
>  return render_template('index.html')
>
> @app.route('/analysis', methods=['POST'])
> def upload():
>  uploaded_files = request.files.getlist('files')
>  ...
>  for file in uploaded_files:
>...
>  return render_template('analysis.html')
>
> ...
>
> The folder with static files which Flask renders is:
>
> home/user/flask_stuff_files/templates
>
>
> in Apache ive corrected document root folder and added directory with
> static files:
>
> apache-wsgi config:
> 
> 
>   ServerName www.example.com
>   DocumentRoot /home/user/flask_stuff_files/templates
>
>
> What are you trying to have happen by adding this?
>
> The Apache user would need access to that directory and once agains the
> permissions on the directories are such that that can’t happen. Changing
> user for mod_wsgi daemon process group only affects access to Python code,
> not static files Apache tries to serve up.
>
> In general this is why is better not to have anything for your application
> under your home directory. Better under separate directory for project
> under /var/www.
>
>   WSGIDaemonProcess home=/var/www/wsgi-scripts python-path=
> /home/user/flask_stuff_files user=user group=user
>   WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi
> process-group=app application-group=%{GLOBAL}
>
>   
>   Require all granted
>   
>
>   
>   WSGIProcessGroup app
>   WSGIApplicationGroup %{GLOBAL}
>   Require all granted
>   
>
>
> May not need this entry for /home/user/flask_stuff_files.
>
>   
>   WSGIProcessGroup app
>   WSGIApplicationGroup %{GLOBAL}
>   Require all granted
>   
>
>
> May not need this entry for /home/user/flask_stuff_files/templates.
> Depends on answer about DocumentRoot.
>
> The Directory block and access grants is only needed for where the WSGI
> script file is located.
>
> The WSGIScriptAlias already specifies process-group and application-group
> so the WSGIProcessGroup and WSGIApplicationGroup not needed either.
>
>  
>
> So, www.example.com/test - it renders main page as intended, but when i
> select files and submit them via POST request ive got a forbidden access
> with error_log : Permission denied [...] : acces to /analysis denied
> (filesystempath '/home/user/flask_stuff_files') because search
> permissions are missing on a component of the path, referer:
> www.example.com/test.
>
> For the test, i set permissions of the folder /home/user/flask_stuff_files
> to the drwxrwxrwx, it belongs to user user.
>
> So, could you share your thoughts on what is wrong here?
>
>
> Graham
>
> 2016-08-21 23:28 GMT+03:00 Graham Dumpleton <graham.dumple...@gmail.com>:
>
>> Your code will be running as the Apache user. Your home directory would
>> have restrictive permissions on it such that not everyone can access files
>> out of it.
>>
>> The quickest solution would be to set the process/group that the mod_wsgi
>> daemon process runs as.
>>
>> WSGIDaemonProcess home=/var/www/wsgi-scripts
>> python-path=/home/user/flask_stuff_files user=xxx group=yyy
>>
>> Replace xxx with your user name and yyy with the group name, likely same
>> as xxx.
>>
>> Thi presume

Re: [modwsgi] Re: mod_wsgi importError

2016-08-21 Thread Tierprot B.
Aha! Thanks! Addition of proper user and group options to WSGIDaemonProcess
solved the ImportError! The last question i have might be not related to
mod_wsgi directly, but still.
I have a Flask app, purpose of which to be able to upload files provided by
user, do some math and return result on a new page. Simplified code looks
like this:

...

@app.route('/'):
def index()
 return render_template('index.html')

@app.route('/analysis', methods=['POST'])
def upload():
 uploaded_files = request.files.getlist('files')
 ...
 for file in uploaded_files:
   ...
 return render_template('analysis.html')

...

The folder with static files which Flask renders is:

home/user/flask_stuff_files/templates


in Apache ive corrected document root folder and added directory with
static files:

apache-wsgi config:


  ServerName www.example.com
  DocumentRoot /home/user/flask_stuff_files/templates
  WSGIDaemonProcess home=/var/www/wsgi-scripts python-path=
/home/user/flask_stuff_files user=user group=user
  WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi
process-group=app application-group=%{GLOBAL}

  
  Require all granted
  

  
  WSGIProcessGroup app
  WSGIApplicationGroup %{GLOBAL}
  Require all granted
  

  
  WSGIProcessGroup app
  WSGIApplicationGroup %{GLOBAL}
  Require all granted
  

 

So, www.example.com/test - it renders main page as intended, but when i
select files and submit them via POST request ive got a forbidden access
with error_log : Permission denied [...] : acces to /analysis denied
(filesystempath '/home/user/flask_stuff_files') because search permissions
are missing on a component of the path, referer: www.example.com/test.

For the test, i set permissions of the folder /home/user/flask_stuff_files
to the drwxrwxrwx, it belongs to user user.

So, could you share your thoughts on what is wrong here?

2016-08-21 23:28 GMT+03:00 Graham Dumpleton <graham.dumple...@gmail.com>:

> Your code will be running as the Apache user. Your home directory would
> have restrictive permissions on it such that not everyone can access files
> out of it.
>
> The quickest solution would be to set the process/group that the mod_wsgi
> daemon process runs as.
>
> WSGIDaemonProcess home=/var/www/wsgi-scripts
> python-path=/home/user/flask_stuff_files user=xxx group=yyy
>
> Replace xxx with your user name and yyy with the group name, likely same
> as xxx.
>
> Thi presumes the issue isn’t as simple as you having left off the leading
> slash on the path to the python-path option as your snippet showed.
>
> Graham
>
> On 21 Aug 2016, at 11:41 PM, Tierprot B. <tierp...@gmail.com> wrote:
>
>
>> That is what WSGIScriptAlias is doing in giving it the path to the WSGI
>> script file. If you mean something different you need to be clearer.
>>
>> b) that it should include python files from outside directory, for
>> example home/user/flask_stuff_files ?
>>
>>
>> If you are talking about other places to look for Python modules to
>> import, that is what the python-path option for WSGIDaemonProcess that I
>> mentioned is for.
>>
>> Graham
>>
>>
> Ok, ive got python modules which i try to import located at 
> home/user/flask_stuff_files,
> mine wsgi file is in /var/www/wsgi-scripts, now to the code:
>
> apache-wsgi config:
> 
> 
>   ServerName www.example.com
>   DocumentRoot /var/www/html
>
>   WSGIDaemonProcess home=/var/www/wsgi-scripts python-path=
> home/user/flask_stuff_files
>   WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi
>
>   
>   Require all granted
>   
>  
> -
>
> simple_app.wsgi:
> --
> import server_handle
>
> def application(environ, start_response):
> status = '200 OK'
> output = b'Hello, World!'
>
> response_headers = [('Content-type', 'text/plain'),
> ('Content-Length', str(len(output)))]
> start_response(status, response_headers)
> return [output]
>
> 
>
> server_handle.py module is located at /home/user/flask_stuff_files
>
> on trying www.example.com/test Apache spits with error ImportError: no
> module named 'server_handle'
>
> adding of code like:
>
> import sys
> sys.path.insert(0,'/home/user/flask_stuff_files')
>
> dont solve the problem too (do you know why, btw?)
>
> Theres something i didn`t properly understood, so sorry for annoying and
> dumb questions :)
>
> --
> You received this message because you are subscribed to the Go

Re: [modwsgi] Re: mod_wsgi importError

2016-08-21 Thread Tierprot B.

>
>
> That is what WSGIScriptAlias is doing in giving it the path to the WSGI 
> script file. If you mean something different you need to be clearer.
>
> b) that it should include python files from outside directory, for example 
> home/user/flask_stuff_files ?
>
>
> If you are talking about other places to look for Python modules to 
> import, that is what the python-path option for WSGIDaemonProcess that I 
> mentioned is for.
>
> Graham
>
>
Ok, ive got python modules which i try to import located at 
home/user/flask_stuff_files, 
mine wsgi file is in /var/www/wsgi-scripts, now to the code:

apache-wsgi config:


  ServerName www.example.com 
  DocumentRoot /var/www/html

  WSGIDaemonProcess home=/var/www/wsgi-scripts python-path=
home/user/flask_stuff_files
  WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi
  
  
  Require all granted
  
 
-

simple_app.wsgi:
--
import server_handle

def application(environ, start_response):
status = '200 OK'
output = b'Hello, World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]



server_handle.py module is located at /home/user/flask_stuff_files

on trying www.example.com/test Apache spits with error ImportError: no 
module named 'server_handle'  

adding of code like:

import sys
sys.path.insert(0,'/home/user/flask_stuff_files')

dont solve the problem too (do you know why, btw?)

Theres something i didn`t properly understood, so sorry for annoying and 
dumb questions :)

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to modwsgi+unsubscr...@googlegroups.com.
To post to this group, send email to modwsgi@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.


[modwsgi] Re: mod_wsgi importError

2016-08-21 Thread Tierprot B.
Thanks for the fast reply! I did what you`ve wrote and yay it worked! Now i 
wondering how can i tell to mod_wsgi two things - a) that wsgi file itself 
lies in /var/www/wsgi-scripts and b) that it should include python files 
from outside directory, for example home/user/flask_stuff_files ?

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to modwsgi+unsubscr...@googlegroups.com.
To post to this group, send email to modwsgi@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.


[modwsgi] mod_wsgi importError

2016-08-20 Thread Tierprot B.
Good day, im trying to deploy a server on CentOs7 in combination 
Flask+Apache 2.4+mod_wsgi 4.5.5. Mod_wsgi was compiled with python 3.5.2 
and test-run from manual works fine. However when i tried to connect mine 
app i failed so i reduced tests to only Apache+mod_wsgi stack and found 
that somehow import of python modules isnt working. The simplest test ive 
run is -  ive got folder with wsgi file and some function deployed in the 
same folder. 


insides of simple_app.wsgi:
---
import sys, os
sys.path.insert(0,os.getcwd())

import add


def application(environ, start_response):
status = '200 OK'
output = add.echo()

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]

-

insides of add.py:
-
def echo():
 return b'module import is fine'
-

Apache VirtualHost config:
-

  ServerName www.example.com 
  DocumentRoot /var/www/html
  WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi
  
  
  Require all granted
  
 

Apache logs are telling:
...
[wsgi:error] [pid 11717] [client 83.220.186.194:56534] ImportError: no 
module named 'add'
...

If i will leave the same Apache config, remove importing stuff from 
simple_app.wsgi and as a result will return some byte string, like in this 
code:


def application(environ, start_response):
status = '200 OK'
output = b'Hello, World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]


everything will work just fine without errors and by opening 
www.example.com/test i will see 

"Hello, World!"



Since im totally newbie in Apache/mod_wsgi stuff all suggestions are 
welcome!







-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to modwsgi+unsubscr...@googlegroups.com.
To post to this group, send email to modwsgi@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.