I try deploying Django in apache2 with python 3.4, but send error 500.
apache error.log:
[Sat May 13 15:56:53.638802 2017] [mpm_event:notice] [pid 3610:tid 140692947613568] AH00489: Apache/2.4.12 (Ubuntu) mod_wsgi/4.3.0 Python/3.4.3+ configured -- resuming normal operations
[Sat May 13 15:56:53.638897 2017] [core:notice] [pid 3610:tid 140692947613568] AH00094: Command line: '/usr/sbin/apache2'
[Sat May 13 15:56:56.622523 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] mod_wsgi (pid=3613): Target WSGI script '/var/www/html/reportado-plataforma/reportalo/wsgi.py' cannot be loaded as Python module.
[Sat May 13 15:56:56.622610 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] mod_wsgi (pid=3613): Exception occurred processing WSGI script '/var/www/html/reportado-plataforma/reportalo/wsgi.py'
[Sat May 13 15:56:56.622646 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] Traceback (most recent call last):
[Sat May 13 15:56:56.622842 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] File "/var/www/html/reportado-plataforma/reportalo/wsgi.py", line 12, in <module>
[Sat May 13 15:56:56.622851 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] from django.core.wsgi import get_wsgi_application
[Sat May 13 15:56:56.622876 2017] [wsgi:error] [pid 3613:tid 140692834260736] [remote 181.75.140.109:26259] ImportError: No module named 'django'
I installed
sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
my VirtualHost:
WSGIScriptAlias / /var/www/html/reportado-plataforma/reportalo/wsgi.py
WSGIDaemonProcess reportalo python-path=/var/www/html/reportado-plataforma:/root/env/lib/python3.4/site-packages
WSGIProcessGroup reportalo
WSGIPassAuthorization On
virtualhost directory:
<Directory /var/www/html/reportado-plataforma/reportalo>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
my environment:
appdirs==1.4.3
Django==1.11.1
django-cors-headers==2.0.2
django-filter==1.0.2
django-geoposition==0.3.0
django-location-field==2.0.3
djangorestframework==3.6.2
djangorestframework-gis==0.11.1
Markdown==2.6.8
olefile==0.44
packaging==16.8
Pillow==4.1.1
psycopg2==2.7.1
pyparsing==2.2.0
pytz==2017.2
six==1.10.0
uWSGI==2.0.15
The user that Apache runs your code as is unlikely to have the ability to see anything under the /root directory. Usually only root can see into that directory. Place your application Python virtual environment somewhere else.
Also read:
http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
for the recommended way of setting up a Python virtual environment with mod_wsgi. Use python-home as documented and not python-path.
Related
I'm trying to deploy my django application on my remote server, but I'm getting an http 500 internal server error.
Here are the configurations I made:
Structure file
/home/ubuntu/project/env (virtualenv folder)
bin
include
lib
/home/ubuntu/project/
|- manage.py
| - env
| - my_project
/home/ubuntu/project/my_project
|__init__.py
|settings.py
|urls.py
|wsgi.py
Fichier 000-default.conf
<VirtualHost *:80>
WSGIDaemonProcess myproject python-home=/home/ubuntu/project/env python-
path=/home/ubuntu/project/my_project
WSGIProcessGroup myproject
WSGIScriptAlias / /home/ubuntu/project/my_project/wsgi.py
<Directory /home/ubuntu/project/my_project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Error log
[Fri Dec 30 11:28:18.988904 2022] [wsgi:error] [pid 31289:tid 140473618372288] [remote
41.82.143.41:50428] File "/home/ubuntu/project/my_project/wsgi.py", line 12, in <module>
[Fri Dec 30 11:28:18.988915 2022] [wsgi:error] [pid 31289:tid 140473618372288] [remote
41.82.143.41:50428] from django.core.wsgi import get_wsgi_application
[Fri Dec 30 11:28:18.988933 2022] [wsgi:error] [pid 31289:tid 140473618372288] [remote
41.82.143.41:50428] ModuleNotFoundError: No module named 'django'
[Fri Dec 30 11:28:19.164861 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote
41.82.143.41:50427] mod_wsgi (pid=31289): Failed to exec Python script file
'/home/ubuntu/project/my_project/wsgi.py'.
[Fri Dec 30 11:28:19.164958 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote
41.82.143.41:50427] mod_wsgi (pid=31289): Exception occurred processing WSGI script
'/home/ubuntu/project/my_project/wsgi.py'.
[Fri Dec 30 11:28:19.165130 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote
41.82.143.41:50427] Traceback (most recent call last):
[Fri Dec 30 11:28:19.165172 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote
41.82.143.41:50427] File "/home/ubuntu/project/my_project/wsgi.py", line 12, in <module>
[Fri Dec 30 11:28:19.165183 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote
41.82.143.41:50427] from django.core.wsgi import get_wsgi_application
[Fri Dec 30 11:28:19.165212 2022] [wsgi:error] [pid 31289:tid 140473651943104] [remote
41.82.143.41:50427] ModuleNotFoundError: No module named 'django'
I then used this process : make custom versions of Python and mod_wsgi ourselves.
apt install apache2 apache2-dev
wget https://codeload.github.com/GrahamDumpleton/mod_wsgi/tar.gz/4.9.4
tar xvfz 4.9.4
cd mod_wsgi-4.9.4
./configure --with-python=[your python path]
## For example: ./configure --with-python=/usr/bin/python3.10
sudo make
sudo make install
## Finally:
sudo systemctl reload apache2
I use python 3.10 and apache2
and the error still persists (500 internal server error)
I do not know what to do ???
I found the answer by adding to my wsgi.py file the path where django is installed
I am trying to deploy a Django application using apache and i am getting the following error
[Fri Oct 08 07:55:44.393237 2021] [wsgi:error] [pid 12424:tid 140450959271680] mod_wsgi (pid=12424): Target WSGI script '/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py' cannot be loaded as Python module.
[Fri Oct 08 07:55:44.393281 2021] [wsgi:error] [pid 12424:tid 140450959271680] mod_wsgi (pid=12424): Exception occurred processing WSGI script '/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py'.
[Fri Oct 08 07:55:44.393408 2021] [wsgi:error] [pid 12424:tid 140450959271680] Traceback (most recent call last):
[Fri Oct 08 07:55:44.393430 2021] [wsgi:error] [pid 12424:tid 140450959271680] File "/home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py", line 12, in <module>
[Fri Oct 08 07:55:44.393435 2021] [wsgi:error] [pid 12424:tid 140450959271680] from django.core.wsgi import get_wsgi_application
[Fri Oct 08 07:55:44.393446 2021] [wsgi:error] [pid 12424:tid 140450959271680] ModuleNotFoundError: No module named 'django'
My apache virtual host
<VirtualHost *:80>
DocumentRoot /home/preinstall/hx_preinstaller
ErrorLog ${APACHE_LOG_DIR}/preinstall_error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/preinstall/hx_preinstaller/hx_preinstaller>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /home/preinstall/hx_preinstaller>
Require all granted
</Directory>
WSGIDaemonProcess preinstall python-path=/home/preinstall/hx_preinstaller:/home/preinstall/.local/lib/python3.6/site-packages
WSGIProcessGroup preinstall
WSGIPassAuthorization On
WSGIScriptAlias / /home/preinstall/hx_preinstaller/hx_preinstaller/wsgi.py
</VirtualHost>
What should i do?..
Maybe its a python version mismatch , or you didnt add correctly the python path to the appache.conf .
go check this post to know more about this error ->>> link
i get this eror :
sudo service apache2 restart :
[Thu Apr 18 13:11:02.687353 2019] [mpm_event:notice] [pid 2135:tid 140232732096384] AH00491: caught SIGTERM, shutting down
[Thu Apr 18 13:11:03.694739 2019] [ssl:warn] [pid 2300:tid 139990910658432] AH01909: ip-*.*.*.*.ec2.internal:443:0 server certificate does NOT include an ID which matches the server name
[Thu Apr 18 13:11:03.702921 2019] [ssl:warn] [pid 2301:tid 139990910658432] AH01909: ip-*.*.*.*.ec2.internal:443:0 server certificate does NOT include an ID which matches the server name
[Thu Apr 18 13:11:03.703014 2019] [wsgi:warn] [pid 2301:tid 139990910658432] mod_wsgi: Compiled for Python/2.7.11.
[Thu Apr 18 13:11:03.703018 2019] [wsgi:warn] [pid 2301:tid 139990910658432] mod_wsgi: Runtime using Python/2.7.12.
then i entered the domain we site and got in /var/log/apache2/error.log:
[Thu Apr 18 13:11:03.703598 2019] [mpm_event:notice] [pid 2301:tid 139990910658432] AH00489: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Thu Apr 18 13:11:03.703617 2019] [core:notice] [pid 2301:tid 139990910658432] AH00094: Command line: '/usr/sbin/apache2'
[Thu Apr 18 13:11:10.014862 2019] [wsgi:error] [pid 2304:tid 139990600201984] err : No module named boto
[Thu Apr 18 13:11:10.015214 2019] [wsgi:error] [pid 2304:tid 139990600201984] [client 81.218.184.134:30333] mod_wsgi (pid=2304): Target WSGI script '/home/ubuntu/path/to/my_project/src/my_project/wsgi.py' does not contain WSGI application 'application'.
i am working with ubuntu 16.0.4 apache2 and nod_wsgi on AWS EC2, start to get up project that is working (not a new project)
printing the Exception in my wsgi.py i get :
No module named boto from
try:
application = get_wsgi_application()
except Exception as e:
print "err : {}".format(e)
but i have boto install :
# pip freeze | grep boto
You are using pip version 8.1.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
boto==2.49.0
boto3==1.9.112
botocore==1.12.16
here are other files that i configured according to https://docs.djangoproject.com/en/2.2/topics/install/ :
# cat /etc/apache2/mods-enabled/wsgi.load
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
# cat /etc/apache2/mods-enabled/wsgi.conf
<IfModule mod_wsgi.c>
WSGIPassAuthorization on
WSGIScriptAlias / /home/ubuntu/path/to/wsgi.py
WSGIPythonPath /home/ubuntu/path/to/my_project
<VirtualHost *:80>
<Directory "/home/ubuntu/path/to//my_project/">
Require all granted
</Directory>
</VirtualHost>
..
</IfModule>
It looks like you could be missing the site-packages directory in your WSGIPythonPath directive. I usually define the python path as part of the WSGIDaemonProcess directive:
WSGIDaemonProcess example \
display-name=example \
processes=2 threads=20 \
maximum-requests=10000 \
umask=0002 \
python-path=${SRV}/www:${SRV}/src:${SRV}/venv/prod_142/lib/python2.7/site-packages \
python-eggs=${SRV}/.python-eggs
WSGIScriptAlias / ${SRV}/www/example/wsgi.py \
process-group=example \
application-group=%{GLOBAL}
You can see a more full-featured virtualhost definition in the readme at https://github.com/datakortet/dkbuild-apacheconf (I'm the author).
the issue was that not all the python packages was installed , after installed all missing packages the website worked
Hi all i am using Apache mod_wsgi to deploy a python application but i am getting internal server error as:
[Fri Nov 17 17:26:01.285539 2017] [mpm_event:notice] [pid 25751:tid 140495002072960] AH00491: caught SIGTERM, shutting down
[Fri Nov 17 17:26:02.395406 2017] [so:warn] [pid 26122:tid 140693819524992] AH01574: module wsgi_module is already loaded, skipping
[Fri Nov 17 17:26:02.396961 2017] [wsgi:warn] [pid 26123:tid 140693819524992] mod_wsgi: Compiled for Python/2.7.11.
[Fri Nov 17 17:26:02.396983 2017] [wsgi:warn] [pid 26123:tid 140693819524992] mod_wsgi: Runtime using Python/2.7.12.
[Fri Nov 17 17:26:02.397621 2017] [mpm_event:notice] [pid 26123:tid 140693819524992] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Fri Nov 17 17:26:02.397650 2017] [core:notice] [pid 26123:tid 140693819524992] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 17 17:26:28.707573 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] mod_wsgi (pid=26126): Target WSGI script '/home/rajesh/mymapproxy/config.py' cannot be loaded as Python module.
[Fri Nov 17 17:26:28.707618 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] mod_wsgi (pid=26126): Exception occurred processing WSGI script '/home/rajesh/mymapproxy/config.py'.
[Fri Nov 17 17:26:28.707636 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] Traceback (most recent call last):
[Fri Nov 17 17:26:28.707655 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] File "/home/rajesh/mymapproxy/config.py", line 9, in
[Fri Nov 17 17:26:28.707703 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] from mapproxy.wsgiapp import make_wsgi_app
[Fri Nov 17 17:26:28.707747 2017] [wsgi:error] [pid 26126:tid 140693723956992] [client ::1:58008] ImportError: No module named mapproxy.wsgiapp
How can i fix this issue
Here is my apache configration: /etc/apche2/site-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias /mapproxy /home/rajesh/workspace/mymapproxy/config.py
WSGIApplicationGroup %{GLOBAL}
<Directory "/home/rajesh/workspace/mymapproxy/">
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
This is my /home/rajesh/workspace/mymapproxy/config.py
from mapproxy.wsgiapp import make_wsgi_app
application = make_wsgi_app(r'/etc/mapproxy.yaml')
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"