Migrating Django from FCGID to Passenger

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:

    #!/home/username/.virtualenvs/virtualenv/bin/python
    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?

Related Articles

Executing PHP scripts in a cron job

Using a cron job is a great way to automatically perform a task at regular intervals all the way...

Increasing PHP upload limit

By default the maximum file size you can upload via PHP is 2MB, but sometimes this isn't enough....

Checking PHP Settings

You can check the PHP settings for your account, or a particular directory in your account using...

Changing PHP Settings - Advanced

Our PHP configuration has been set to allow as many scripts as possible to run, but there are...

SSH Access

Secure Shell Handler is a command-line interface to the server, the majority of tasks possible...