Django with fastcgi
While it is possible to install Django on DCTIT servers, it is not a supported application, and we are unable to install it for you. It is recommended that you have a developer available to assist you with any issues that may arise while installing or using this software.
This article will cover installation, setting up Django projects, and managing your project:
On our shared and reseller accounts you will need to use Virtualenv to install a localized version of Django without root access. To start, you’ll need to set up and activate Virtualenv.
- Log into SSH with your cPanel credentials.
- Create and navigate to a temp directory for the installation:
- Download the latest version of Virtualnv:
- Extract the compressed install files into the temp directory:
- Navigate to the install files directory:
- Use Python to run the Virtualenv install:
- Navigate to the home directory:
- Remove the install files:
- Run find to check the contents of the directory before deleting it:
- After ensuring that the directoy is correct, delete it:
- Set up your virtual environment in the mydjango directory:
- Activate your mydjango Virtualenv:
Once this is complete you will now be working in a Virtualenv setting and your command prompt should look similar to this:
The best practice for exiting Virtualenv is to log out of SSH and then log back in to start a new session. You can do this and then re-activate and begin working from this environment at any time by once again entering this full command:
Next, to install Django. Please ensure that virtual environment is activated before proceeding:
- Check which PIP is being used. The output should indicate the pip file in the~/mydjango/bin/ directory:
- Begin by upgrading PIP:
- Install Django:
- Install Flup:
- Grant Executable permissions to the django-admin.py file:
Setting up Django Projects
In order to create a new Django project, make sure your virtual environment is active and run these commands replacing testproject with the name of the directory you wish the project to be run from.
- Create a new project:
- Override the default SCRIPT_NAME with the path to set it to index.fcgi:
- Navigate to the new project directory:
- Grant executable permissions to the manage.py file:
- Start the new app:
Managing your Project
In order to manage your project, you will need to set up an index file that you can access from your browser.
- Create index.fcgi and place it inside your public_html directory, or your desired document root.
- Change the file’s permissions to 0755.
- Edit the file and enter this code:
- Add the following
.htaccessrewrite rules to the .htaccess file in the same directory as your new index.fcgi file:
- Log into SSH.
- Navigate to your public_html directory:
- Copy the /static directory:
At this time, Django should now be correctly installed and you can manage your project by logging into your admin url:
Note: Replace mydomain.com with the domain you installed django to.