Migrating Django from FCGID to Passenger

If you've previously set up a Django-based website using FCGID, from early 2018 you will need to migrate to the newer Passenger-based WSGI setup as we will be ending support for FCGID early in the year. This process is very simple, and requires only small changes to your existing setup. Note that these instructions assume you set up your Django site using our old FCGI instructions. Please get in touch if you require any assistance.

  1. First create a new file in your ~/django/ directory called passenger_wsgi.py containing the following:

    import sys, os
    # Add a custom Python path.
    sys.path.insert(0, "/home/username/django/")
    # Set the DJANGO_SETTINGS_MODULE environment variable.
    os.environ['DJANGO_SETTINGS_MODULE'] = "projectname.settings"

    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()

    Replacing the username, virtualenv name, and projectname with your own values.

  2. Next, open your .htaccess file and find the following directives:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /django.fcgi/$1 [QSA,L]

    Replace these with the following:

    PassengerAppRoot "/home/username/django/"
    PassengerBaseURI "/"
    PassengerPython "/home/username/.virtualenvs/virtualenv/bin/python"

    Inserting your username and Python virtualenv name. Make sure the PassengerAppRoot contains the path to the parent directory containing your Django project directory.

And you should be all set! You can now delete your old django.fcgi file.

Note: Any index.html or index.php files will take precedence over Passenger, which was not the case with FCGID. Make sure to move or rename any such files if you aren't using them.

  • 0 Users Found This Useful
Was this answer helpful?

Powered by WHMCompleteSolution