Search code examples
pythondjangoherokucpanelwsgi

404 Error in Django Deployment with Cpanel


I have recently deployed my django application to my Linux CPanel-Shared hosting. After testing all works very well in development but soon after deploying, my application displays 404 Not Found pages every time a user tries to navigate to a URL (including the in-built Django Admin panel).

Here is my deployment website: https://covid19.africansurveyors.net

I contacted my hosting service provider to check for me where the problem could be but unfortunately it was not resolved as they mentioned about code error. So I then took my application to Heroku and managed to deploy.

The URL to the Heroku App which is still the same app is: https://covid19zwe.herokuapp.com/. The application works perfectly fine on Heroku, but fails to run well on CPanel Shared hosting.

I also checked the --tail of my server log files this is what came up.

App 2247037 output: wsgi = imp.load_source('wsgi', 'passenger_wsgi.py')
App 2247037 output:   File "/home/<my_username>/virtualenv/public_html/covid19.africansurveyors.net/3.7/lib64/python3.7/imp.py", line 169, in load_source
App 2247037 output:     
App 2247037 output: module = _exec(spec, sys.modules[name])
App 2247037 output:   File "<frozen importlib._bootstrap>", line 623, in _exec
App 2247037 output:   File "<frozen importlib._bootstrap>", line 568, in _init_module_attrs
App 2247037 output:   File "<frozen importlib._bootstrap>", line 409, in cached
App 2247037 output:   File "<frozen importlib._bootstrap_external>", line 372, in _get_cached
App 2247037 output:   File "<frozen importlib._bootstrap_external>", line 296, in cache_from_source
App 2247037 output: RecursionError
App 2247037 output: : maximum recursion depth exceeded while calling a Python object
App 2388434 output: /opt/passenger-5.3.7-9.el6.cloudlinux/src/helper-scripts/wsgi-loader.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
App 2388434 output:   import sys, os, io, re, imp, threading, signal, traceback, socket, select, struct, logging, errno
App 436449 output: /opt/passenger-5.3.7-9.el6.cloudlinux/src/helper-scripts/wsgi-loader.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
App 436449 output:   import sys, os, io, re, imp, threading, signal, traceback, socket, select, struct, logging, errno
App 439960 output: /opt/passenger-5.3.7-9.el6.cloudlinux/src/helper-scripts/wsgi-loader.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
App 439960 output:   import sys, os, io, re, imp, threading, signal, traceback, socket, select, struct, logging, errno

I have configured the WSGI also in the passenger_wsgi.py file this way

import os
import sys
from covid.wsgi import application

Where my apps name is covid

I am not sure what really is going on. If anyone could assist I would really appreciate.


Solution

  • I encountered the same issue then resolve it like this.

    passenger_wsgi.py

    from flask_app import app as application
    

    flask_app.py

    from flask import Flask
    from werkzeug.middleware.proxy_fix import ProxyFix
    app = Flask(__name__)
    app.wsgi_app = ProxyFix(app.wsgi_app)
    app.config.from_pyfile("config/settings.py")
    init_app(app)
    

    CPanel config:

    • Application root: <root_app_dir>
    • Application startup file: passenger_wsgi.py
    • Application Entry point: flask_app
    • Passenger log file: <root_dir>/passenger.logs