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
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 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.
I've set this up using a multitude of documentation and repeatedly get the same result. This particular one below is following https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/#daemon-mode exactly as it says. I need help!
[Sun Oct 09 14:52:09.208810 2016] [wsgi:warn] [pid 53237] mod_wsgi: Compiled for Python/3.5.1+.
[Sun Oct 09 14:52:09.208844 2016] [wsgi:warn] [pid 53237] mod_wsgi: Runtime using Python/3.5.2.
[Sun Oct 09 14:52:09.210835 2016] [mpm_prefork:notice] [pid 53237] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Sun Oct 09 14:52:09.210866 2016] [core:notice] [pid 53237] AH00094: Command line: '/usr/sbin/apache2'
[Sun Oct 09 14:52:09.245977 2016] [wsgi:error] [pid 53240] mod_wsgi (pid=53240): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Sun Oct 09 14:52:09.246021 2016] [wsgi:error] [pid 53240] mod_wsgi (pid=53240): Call to 'site.addsitedir()' failed for '/home/addohm/projects/rtservice/projectenv/lib/python2.7/site-packages'.
If You are trying to deploy Django web on EB with a single EC2 instance and want to configure SSL on that single EB instance instead of doing at ELB.
Step-1 Login to EC2 and do sudo yum install mod24_ssl.
Step-2 sudo vi /etc/httpd/conf.d/ssl.conf
Step-3 Paste below config
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/python/run/venv
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On
Listen 443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/pki/tls/certs/server.crt"
SSLCertificateKeyFile "/etc/pki/tls/certs/server.key"
Alias /static/ /opt/python/current/app/static/
<Directory /opt/python/current/app/static>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /opt/python/current/app/<yoursite>/wsgi.py
<Directory /opt/python/current/app>
Require all granted
</Directory>
WSGIDaemonProcess wsgi-ssl processes=1 threads=15 display-name=%{GROUP} \
python-home=/opt/python/run/venv/ \
python-path=/opt/python/current/app user=wsgi group=wsgi \
home=/opt/python/current/app
WSGIProcessGroup wsgi-ssl
Step-4
CERTIFICATE.crt > "/etc/pki/tls/certs/server.crt"
PRIVATE KEY.crt > "/etc/pki/tls/certs/server.key"
Step-5 Restart server
Try Https on your site, should be working fine.
So I am trying to deploy my django project on a windows server, using apache 2.4 with mod_wsgi and pythong 3.4. Before I configure httpd.conf and just try start apache with mod-wsgi installed, it works and show me that "it works" page. then I did the following configuration in httpd.conf:
# Change Python path used by the server.
WSGIPythonPath “/EquipmentCalibration”
# Make calls to http://localhost/ refer to the Python/WSGI-script located at the specified location.
WSGIScriptAlias / /EquipmentCalibration/equipcal/wsgi.py
# Make calls to http://localhost/static refer to the specified folder.
Alias /static/ /EquipmentCalibration/static
Alias /media/ /EquipmentCalibration/media
<Directory /EquipmentCalibration/static>
Require all granted
</Directory>
<Directory /EquipmentCalibration/media>
Require all granted
</Directory>
<Directory /EquipmentCalibration/equipcale>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
And then try to go to localhost:8080 (I changed the port from 80 to 8080), I got this error saying:
Forbidden
You don't have permission to access / on this server.
And below is the relevant error.log.
[Thu Sep 29 15:05:25.171920 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00456: Apache Lounge VC10 Server built: Jul 9 2016 11:59:00
[Thu Sep 29 15:05:25.171920 2016] [core:notice] [pid 7756:tid 528] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Thu Sep 29 15:05:25.171920 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00418: Parent: Created child process 7524
[Thu Sep 29 15:05:25.500078 2016] [wsgi:warn] [pid 7524:tid 456] mod_wsgi: Compiled for Python/3.4.2.
[Thu Sep 29 15:05:25.500078 2016] [wsgi:warn] [pid 7524:tid 456] mod_wsgi: Runtime using Python/3.4.3.
[Thu Sep 29 15:05:26.171978 2016] [mpm_winnt:notice] [pid 7524:tid 456] AH00354: Child: Starting 64 worker threads.
[Thu Sep 29 15:05:27.174429 2016] [mpm_winnt:notice] [pid 7636:tid 456] AH00364: Child: All worker threads have exited.
[Thu Sep 29 15:05:29.923754 2016] [authz_core:error] [pid 7524:tid 1108] [client ::1:55483] AH01630: client denied by server configuration: C:/EquipmentCalibration/equipcal/wsgi.py
Could somebody please help? TIA.
The section:
<Directory /EquipmentCalibration/equipcale>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
has a directory name which does match what is used in the WSGIScriptAlias directive. One uses equipcal and the other equipcale. They need to match in that segment name.
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