The current working directory of the process will not be where you source code 
is located, thus using os.getcwd() will not do what you want.

Use a configuration of:

    WSGIDaemonProcess myapp home=/var/www/wsgi-scripts
    WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi 
process-group=myapp application-group=%{GLOBAL}

and delete the modification of sys.path from the WSGI script file.

The WSGIDaemonProcess directive sets you up for using daemon mode, which is 
better than embedded mode.

    http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html 
<http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html>

The ‘home’ option to WSGIDaemonProcess changes the current working directory to 
be the directory where your WSGI script is and should also result in that 
directory being in the module search path.

If my memory is fuzzy, and that directory isn’t in module search path, also add 
to WSGIDaemonProcess the option:

    python-path=/var/www/wsgi-scripts

Graham

> On 21 Aug 2016, at 11:02 AM, Tierprot B. <tierp...@gmail.com> wrote:
> 
> 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:
> -------------------------
> <VirtualHost *:80>
>       ServerName www.example.com 
>       DocumentRoot /var/www/html
>       WSGIScriptAlias /test /var/www/wsgi-scripts/simple_app.wsgi
>       
>       <Directory /var/www/wsgi-scripts>
>           Require all granted
>       </Directory>
>  </VirtualHost>
> 
> 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 
> <mailto:modwsgi+unsubscr...@googlegroups.com>.
> To post to this group, send email to modwsgi@googlegroups.com 
> <mailto:modwsgi@googlegroups.com>.
> Visit this group at https://groups.google.com/group/modwsgi 
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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.

Reply via email to