Python Forum
Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi)
#1
I’m having some issues deploying Django.

Here is my site: https://daniel496.agency/

I’m running a Digital Ocean Droplet with Ubuntu 14.04 and Python v3.4 with Django 2.0.2 installed.

In this post first I share what errors I am encountering, then what I think is the issue is and then what I’ve tried to resolve the issue. At the end of this post are my configuration files like ssl.conf and wsgi.py.

Before I begin, I think the issue could be that my project folder on my local machine is named: first_project_attemp. But on my remote server, the project folder is named, cel2fah. I copied the contents locally to my remote host and now trying to iron out the issues.

Here I go. If you access my site linked to above, right now it is showing:

Quote:Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.7 (Ubuntu) Server at daniel496.agency Port 443

Here are the last ~50 lines of my apache error log file: https://pastebin.com/UPsTmf28

I’m thinking that there could be a potential conflict between libapache2-mod-wsgi and libapache2-mod-wsgi-py3. I encountered a similar issue a few weeks ago. There are apparently still traces of libapache2-mod-wsgi (for Python 2.7) still flagged as active on my system given that $ sudo dpkg -s libapache2-mod-wsgi prints:

Quote:Package: libapache2-mod-wsgi
Status: deinstall ok config-files
Priority: optional
Section: httpd
Installed-Size: 242
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Source: mod-wsgi
Version: 3.4-4ubuntu2.1.14.04.2
Config-Version: 3.4-4ubuntu2.1.14.04.2
Provides: httpd-wsgi
Depends: libc6 (>= 2.14), libpython2.7 (>= 2.7), apache2-api-20120211, python (>= 2.7), python (<< 2.8)
Conffiles:
/etc/apache2/mods-available/wsgi.load 06d2b4d2c95b28720f324bd650b7cbd6 obsolete
/etc/apache2/mods-available/wsgi.conf c4ca5be35d0820b5d5cc2892097b476b obsolete
Description: Python WSGI adapter module for Apache
The mod_wsgi adapter is an Apache module that provides a WSGI (Web Server
Gateway Interface, a standard interface between web server software and
web applications written in Python) compliant interface for hosting Python
based web applications within Apache. The adapter provides significantly
better performance than using existing WSGI adapters for mod_python or CGI.
.
This package provides module for Python 2.X.
Homepage: http://www.modwsgi.org/
Original-Maintainer: Debian Python Modules Team <[email protected]>

However when I go to remove it, it says it’s not installed:

Error:
$ sudo apt remove libapache2-mod-wsgi Reading package lists... Done Building dependency tree Reading state information... Done Package 'libapache2-mod-wsgi' is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 44 not upgraded. $
More to the point, when invoking this as root:

Quote:apache2ctl -t -D DUMP_MODULES

...it lists what modules apache2 has loaded. And libapache2-mod-wsgi (for Python version 2) is included. So I Google ‘how to remove apache modules’ which turns up this SO post: https://stackoverflow.com/questions/9288...he2-module
So I set out to rename my libapache2-mod-wsgi.so (for Python version 2) from my apache2 modules directory inside /usr/lib. I see a symlink mod_wsgi.so which refers to mod_wsgi.so-3.4:

Quote:<user>@<host>:/usr/lib/apache2/modules$ ls -la mod_wsgi*
lrwxrwxrwx 1 root root 15 Nov 18 2014 mod_wsgi.so -> mod_wsgi.so-3.4
-rw-r--r-- 1 root root 174448 Nov 18 2014 mod_wsgi.so-3.4
<user>@<host>:/usr/lib/apache2/modules$

So is my Apache serving the libapache2-mod-wsgi module for python2 or just for python3 or what?

What else can you people determine could be the issue here?

Here is my wsgi.py:

"""
WSGI config for first_project_attempt project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os
import sys
from django.core.wsgi import get_wsgi_application

sys.path.append('/home/tranq/cel2fah/cel2fah')
# NEW:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cel2fah.settings")

# OLD:
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "first_project_attempt.settings")

application = get_wsgi_application()
And my ssl.conf:

Quote:<IfModule mod_ssl.c>
<VirtualHost *:443>

ServerAdmin [email protected]
ServerName daniel496.agency
ServerAlias www.daniel496.agency
# DocumentRoot /var/www/html/daniel496.agency/public_html

# ErrorLog ${APACHE_LOG_DIR}/error.log
ErrorLog ${APACHE_LOG_DIR}/daniel496/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# Django project
Alias /static /home/tranq/cel2fah/static
<Directory /home/tranq/cel2fah/static>
Require all granted
</Directory>

<Directory /home/tranq/cel2fah/cel2fah>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

WSGIDaemonProcess cel2fah2 python-home=/home/tranq/cel2fah/venv
WSGIProcessGroup cel2fah2
WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/daniel496.agency/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/daniel496.agency/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/daniel496.agency/chain.pem

</VirtualHost>
</IfModule>

Thanks for your attention.
Reply


Messages In This Thread
Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi) - by Drone4four - Mar-08-2018, 06:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  deploying python script on a server rickyrt 0 1,516 Aug-31-2021, 04:03 PM
Last Post: rickyrt
  Django project deployed to Heroku: Postgres security Drone4four 0 1,962 Mar-26-2021, 10:17 AM
Last Post: Drone4four
  creating an exe file for a python django project Sanjish 0 2,659 Dec-27-2020, 07:33 AM
Last Post: Sanjish
  category and subcategory into django project dhirendra007 0 2,039 Dec-26-2020, 10:33 AM
Last Post: dhirendra007
  cant access root environment folder from django folder using __init__.py Sanjish 0 1,949 Dec-25-2020, 05:56 AM
Last Post: Sanjish
  WSGI Multi processing. simbha 1 2,873 May-05-2020, 10:34 AM
Last Post: pyzyx3qwerty
  wsgi server ports chrisdb 3 3,363 Feb-26-2020, 04:24 PM
Last Post: snippsat
  Django project with a setup.py script. That do you think? axju 0 1,664 Oct-22-2019, 10:06 PM
Last Post: axju
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,412 Jun-30-2019, 12:21 AM
Last Post: scidam
  WSGI server vs Web Server chrisdb 24 10,747 May-29-2019, 02:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020