python - os.makedirs leads to OSError on Amazon AWS Ubuntu instance -


on ubuntu aws instance, trying set flask service after setting apache.

in /var/www/html/myapp/, have these files, among others:

myapp.py

myapp.wsgi

here contents of myapp.wsgi:

import sys sys.path.insert(0, '/var/www/html/myapp')  myapp import app application 

and here contents of /etc/apache2/sites-enabled/000-default.conf:

<virtualhost *:80>     # servername directive sets request scheme, hostname , port     # server uses identify itself. used when creating     # redirection urls. in context of virtual hosts, servername     # specifies hostname must appear in request's host: header     # match virtual host. default virtual host (this file)     # value not decisive used last resort host regardless.     # however, must set further virtual host explicitly.     #servername www.example.com      serveradmin webmaster@localhost     documentroot /var/www/html      wsgidaemonprocess charter threads=5     wsgiscriptalias / /var/www/html/myapp/myapp.wsgi      <directory flaskapp>         wsgiprocessgroup myapp         wsgiapplicationgroup %{global}         order deny,allow         allow     </directory>      # available loglevels: trace8, ..., trace1, debug, info, notice, warn,     # error, crit, alert, emerg.     # possible configure loglevel particular     # modules, e.g.     #loglevel info ssl:warn      errorlog ${apache_log_dir}/error.log     customlog ${apache_log_dir}/access.log combined      # configuration files conf-available/,     # enabled or disabled @ global level, possible     # include line 1 particular virtual host. example     # following line enables cgi configuration host     # after has been globally disabled "a2disconf".     #include conf-available/serve-cgi-bin.conf </virtualhost> 

and in myapp.py, have code make directory:

if not os.path.exists("dir"):     os.makedirs("dir") 

but when navigate browser http://my-ubuntu-ec2-address.compute-1.amazonaws.com/myapp/, returns 500 error.

when check error log @ /var/log/apache2/error.log, see these lines:

[mon aug 14 22:57:06.346698 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792] mod_wsgi (pid=6641): target wsgi script '/var/www/html/myapp/myapp.wsgi' cannot loaded python module. [mon aug 14 22:57:06.346734 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792] mod_wsgi (pid=6641): exception occurred processing wsgi script '/var/www/html/myapp/myapp.wsgi'. [mon aug 14 22:57:06.346750 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792] traceback (most recent call last): [mon aug 14 22:57:06.346768 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792]   file "/var/www/html/myapp/myapp.wsgi", line 4, in <module> [mon aug 14 22:57:06.346791 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792]     myapp import app application [mon aug 14 22:57:06.346797 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792]   file "/var/www/html/myapp/myapp.py", line 12, in <module> [mon aug 14 22:57:06.346806 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792]     os.makedirs(graphicsfiles) [mon aug 14 22:57:06.346811 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792]   file "/usr/lib/python2.7/os.py", line 157, in makedirs [mon aug 14 22:57:06.346820 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792]     mkdir(name, mode) [mon aug 14 22:57:06.346837 2017] [:error] [pid 6641:tid 139812646708992] [client ip-address-removed:48792] oserror: [errno 13] permission denied: 'dir' 

what need change ensure app has permission make directory or file?

you can't use relative path names, nor use directory apache user can't write to. see documentation at:

your apache configuration wrong.

<directory flaskapp>     wsgiprocessgroup myapp     wsgiapplicationgroup %{global}     order deny,allow     allow </directory> 

using flaskapp argument here directory isn't correct. argument should directory wsgi script file located in.

<directory /var/www/html/myapps>     wsgiprocessgroup myapp     wsgiapplicationgroup %{global}     order deny,allow     allow </directory> 

a further issues is bad practice put source code under directory specified documentroot. if make mistake in apache configuration, people download source code, possibly including configuration secrets in source code.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -