wsgi is unable to load app from different location - python-2.7

When I am loading my class directly from some location I am able to load it.
>>> import sys
>>> sys.path.append('/path/to/my/flask/application')
>>> from myfile import app as application
>>>
Now from wsgi when I am doing the same thing.. it's not loading.
[Sat Aug 19 07:41:18 2017] [info] mod_wsgi (pid=29177): Imported 'mod_wsgi'.
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] mod_wsgi (pid=29172): Target WSGI script '/var/www/flask-prod/webtool.wsgi' cannot be loaded as Python module.
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] mod_wsgi (pid=29172): Exception occurred processing WSGI script '/var/www/flask-prod/webtool.wsgi'.
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] Traceback (most recent call last):
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] File "/var/www/flask-prod/webtool.wsgi", line 6, in <module>
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] from myfile import app as application
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] ImportError: No module named myfile
wsgi virtual host configuration below:
WSGIPythonHome /pathto/condadir
WSGIPythonPath /pathto/condadir/lib/python2.7
<virtualhost *:80>
ServerName myhost.example.com
WSGIDaemonProcess webtool user=apache group=root threads=5 home=/var/www/flask-prod/
WSGIScriptAlias / /var/www/flask-prod/webtool.wsgi
<directory /var/www/flask-prod>
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order allow,deny
Allow from all
</directory>
</virtualhost>
Below is the wsgi file.
#!/pathto/condadir/bin/python
import sys
sys.path.append('/path/to/my/flask/application')
from myfile import app as application
Server mount status:
$ df -hP
/dev/xvda1 494M 29M 440M 7% /boot
tmpfs 5.0G 0 5.0G 0% /dev/shm
/dev/xvdc1 50G 3.2G 44G 7% /path
/dev/mapper/vg_apol-lv_var 1.5G 164M 1.3G 12% /var
My Application:
$ ls -lrt /path/to/my/flask/
-rwxrwx--- 1 root root 109 Aug 9 11:16 README
drwxrwx--- 4 root root 4096 Aug 19 08:24 application
-rw------- 1 root root 0 Aug 19 08:25 __init__.py
$ ls -lrt /path/to/my/flask/application
-rwxrwx--- 1 root root 23 Jun 4 05:19 __init__.py
drwxrwx--- 6 root root 4096 Aug 7 15:24 static
-rwxrwx--- 1 root root 7168 Aug 9 11:45 users_sqlite.db
-rwxrwx--- 1 root root 9670 Aug 9 12:06 myfile.py
drwxrwx--- 5 root root 4096 Aug 10 14:50 templates
-rwxrwx--- 1 root root 448 Aug 10 14:51 myfile.pyc
httpd app portion:
$ pwd
/var/www
$ ls -ld flask-prod
drwxr-xr-x 2 root root 4096 Aug 19 08:21 flask-prod
$ ls -rlt flask-prod/
total 28
-rw------- 1 root root 0 Aug 18 15:54 __init__.py
-rwxr-xr-x 1 root root 258 Aug 19 08:21 webtool.wsgi

Related

Custom systemd service to run Gunicorn not working

I am trying to deploy my Django website to a Ubuntu server. I am following this tutorial: linuxhint.com/create_django_app_ubuntu/. However, the Gunicorn service doesn't work.
I have my site at /home/django/blog.
My Python 3.6 virtualenv is activated at /home/django/.venv/bin/activate (-rwxr-xr-x 1 django root 2207 Sep 21 14:07 activate).
The script for starting the server is at /home/django/bin/start-server.sh (-rwxr-xr-x 1 django root 69 Sep 21 15:50 start-server.sh), with the following content:
cd /home/django
source .venv/bin/activate
cd blog
gunicorn blog.wsgi
Running this script manually works just fine.
The Gunicorn service is at /etc/systemd/system/gunicorn.service, with this content:
[Unit]
Description=Gunicorn
After=network.target
[Service]
Type=simple
User=django
ExecStart=/home/django/bin/start-server.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Running systemctl status gunicorn.service gives this:
● gunicorn.service - Gunicorn
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2020-09-21 16:15:17 UTC; 6s ago
Process: 1114 ExecStart=/home/django/bin/start-server.sh (code=exited, status=203/EXEC)
Main PID: 1114 (code=exited, status=203/EXEC)
Sep 21 16:15:17 example.com systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Sep 21 16:15:17 example.com systemd[1]: gunicorn.service: Service hold-off time over, scheduling restart.
Sep 21 16:15:17 example.com systemd[1]: gunicorn.service: Scheduled restart job, restart counter is at 5.
Sep 21 16:15:17 example.com systemd[1]: Stopped Gunicorn.
Sep 21 16:15:17 example.com systemd[1]: gunicorn.service: Start request repeated too quickly.
Sep 21 16:15:17 example.com systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Sep 21 16:15:17 example.com systemd[1]: Failed to start Gunicorn.
Sep 21 16:15:18 example.com systemd[1]: gunicorn.service: Start request repeated too quickly.
Sep 21 16:15:18 example.com systemd[1]: gunicorn.service: Failed with result 'exit-code'.
Sep 21 16:15:18 example.com systemd[1]: Failed to start Gunicorn.
Sep 21 14:22:36 example.com systemd[7906]: gunicorn.service: Failed to execute command: Permission denied
Sep 21 14:22:36 example.com systemd[7906]: gunicorn.service: Failed at step EXEC spawning /home/django/bin/start-server.sh: Permission denied
Sep 21 14:23:40 example.com systemd[7940]: gunicorn.service: Failed to execute command: Permission denied
Sep 21 14:23:40 example.com systemd[7940]: gunicorn.service: Failed at step EXEC spawning /home/django/bin/start-server.sh: Permission denied
Sep 21 14:24:47 example.com systemd[7958]: gunicorn.service: Failed to execute command: Permission denied
Sep 21 14:24:47 example.com systemd[7958]: gunicorn.service: Failed at step EXEC spawning /home/django/bin/start-server.sh: Permission denied
Permission denied
.
.
.
I ran chown -R django:django /home/django. Now, the output of ls -lah /home/django is:
total 32K
drwxr-xr-x 5 django django 4.0K Sep 21 14:19 .
drwxr-xr-x 3 root root 4.0K Sep 21 14:04 ..
-rw-r--r-- 1 django django 220 Apr 4 2018 .bash_logout
-rw-r--r-- 1 django django 3.7K Apr 4 2018 .bashrc
-rw-r--r-- 1 django django 807 Apr 4 2018 .profile
drwxr-xr-x 4 django django 4.0K Sep 21 14:07 .venv
drwxr-xr-x 2 django django 4.0K Sep 21 15:58 bin
drwxr-xr-x 3 django django 4.0K Sep 21 14:08 blog
Solution
Thanks to Dmitry Belaventsev, the solution to this is to change
ExecStart=/home/django/bin/start-server.sh
to
ExecStart=/bin/bash /home/django/bin/start-server.sh
In the file /etc/systemd/system/gunicorn.service.
Your systemd service is setup to execute the script from behalf of django user. In the meantime:
ls -lah /home/django
total 32K
drwxr-xr-x 5 django django 4.0K Sep 21 14:19 .
drwxr-xr-x 3 root root 4.0K Sep 21 14:04 ..
-rw-r--r-- 1 django django 220 Apr 4 2018 .bash_logout
-rw-r--r-- 1 django django 3.7K Apr 4 2018 .bashrc
-rw-r--r-- 1 django django 807 Apr 4 2018 .profile
drwxr-xr-x 4 django root 4.0K Sep 21 14:07 .venv
drwxr-xr-x 2 root root 4.0K Sep 21 15:58 bin
drwxr-xr-x 3 root root 4.0K Sep 21 14:08 blog
As you can see:
drwxr-xr-x 3 root root 4.0K Sep 21 14:04 ..
and
drwxr-xr-x 2 root root 4.0K Sep 21 15:58 bin
which means:
/home directory belongs to root:root
/home/django/bin belongs to root:root
To let systemd execute a bash script from behalf of django user:
That script should be executable
All parent directories should have execution rights
All those directories and the script should be available for django user
The quickest solution:
chown -R /home/django django:django
Also you could play with group and group rights as well.

Script timed out before returning headers: wsgi.py; Django app on elastic beanstalk

I am deploying a Django app, but in the past 2 days I randomly started receiving the Script timed out before returning headers: wsgy.py with the following logs:
[Sun Feb 16 03:02:30.697009 2020] [mpm_prefork:notice] [pid 20719] AH00163: Apache/2.4.41 (Amazon) mod_wsgi/3.5 Python/3.6.8 configured -- resuming normal operations
[Sun Feb 16 03:02:30.697031 2020] [core:notice] [pid 20719] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Sun Feb 16 03:03:33.906331 2020] [mpm_prefork:notice] [pid 20719] AH00169: caught SIGTERM, shutting down
[Sun Feb 16 03:03:34.352673 2020] [suexec:notice] [pid 29207] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Sun Feb 16 03:03:34.368938 2020] [so:warn] [pid 29207] AH01574: module wsgi_module is already loaded, skipping
[Sun Feb 16 03:03:34.371217 2020] [http2:warn] [pid 29207] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Sun Feb 16 03:03:34.371234 2020] [http2:warn] [pid 29207] AH02951: mod_ssl does not seem to be enabled
[Sun Feb 16 03:03:34.371790 2020] [lbmethod_heartbeat:notice] [pid 29207] AH02282: No slotmem from mod_heartmonitor
[Sun Feb 16 03:03:34.371850 2020] [:warn] [pid 29207] mod_wsgi: Compiled for Python/3.6.2.
[Sun Feb 16 03:03:34.371855 2020] [:warn] [pid 29207] mod_wsgi: Runtime using Python/3.6.8.
[Sun Feb 16 03:03:34.374156 2020] [mpm_prefork:notice] [pid 29207] AH00163: Apache/2.4.41 (Amazon) mod_wsgi/3.5 Python/3.6.8 configured -- resuming normal operations
[Sun Feb 16 03:03:34.374172 2020] [core:notice] [pid 29207] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Sun Feb 16 12:10:08.501006 2020] [core:error] [pid 26171] [client 172.31.3.222:62336] Script timed out before returning headers: wsgi.py
This seems to be similar to the problem mentioned here, but those answers are a bit of a mess and additionally do not solve my problem. Here are some additional files:
wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
application = get_wsgi_application()
All of the following are elastic beanstalk configs:
01_packages.config:
packages:
yum:
git: []
postgresql93-devel: []
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "app.settings"
"PYTHONPATH": "/opt/python/current/app/app:$PYTHONPATH"
"ALLOWED_HOSTS": ".elasticbeanstalk.com"
"aws:elasticbeanstalk:container:python":
WSGIPath: app/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
02_python.config (with continer_commands ommitted):
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "app.settings"
"PYTHONPATH": "/opt/python/current/app/app:$PYTHONPATH"
"ALLOWED_HOSTS": ".elasticbeanstalk.com"
"aws:elasticbeanstalk:container:python":
WSGIPath: app/wsgi.py
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
03_apache.config:
container_commands:
01_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
files:
"/etc/httpd/conf.d/eb_healthcheck.conf":
mode: "000644"
owner: root
group: root
content: |
<If "req('User-Agent') == 'ELB-HealthChecker/2.0' && %{REQUEST_URI} == '/'">
RequestHeader set Host "app.com"
</If>
app.config:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: app/wsgi.py
files:
"/etc/httpd/conf.d/wsgi_custom.conf":
mode: "000644"
owner: root
group: root
content: |
WSGIApplicationGroup %{GLOBAL}
container_commands:
01_migrate:
command: "python manage.py migrate"
leader_only: true
packages:
yum:
git: []
postgresql93-devel: []
As you can see I have basically grown frustrated attempting different solutions with no real fix. I am also obviously not that familiar with Apache and elastic beanstalk and have had difficulty. Any guidance would be appreciated.

Forbidden You don't have permission to access / on this server. on Django, Apache, Centos7

I'm using Centos 7. I create a django project under /home/WEFORUM/admshapersdev/stargate/ and create a wsgi file in /home/WEFORUM/admshapersdev/stargate/stargate
The Django.conf
Alias /static /home/WEFORUM/admshapersdev/stargate/landingpage/static
<Directory /home/WEFORUM/admshapersdev/stargate/landingpage/static>
Require all granted
</Directory>
<Directory /home/WEFORUM/admshapersdev/stargate/stargate>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess stargate python-path=/home/WEFORUM/admshapersdev/stargate:/home/WEFORUM/admshapersdev/stargate/stargateenv/lib/python3.6/site-packages
WSGIProcessGroup stargate
WSGIScriptAlias / /home/WEFORUM/admshapersdev/stargate/stargate/wsgi.py
The structure and rights of the project folder:
../stargate
drwxr-xr-x. 6 admshapersdev apache 4096 Aug 17 22:47 landingpage/
-rwxr-xr-x. 1 admshapersdev apache 806 Aug 17 21:42 manage.py*
-rw-r--r--. 1 admshapersdev apache 464 Aug 17 22:42 requirements.txt
drwxr-xr-x. 4 admshapersdev apache 4096 Aug 18 01:08 stargate/
drwxr-xr-x. 5 admshapersdev apache 77 Aug 17 21:41 stargateenv/
drwxr-xr-x. 2 admshapersdev apache 6 Aug 17 21:52 static/
../stargate/stargate
-rw-r--r--. 1 admshapersdev apache 0 Aug 17 21:42 __init__.py
drwxr-xr-x. 2 admshapersdev apache 4096 Aug 18 01:09 __pycache__/
-rw-r--r--. 1 admshapersdev domain users 3555 Aug 18 01:08 settings.py
-rw-r--r--. 1 admshapersdev apache 3676 Aug 18 01:05 settings.py_1
drwxr-xr-x. 9 admshapersdev apache 91 Aug 17 22:49 static/
-rw-r--r--. 1 admshapersdev apache 259 Aug 17 22:38 urls.py
-rwxr--r--. 1 admshapersdev apache 394 Aug 18 00:49 wsgi.py*
But each time I try to reach my page, I am having this error in apache log:
[core:error] [pid 22477] (13)Permission denied: [client 192.168.140.179:63696] AH00035: access to /favicon.ico denied (filesystem path '/home/WEFORUM/admshapersdev/stargate') because search permissions are missing on a component of the path, referer: http://stargate0.weforum.local/admin
Does anyone know how to handle this? thank you for suggestions.
I move the project to /var/www but now I am having this:
[Sat Aug 18 07:43:49.987481 2018] [core:notice] [pid 20202] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Sat Aug 18 07:58:19.927287 2018] [core:error] [pid 20205] (13)Permission denied: [client 192.168.140.179:49188] AH00035: access to /admin/ denied (filesystem path '/var/www/stargate') because search permissions are missing on a component of the path, referer: http://stargate0.weforum.local/admin/login/?next=/admin/
[Sat Aug 18 07:58:24.840377 2018] [core:error] [pid 20205] (13)Permission denied: [client 192.168.140.179:49188] AH00035: access to / denied (filesystem path '/var/www/stargate') because search permissions are missing on a component of the path
[Sat Aug 18 07:58:29.481225 2018] [core:error] [pid 20205] (13)Permission denied: [client 192.168.140.179:49188] AH00035: access to /admin/ denied (filesystem path '/var/www/stargate') because search permissions are missing on a component of the path, referer: http://stargate0.weforum.local/admin/login/?next=/admin/

mod_wsgi cannot be loaded as Python module

I'm trying to access a Django application using apache and I'm getting Internal Server Error. I've opened the logs to see what is going on and I found this:
[Thu Jun 23 03:10:03 2016] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jun 23 03:10:03 2016] [notice] Digest: generating secret for digest authentication ...
[Thu Jun 23 03:10:03 2016] [notice] Digest: done
[Thu Jun 23 03:10:03 2016] [notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 configured -- resuming normal operations
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] mod_wsgi (pid=5612): Target WSGI script '/home/TaskManagement/teamwork/wsgi.py' cannot be loaded as Python module.
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] mod_wsgi (pid=5612): Exception occurred processing WSGI script '/home/TaskManagement/teamwork/wsgi.py'.
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] Traceback (most recent call last):
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/TaskManagement/teamwork/wsgi.py", line 15, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.core.wsgi import get_wsgi_application
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/__init__.py", line 1, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.utils.version import get_version
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/utils/version.py", line 7, in <module>
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] from django.utils.lru_cache import lru_cache
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] File "/home/py3venv/lib/python3.4/site-packages/django/utils/lru_cache.py", line 28
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] fasttypes = {int, str, frozenset, type(None)},
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] ^
[Thu Jun 23 03:10:10 2016] [error] [client 197.41.248.175] SyntaxError: invalid syntax
I'm using python 3.4, Django 1.9, apache 2.2.
and here is my apache configuration:
WSGISocketPrefix /var/run/wsgi
WSGIScriptAlias / /home/TaskManagement/teamwork/wsgi.py process-group=hrm.jodod.info
WSGIDaemonProcess hrm.jodod.info python-path=/home/TaskManagement:/home/py3venv/lib/python3.4/site-packages
WSGIProcessGroup hrm.jodod.info
Alias /robots.txt /home/TaskManagement/robots.txt
Alias /favicon.ico /home/TaskManagement/favicon.ico
Alias /static/ /home/TaskManagement/static/
<Directory /path/to/mysite.com/static>
Order deny,allow
Allow from all
</Directory>
<Directory /home/TaskManagement/teamwork>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
and here is my wsgi.py file:
import os
import sys
sys.path.append('/home/TaskManagement')
sys.path.append('/home/TaskManagement/teamwork')
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"
application = get_wsgi_application()
Can anybody figure out what am I doing wrong?
Python/2.6.6 configured -- resuming normal operations
Looks like your mod_wsgi is compiled against Python 2.6.6 and you're trying to run Python3 code with it. The Set syntax you are seeing in the error appeared in Py3. Recompile mod_wsgi and try again.
Your wsgi.py line 9 has to be
os.environ["DJANGO_SETTINGS_MODULE"] = "teamwork.settings"
if the directory it's stored is called teamwork (your project's name)
also in your manage.py it has to be "teamwork.settings"

centos 7 Apache wsgi writing files permission denied

In my site2 Django application Apache wsgi don't have writing access for files in /var/www/site2, even if:
I have chown-ed to apache all files from /var/www/site2 directory
I give all rights (chmod -R 777).
and SELinux is disabled.
Below is a briefing state:
[root#nuc www]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13
[root#nuc www]# ls -l
total 4
drwxr-xr-x. 2 root root 6 Nov 19 23:43 cgi-bin
drwxr-xr-x. 2 root root 6 Apr 2 15:02 html
drwxrwxrwx. 6 apache apache 4096 Apr 3 16:14 site2
[root#nuc site2]# ls -l
...
drwxrwxrwx. 5 apache apache 4096 Apr 2 15:23 blog
-rwxrwxrwx. 1 apache apache 95232 Apr 3 16:09 db.sqlite3
drwxrwxrwx. 5 apache apache 4096 Apr 2 16:54 home
-rwxrwxrwx. 1 apache apache 248 Mar 19 13:56 manage.py
drwxrwxrwx. 5 apache apache 4096 Apr 3 16:13 pock
drwxrwxrwx. 2 apache apache 4096 Apr 3 14:45 site2
[root#nuc www]# sestatus
SELinux status: disabled
httpd.conf ...
#-------------------------------------------------
WSGIScriptAlias / /var/www/site2/site2/wsgi.py
WSGIPythonPath /var/www/site2/
Alias /static/ /var/www/site2/blog/static/
Alias /static2/ /var/www/site2/home/static/
Alias /static3/ /var/www/site2/pock/static/
<Directory /var/www/site2/blog/static/>
Require all granted
</Directory>
<Directory /var/www/site2/home/static/>
Require all granted
</Directory>
<Directory /var/www/site2/pock/static/>
Require all granted
</Directory>
<Directory /var/www/site2/site2/>
<Files wsgi.py>
#Order deny,allow
Allow from all
Require all granted
</Files>
</Directory>
#-------------------------------------------------
And still in /var/log/httpd/error_log:
[Sun Apr 03 13:43:17.389404 2016] [:error] [pid 4753] /var/www/site2
[Sun Apr 03 13:43:17.390560 2016] [:error] [pid 4753] Internal Server Error: /pock/test/
[Sun Apr 03 13:43:17.390593 2016] [:error] [pid 4753] Traceback (most recent call last):
[Sun Apr 03 13:43:17.390602 2016] [:error] [pid 4753] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
[Sun Apr 03 13:43:17.390609 2016] [:error] [pid 4753] response = self.process_exception_by_middleware(e, request)
[Sun Apr 03 13:43:17.390634 2016] [:error] [pid 4753] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
[Sun Apr 03 13:43:17.390643 2016] [:error] [pid 4753] response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Sun Apr 03 13:43:17.390650 2016] [:error] [pid 4753] File "/var/www/site2/pock/views.py", line 57, in test
[Sun Apr 03 13:43:17.390656 2016] [:error] [pid 4753] f = open('test.txt', 'w')
[Sun Apr 03 13:43:17.390662 2016] [:error] [pid 4753] IOError: [Errno 13] Permission denied: 'test.txt'
SOLVED
Thanks to suggestions of Volodymyr I did more digging and I find the way finnaly.
Moving project in /home directory was not working for me: getting "Forbidden" from Apache.
The file I was trying to write need absolute path:
f = open('/var/www/site2/test.txt', 'w')
Otherwise wsgi python would try to write it in "/" root file system, so the error above is explained
In the end I did chown -R 744 /var/www/site2 and it worked, writing to files and database.
Seems that I have done other error but, anyway, it works now.
Try to :
chown -R root:apache /Path/To/You/WebSitePackage
I had this problem when deploy Django with httpd on Centos 7. I chose other way : Create WEBSITE Package in home/user/ directory, then
chown -R apache:apache Path/To/WEBSITEPackage
chmod -R 770 Path/To/WEBSITEPackage
After You can try :
chown -R user:root Path/To/WEBSITEPackage
chmod -R 770 Path/To/WEBSITEPackage
chown -R apache:root Path/To/WEBSITEPackage
chmod -R 770 Path/To/WEBSITEPackage
Other words apache on centos 7 need root privelegies