Wagtail deployment on Centos7 - django

I could really use some help here. I am in the process of setting up a test deployment of wagtail on a CentOS7 box and it seems as though the wsgi daemon is not getting access to the necessary python modules. I have checked permissions on all of the directories in the virtual environment and made sure that the owner was apache as well as the group owner was apache (recursively). SELinux is also in permissive mode while I'm trying to figure this out. It's a fresh install of wagtail, no modifications have been made after running the start command from wagtail.
My virtual host config file is as follows:
<VirtualHost *:80>
ServerName <server.name>
ServerAdmin <server.admin>
Alias /static /var/www/<virtual.env>/<project.name>/static
<Directory /var/www/<virtual.env>/<project.name>/static>
Require all granted
</Directory>
<Directory /var/www/<virtual.env>/<project.name>/wsgi.py>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess <project> python-path=/var/www/<virtual.env>/<project.name>/<project.name>:/var/www/<virtual.env/lib/python3.4/site-packages
WSGIProcessGroup <project>
WSGIScriptAlias / /var/www/<project.env>/<project.name>/<project.name>/wsgi.py
ErrorLog /var/log/httpd/<project.name>_error.log
CustomLog /var/log/httpd/<project.name>_access.log combined
My project_error.log file contains the following:
[Thu May 04 18:50:35.596691 2017] [:error] [pid 13101] [remote 10.30.112.49:52] mod_wsgi (pid=13101): Exception occurred processing WSGI script '/var/www/<project.name>_env/<project.name>/<project.name>/wsgi.py'.
[Thu May 04 18:50:35.596712 2017] [:error] [pid 13101] [remote 10.30.112.49:52] Traceback (most recent call last):
[Thu May 04 18:50:35.596733 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/<project.name>/<project.name>/wsgi.py", line 18, in <module>
[Thu May 04 18:50:35.596785 2017] [:error] [pid 13101] [remote 10.30.112.49:52] application = get_wsgi_application()
[Thu May 04 18:50:35.596797 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu May 04 18:50:35.596836 2017] [:error] [pid 13101] [remote 10.30.112.49:52] django.setup(set_prefix=False)
[Thu May 04 18:50:35.596846 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/django/__init__.py", line 27, in setup
[Thu May 04 18:50:35.596887 2017] [:error] [pid 13101] [remote 10.30.112.49:52] apps.populate(settings.INSTALLED_APPS)
[Thu May 04 18:50:35.596898 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
[Thu May 04 18:50:35.597029 2017] [:error] [pid 13101] [remote 10.30.112.49:52] app_config.import_models(all_models)
[Thu May 04 18:50:35.597039 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/django/apps/config.py", line 199, in import_models
[Thu May 04 18:50:35.597118 2017] [:error] [pid 13101] [remote 10.30.112.49:52] self.models_module = import_module(models_module_name)
[Thu May 04 18:50:35.597131 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
[Thu May 04 18:50:35.597177 2017] [:error] [pid 13101] [remote 10.30.112.49:52] __import__(name)
[Thu May 04 18:50:35.597187 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/wagtail/wagtailforms/models.py", line 16, in <module>
[Thu May 04 18:50:35.597283 2017] [:error] [pid 13101] [remote 10.30.112.49:52] from wagtail.wagtailadmin.edit_handlers import FieldPanel
[Thu May 04 18:50:35.597292 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/wagtail/wagtailadmin/edit_handlers.py", line 19, in <module>
[Thu May 04 18:50:35.597493 2017] [:error] [pid 13101] [remote 10.30.112.49:52] from wagtail.wagtailadmin import compare, widgets
[Thu May 04 18:50:35.597503 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/wagtail/wagtailadmin/compare.py", line 5, in <module>
[Thu May 04 18:50:35.597660 2017] [:error] [pid 13101] [remote 10.30.112.49:52] from bs4 import BeautifulSoup
[Thu May 04 18:50:35.597673 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/bs4/__init__.py", line 35, in <module>
[Thu May 04 18:50:35.597822 2017] [:error] [pid 13101] [remote 10.30.112.49:52] from .builder import builder_registry, ParserRejectedMarkup
[Thu May 04 18:50:35.597832 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/bs4/builder/__init__.py", line 7, in <module>
[Thu May 04 18:50:35.597933 2017] [:error] [pid 13101] [remote 10.30.112.49:52] from bs4.element import (
[Thu May 04 18:50:35.597943 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/bs4/element.py", line 10, in <module>
[Thu May 04 18:50:35.598337 2017] [:error] [pid 13101] [remote 10.30.112.49:52] from bs4.dammit import EntitySubstitution
[Thu May 04 18:50:35.598347 2017] [:error] [pid 13101] [remote 10.30.112.49:52] File "/var/www/<project.name>_env/lib/python3.4/site-packages/bs4/dammit.py", line 14, in <module>
[Thu May 04 18:50:35.598548 2017] [:error] [pid 13101] [remote 10.30.112.49:52] from html.entities import codepoint2name
[Thu May 04 18:50:35.598565 2017] [:error] [pid 13101] [remote 10.30.112.49:52] ImportError: No module named html.entities
Huge thanks in advance.

Two things I noticed. <Directory /var/www/<virtual.env>/<project.name>/wsgi.py> should point to the directory <Directory /var/www/<virtual.env>/<project.name>/, not the file itself. Also, mod_wsgi needs to be compiled against the same version of Python you developed against, as #gasman mentioned.
If you want to upgrade to Python 3.5 and install mod_wsgi from the IUS repository:
sudo yum install https://centos7.iuscommunity.org/ius-release.rpm
sudo yum install python35u python35u-pip python35u-devel python35u-mod_wsgi
Good luck!

Related

How to Serve Django Application With Apache2 and Mod WSGI

I want to serve my Django applications using Apache2 and the mod_wsgi module. I have setup an Apache virtualhost at /etc/apache2/sites-available/mysite.confand I have made some configuration changes to WSGI at home/username/development/mysite/mysite/wsgi.py However, when I navigate to mydomain.com, I am being presented with the 500 Internal Server Error: The server encountered an internal error or misconfiguration and was unable to complete your request.. I am very new to server development and have never used Apache2 before so I am unsure as to where I have gone wrong in my configuration. Below you will find my virtualhost configuration file as well as my WSGI file. Additionally, I have provided the structure layout of my project directory in case this helps. Any help is greatly appreciated.
directory structure
>> home
>> username
>> development
>> mysite
>> mysite
>> settings.py
>> wsgi.py
>> website
>> static
>> manage.py
>> venv
mysite.conf
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /home/username/development/mysite
WSGIScriptAlias / /home/username/development/mysite/mysite/wsgi.py
WSGIDaemonProcess mydomain.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/username/development/venv/lib/python3.5
WSGIProcessGroup mydomain.com
<directory /home/username/development/mysite>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/username/development/mysite/website/static/
<Directory /home/username/development/mysite/website/static>
Require all granted
</Directory>
</VirtualHost>
wsgi.py
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/username/development/mysite')
# adjust the Python version in the line below as needed
sys.path.append('/home/username/development/venv/lib/python3.5/site-packages')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
error.log
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_mysql.so' - /usr/lib/php/20151012/pdo_mysql.so: undefined symbol: mysqlnd_connect in Unknown on line 0
[Mon Aug 05 06:25:02.417656 2019] [wsgi:warn] [pid 11931] mod_wsgi: Compiled for Python/3.5.1+.
[Mon Aug 05 06:25:02.417679 2019] [wsgi:warn] [pid 11931] mod_wsgi: Runtime using Python/3.5.2.
[Mon Aug 05 06:25:02.418568 2019] [mpm_prefork:notice] [pid 11931] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Mon Aug 05 06:25:02.418590 2019] [core:notice] [pid 11931] AH00094: Command line: '/usr/sbin/apache2'
[Mon Aug 05 10:09:39.950527 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod_wsgi (pid=23705): Target WSGI script '/home/username/development/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Mon Aug 05 10:09:39.950606 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod_wsgi (pid=23705): Exception occurred processing WSGI script '/home/username/development/mysite/mysite/wsgi.py'.
[Mon Aug 05 10:09:39.951482 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] Traceback (most recent call last):
[Mon Aug 05 10:09:39.951546 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/mysite/mysite/wsgi.py", line 16, in <module>
[Mon Aug 05 10:09:39.951552 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] application = get_wsgi_application()
[Mon Aug 05 10:09:39.951564 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Aug 05 10:09:39.951569 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] django.setup(set_prefix=False)
[Mon Aug 05 10:09:39.951577 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/__init__.py", line 19, in setup
[Mon Aug 05 10:09:39.951597 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Aug 05 10:09:39.951607 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 79, in __getattr__
[Mon Aug 05 10:09:39.951612 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] self._setup(name)
[Mon Aug 05 10:09:39.951619 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 66, in _setup
[Mon Aug 05 10:09:39.951623 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] self._wrapped = Settings(settings_module)
[Mon Aug 05 10:09:39.951630 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 157, in __init__
[Mon Aug 05 10:09:39.951634 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Aug 05 10:09:39.951640 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Mon Aug 05 10:09:39.951644 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Aug 05 10:09:39.951651 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Aug 05 10:09:39.951657 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Aug 05 10:09:39.951664 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Mon Aug 05 10:09:39.951671 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Mon Aug 05 10:09:39.951678 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Aug 05 10:09:39.951696 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Aug 05 10:09:39.951704 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Mon Aug 05 10:09:39.951725 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] ImportError: No module named 'mysite'
[Mon Aug 05 10:52:33.048933 2019] [mpm_prefork:notice] [pid 11931] AH00169: caught SIGTERM, shutting down
mysite.conf edit
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /home/username/development/mysite
WSGIScriptAlias / /home/username/development/mysite/mysite/wsgi.py
WSGIDaemonProcess mydomain.com python-home=/home/username/development/venv python-path=/home/username/developement/mysite
WSGIProcessGroup mydomain.com
<directory /home/username/development/mysite>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/username/development/mysite/website/static/
<Directory /home/username/development/mysite/website/static>
Require all granted
</Directory>
</VirtualHost>

Elastic Beanstalk won't find/use my requirements.txt file and so it cannot find the module "django"

I'm trying to deploy a python web app using django and have successfully setup the EB environment but for some reason, it's not using my requirements.txt file to install the required modules (django and pytz). I see no reference to an invalid requirements.txt so I don't think that's the issue. Here is a file hierarchy and the latest log.
FirstWebApp/
.elasticbeanstalk/
config.yml
mysite/
#..
polls/
#..
db.sqlite3
manage.py
requirements.txt
[Sat Sep 01 21:08:01.508757 2018] [mpm_prefork:notice] [pid 7866] AH00169: caught SIGTERM, shutting down
[Sat Sep 01 21:08:02.599699 2018] [suexec:notice] [pid 11160] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Sat Sep 01 21:08:02.615594 2018] [so:warn] [pid 11160] AH01574: module wsgi_module is already loaded, skipping
[Sat Sep 01 21:08:02.617699 2018] [http2:warn] [pid 11160] 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.
[Sat Sep 01 21:08:02.617712 2018] [http2:warn] [pid 11160] AH02951: mod_ssl does not seem to be enabled
[Sat Sep 01 21:08:02.618263 2018] [lbmethod_heartbeat:notice] [pid 11160] AH02282: No slotmem from mod_heartmonitor
[Sat Sep 01 21:08:02.618326 2018] [:warn] [pid 11160] mod_wsgi: Compiled for Python/3.6.2.
[Sat Sep 01 21:08:02.618331 2018] [:warn] [pid 11160] mod_wsgi: Runtime using Python/3.6.5.
[Sat Sep 01 21:08:02.620634 2018] [mpm_prefork:notice] [pid 11160] AH00163: Apache/2.4.33 (Amazon) mod_wsgi/3.5 Python/3.6.5 configured -- resuming normal operations
[Sat Sep 01 21:08:02.620651 2018] [core:notice] [pid 11160] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Sat Sep 01 21:08:05.381076 2018] [:error] [pid 11165] [remote 127.0.0.1:0] mod_wsgi (pid=11165): Target WSGI script '/opt/python/current/app/mysite/wsgi.py' cannot be loaded as Python module.
[Sat Sep 01 21:08:05.381116 2018] [:error] [pid 11165] [remote 127.0.0.1:0] mod_wsgi (pid=11165): Exception occurred processing WSGI script '/opt/python/current/app/mysite/wsgi.py'.
[Sat Sep 01 21:08:05.381287 2018] [:error] [pid 11165] [remote 127.0.0.1:0] Traceback (most recent call last):
[Sat Sep 01 21:08:05.381309 2018] [:error] [pid 11165] [remote 127.0.0.1:0] File "/opt/python/current/app/mysite/wsgi.py", line 12, in <module>
[Sat Sep 01 21:08:05.381313 2018] [:error] [pid 11165] [remote 127.0.0.1:0] from django.core.wsgi import get_wsgi_application
[Sat Sep 01 21:08:05.381326 2018] [:error] [pid 11165] [remote 127.0.0.1:0] ModuleNotFoundError: No module named 'django'
[Sat Sep 01 21:08:06.384353 2018] [:error] [pid 11165] [remote 127.0.0.1:252] mod_wsgi (pid=11165): Target WSGI script '/opt/python/current/app/mysite/wsgi.py' cannot be loaded as Python module.
[Sat Sep 01 21:08:06.384403 2018] [:error] [pid 11165] [remote 127.0.0.1:252] mod_wsgi (pid=11165): Exception occurred processing WSGI script '/opt/python/current/app/mysite/wsgi.py'.
[Sat Sep 01 21:08:06.384505 2018] [:error] [pid 11165] [remote 127.0.0.1:252] Traceback (most recent call last):
[Sat Sep 01 21:08:06.384528 2018] [:error] [pid 11165] [remote 127.0.0.1:252] File "/opt/python/current/app/mysite/wsgi.py", line 12, in <module>
[Sat Sep 01 21:08:06.384531 2018] [:error] [pid 11165] [remote 127.0.0.1:252] from django.core.wsgi import get_wsgi_application
[Sat Sep 01 21:08:06.384560 2018] [:error] [pid 11165] [remote 127.0.0.1:252] ModuleNotFoundError: No module named 'django'
[Sat Sep 01 21:08:07.387609 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] mod_wsgi (pid=11165): Target WSGI script '/opt/python/current/app/mysite/wsgi.py' cannot be loaded as Python module.
[Sat Sep 01 21:08:07.387656 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] mod_wsgi (pid=11165): Exception occurred processing WSGI script '/opt/python/current/app/mysite/wsgi.py'.
[Sat Sep 01 21:08:07.387725 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] Traceback (most recent call last):
[Sat Sep 01 21:08:07.387744 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] File "/opt/python/current/app/mysite/wsgi.py", line 12, in <module>
[Sat Sep 01 21:08:07.387748 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] from django.core.wsgi import get_wsgi_application
[Sat Sep 01 21:08:07.387761 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] ModuleNotFoundError: No module named 'django'
[Sat Sep 01 21:08:08.390656 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] mod_wsgi (pid=11165): Target WSGI script '/opt/python/current/app/mysite/wsgi.py' cannot be loaded as Python module.
[Sat Sep 01 21:08:08.390700 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] mod_wsgi (pid=11165): Exception occurred processing WSGI script '/opt/python/current/app/mysite/wsgi.py'.
[Sat Sep 01 21:08:08.390770 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] Traceback (most recent call last):
[Sat Sep 01 21:08:08.390790 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] File "/opt/python/current/app/mysite/wsgi.py", line 12, in <module>
[Sat Sep 01 21:08:08.390793 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] from django.core.wsgi import get_wsgi_application
[Sat Sep 01 21:08:08.390807 2018] [:error] [pid 11165] [remote 127.0.0.1:2304] ModuleNotFoundError: No module named 'django'
I just had to commit the requirements.txt file. Django only looks at whatever files have been committed.

ImproperlyConfigured: Error loading psycopg2 module: No module named cffi

I developed a platform with django + wsgi + pypy + postgresql + postgis, everything works fine in development environment, but in production it sends error 500 and in the apache log it says ImproperlyConfigured: Error loading psycopg2 module: No module named cffi
my config apache:
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/plataform/project/project/wsgi.py
WSGIDaemonProcess project python-path=/home/user/plataform/project:/home/user/env/site-packages
WSGIProcessGroup project
WSGIPassAuthorization On
<Directory /home/user/plataform/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media /home/user/plataform/project/media/
Alias /static /home/user/plataform/project/static/
<Directory /home/user/plataform/project/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/user/plataform/project/media>
Require all granted
</Directory>
my pip freeze
cffi==1.6.0
Django==1.11.7
django-cors-headers==2.1.0
django-filter==1.1.0
djangorestframework==3.7.3
greenlet==0.4.9
Markdown==2.6.9
olefile==0.44
Pillow==4.3.0
psycopg2cffi==2.7.7
python-stdnum==1.7
pytz==2017.3
readline==6.2.4.1
six==1.11.0
uWSGI==2.0.15
Log Apache:
[Tue Dec 12 11:15:49.727998 2017] [wsgi:warn] [pid 4975:tid 139854422423424] mod_wsgi: Compiled for Python/2.7.11.
[Tue Dec 12 11:15:49.728151 2017] [wsgi:warn] [pid 4975:tid 139854422423424] mod_wsgi: Runtime using Python/2.7.12.
[Tue Dec 12 11:15:49.729853 2017] [mpm_event:notice] [pid 4975:tid 139854422423424] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Tue Dec 12 11:15:49.729893 2017] [core:notice] [pid 4975:tid 139854422423424] AH00094: Command line: '/usr/sbin/apache2'
[Tue Dec 12 11:15:59.608678 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] mod_wsgi (pid=4978): Target WSGI script '/home/user/plataform/project/project/wsgi.py' cannot be loaded as Python module.
[Tue Dec 12 11:15:59.608785 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] mod_wsgi (pid=4978): Exception occurred processing WSGI script '/home/user/plataform/project/project/wsgi.py'.
[Tue Dec 12 11:15:59.608821 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] Traceback (most recent call last):
[Tue Dec 12 11:15:59.608859 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/plataform/project/project/wsgi.py", line 16, in <module>
[Tue Dec 12 11:15:59.608957 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] application = get_wsgi_application()
[Tue Dec 12 11:15:59.608974 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Tue Dec 12 11:15:59.609017 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] django.setup(set_prefix=False)
[Tue Dec 12 11:15:59.609032 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/__init__.py", line 27, in setup
[Tue Dec 12 11:15:59.609090 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] apps.populate(settings.INSTALLED_APPS)
[Tue Dec 12 11:15:59.609112 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/apps/registry.py", line 108, in populate
[Tue Dec 12 11:15:59.609256 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] app_config.import_models()
[Tue Dec 12 11:15:59.609277 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/apps/config.py", line 202, in import_models
[Tue Dec 12 11:15:59.609366 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] self.models_module = import_module(models_module_name)
[Tue Dec 12 11:15:59.609389 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Dec 12 11:15:59.609451 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] __import__(name)
[Tue Dec 12 11:15:59.609465 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/auth/models.py", line 4, in <module>
[Tue Dec 12 11:15:59.609580 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
[Tue Dec 12 11:15:59.609593 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
[Tue Dec 12 11:15:59.609671 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] class AbstractBaseUser(models.Model):
[Tue Dec 12 11:15:59.609686 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/base.py", line 124, in __new__
[Tue Dec 12 11:15:59.610123 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] new_class.add_to_class('_meta', Options(meta, app_label))
[Tue Dec 12 11:15:59.610139 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/base.py", line 325, in add_to_class
[Tue Dec 12 11:15:59.610194 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] value.contribute_to_class(cls, name)
[Tue Dec 12 11:15:59.610216 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/options.py", line 214, in contribute_to_class
[Tue Dec 12 11:15:59.610429 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Tue Dec 12 11:15:59.610446 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/__init__.py", line 33, in __getattr__
[Tue Dec 12 11:15:59.610507 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Tue Dec 12 11:15:59.610521 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/utils.py", line 211, in __getitem__
[Tue Dec 12 11:15:59.610608 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] backend = load_backend(db['ENGINE'])
[Tue Dec 12 11:15:59.610621 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/utils.py", line 115, in load_backend
[Tue Dec 12 11:15:59.610637 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] return import_module('%s.base' % backend_name)
[Tue Dec 12 11:15:59.610646 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Dec 12 11:15:59.610660 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] __import__(name)
[Tue Dec 12 11:15:59.610668 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 2, in <module>
[Tue Dec 12 11:15:59.610706 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] from django.db.backends.postgresql.base import (
[Tue Dec 12 11:15:59.610733 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
[Tue Dec 12 11:15:59.610870 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[Tue Dec 12 11:15:59.610901 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] ImproperlyConfigured: Error loading psycopg2 module: No module named cffi
I made a clean installation of pypy and created a new virtual environment, then changed the conf. of apache for this
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/plataform/project/project/wsgi.py
WSGIDaemonProcess project python-path=/home/user/plataform/project:/home/user/env/site-packages
WSGIProcessGroup project
WSGIPassAuthorization On
<Directory /home/user/plataform/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media/ /home/user/plataform/project/media
Alias /static/ /home/user/plataform/project/static
<Directory /home/user/plataform/project/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/user/plataform/project/media>
Require all granted
</Directory>
</Virtualhost>
and everything worked well

Django-WSGI setup causing permission denied issues on CentOS 7

I'm new in the world of Django. I've been working on setting up WSGI to serve my Django project. It is working fine on my personal machine but on the server I'm having a hard time to setup.
I'm using logging in Django. But it is giving 'permission denied' error. But when I place all my log files in the '/tmp' folder, it works fine.
Similar issue is with the 'db.sqlite3' file (that is my DB file which the Django uses).
Please help me out in resolving the issue.
Following information may be useful to help me out :
OS : CentOS 7
Python : 2.7.5
Apache : 2.4.6
MOD_WSGI : 3.4
Following is the WSGI's error_log:
[Wed Aug 05 01:53:31.661156 2015] [:error] [pid 32177] [remote 192.168.40.142:184] Traceback (most recent call last):
[Wed Aug 05 01:53:31.661192 2015] [:error] [pid 32177] [remote 192.168.40.142:184] File "/var/www/html/portals/wsgi.py", line 18, in <module>
[Wed Aug 05 01:53:31.661254 2015] [:error] [pid 32177] [remote 192.168.40.142:184] application = get_wsgi_application()
[Wed Aug 05 01:53:31.661274 2015] [:error] [pid 32177] [remote 192.168.40.142:184] File "/var/www/html/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Wed Aug 05 01:53:31.661313 2015] [:error] [pid 32177] [remote 192.168.40.142:184] django.setup()
[Wed Aug 05 01:53:31.661330 2015] [:error] [pid 32177] [remote 192.168.40.142:184] File "/var/www/html/venv/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
[Wed Aug 05 01:53:31.661361 2015] [:error] [pid 32177] [remote 192.168.40.142:184] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Wed Aug 05 01:53:31.661378 2015] [:error] [pid 32177] [remote 192.168.40.142:184] File "/var/www/html/venv/lib/python2.7/site-packages/django/utils/log.py", line 86, in configure_logging
[Wed Aug 05 01:53:31.661451 2015] [:error] [pid 32177] [remote 192.168.40.142:184] logging_config_func(logging_settings)
[Wed Aug 05 01:53:31.661483 2015] [:error] [pid 32177] [remote 192.168.40.142:184] File "/usr/lib64/python2.7/logging/config.py", line 803, in dictConfig
[Wed Aug 05 01:53:31.661519 2015] [:error] [pid 32177] [remote 192.168.40.142:184] dictConfigClass(config).configure()
[Wed Aug 05 01:53:31.661537 2015] [:error] [pid 32177] [remote 192.168.40.142:184] File "/usr/lib64/python2.7/logging/config.py", line 585, in configure
[Wed Aug 05 01:53:31.661584 2015] [:error] [pid 32177] [remote 192.168.40.142:184] '%r: %s' % (name, e))
[Wed Aug 05 01:53:31.661643 2015] [:error] [pid 32177] [remote 192.168.40.142:184] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/var/www/html/portals/logs/debug.log'
You need to fix permissions with the chmod command, like this:
chmod 775 /var/www/html/portals/logs/debug.log
chown username:apache /var/www/html/portals/logs/debug.log
If group is www-data,change apache to www-data
If the security not matters.You can try
chmod 777 /var/www/html/portals/logs/debug.log

deploying a Django app on apache2 error

I tried to deplpoy django project to work with apache and mod_wsgi but get this error:
ImportError: DLL load failed: %1 n\x92est pas une application Win32 valide
this is my wsgi.py file
import os, sys
sys.path.append('C:/Users/abda/applica/projet/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projet.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
this is the code in httpd.conf file
WSGIScriptAlias /t C:/Users/abda/applica/test.py
WSGIScriptAlias / C:/Users/abda/applica/projet/projet/wsgi.py
Alias /media/ C:/Users/abda/applica/projet/www/media/
Alias /static/ C:/Users/abda/applica/projet/www/static/
<Directory /abda/applica/projet/projet>
<Files wsgi.py>
Require all granted
</Files>
</Directory>`
this the log error returned
[Mon May 12 15:00:17.476950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] mod_wsgi (pid=13888): Target WSGI script 'C:/Users/abda/applica/projet/projet/wsgi.py' cannot be loaded as Python module.
[Mon May 12 15:00:17.476950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] mod_wsgi (pid=13888): Exception occurred processing WSGI script 'C:/Users/abda/applica/projet/projet/wsgi.py'.
[Mon May 12 15:00:17.476950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] Traceback (most recent call last):
[Mon May 12 15:00:17.476950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:/Users/abda/applica/projet/projet/wsgi.py", line 11, in <module>
[Mon May 12 15:00:17.477950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] from django.core.wsgi import get_wsgi_application
[Mon May 12 15:00:17.477950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:\\Python27\\lib\\site-packages\\django\\core\\wsgi.py", line 1, in <module>
[Mon May 12 15:00:17.477950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] from django.core.handlers.wsgi import WSGIHandler
[Mon May 12 15:00:17.477950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 9, in <module>
[Mon May 12 15:00:17.478950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] from django import http
[Mon May 12 15:00:17.478950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:\\Python27\\lib\\site-packages\\django\\http\\__init__.py", line 1, in <module>
[Mon May 12 15:00:17.478950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] from django.http.cookie import SimpleCookie, parse_cookie
[Mon May 12 15:00:17.478950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:\\Python27\\lib\\site-packages\\django\\http\\cookie.py", line 3, in <module>
[Mon May 12 15:00:17.479950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] from django.utils.encoding import force_str
[Mon May 12 15:00:17.479950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:\\Python27\\lib\\site-packages\\django\\utils\\encoding.py", line 10, in <module>
[Mon May 12 15:00:17.480950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] from urllib import quote
[Mon May 12 15:00:17.480950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:\\Python27\\Lib\\urllib.py", line 26, in <module>
[Mon May 12 15:00:17.481950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] import socket
[Mon May 12 15:00:17.482950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] File "C:\\Python27\\Lib\\socket.py", line 47, in <module>
[Mon May 12 15:00:17.482950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] import _socket
[Mon May 12 15:00:17.482950 2014] [:error] [pid 13888:tid 768] [client 127.0.0.1:60886] ImportError: DLL load failed: %1 n\x92est pas une application Win32 valide.
I use django1.5 and apache2.4
Is your Apache HTTP server compiled for 32 bit or 64 bit processor? It looks like a DLL is looking for a 32-bit version of Windows.
solved
All apache/ wsgi_mod.so and python need to be 64 bit or 32 bit http://modwsgi.readthedocs.org/en/latest/installation-guides/installation-on-windows.html
Can you try using the 32-bit Apache Http Server? XAMPP has one that might make it easier to test.