Hosting Your Django Projects on Bluehost!

Hosting Your Django Projects on Bluehost!

I wanted to host my Django apps on Bluehost, but there was no out of the box solution that I could find. I pieced together a temporary solution using an older release of Django from various sources.

Check out my other Django guides!

You can sign up for Bluehost by clicking this banner!

(Disclosure: Our website is a Bluehost affiliate and will receive a commission for purchases made through this link.)


1. Set up SSH for your Bluehost account

Check out SSH and SCP: Howto, tips & tricks over at the Linux Academy Blog for more details on SSH and SCP.

  1. Search ‘ssh’ from cpanel to access the ssh console
  2. Generate pub/private key pair on Bluehost, then download the private key and put in ~/.ssh (this seems backward, but for some reason, Bluehost insists on having both keys on their server)
  3. ssh bluehostusername@bluehosturl

 

2. Install python

Where homeX/your_username is your home path

You’ll also want to rename python27/bin/python2.7 to python27

NOTE: ./configure will check dependencies and other info about your system to ensure the software will install correctly. It will also generate a makefile to be used by the make command.

 

3. Install setuptools and pip

 

3.5. Install Your Database of Choice (default is sqlite3)

 

4. Install Django 1.8 and flup 1.0.3

NOTE: pip install Django will install Django 1.10, which does not have fastcgi.

If you are getting a 500 error because you installed Django 1.10, you can run the .fcgi file to see the Python error:

Perform the an uninstall and reinstall with a target version of Django to resolve the error:

If you installed the latest version of flup, you’ll get the error:

Again, perform an uninstall and target a specific version of flup:

5. Create myapp.fcgi

chmod myapp.fcgi

6. Create .htaccess

That should do it. When you hit your URL you should see a page not found error (this is good! There is no URL set up to point to the index, so a 404 is expected).

 

My File Tree

I have my project set up as a subdomain on my Bluehost account, but the process is the same if you are interested in using your main URL. Simply put the project directory at the root of public_html (i.e. public_html/myapp). Your URL would be maindomain/myapp.

My url here would be mysubdomain/myapp

subdomain_myapp_tree

 

Converting From fastcgi to wsgi

This works fine for Django 1.8, but what if we want to use the latest and greatest?

Well, fastcgi is no longer part of Django as of Django 1.9, because of lack of flup maintenance.

So ideally, we would convert to wsgi (which is what is used by Heroku, etc, anyway).

Here’s a starting point.

More on this once I’ve gotten it working!

 

 

Sources

I ran across a couple posts from a few years back detailing how to make it happen, but ran into issues because I didn’t specify older versions of things.

Python 2.7 + Django 1.4 on Bluehost

The main problem I ran into with this post was that it used older versions, so we have to specify these older versions when install Django and flup. Another minor point is the order of operations when creating the directory and the project. The project needs to be created inside the folder in public_html. (You can always move the project if you’ve created the project before the directory).

Tutorial: Installing Django on Shared Hosting Service Such as Bluehost.com

This one has some code formatting issues, so beware the copy pasta.

Bluehost’s Django troubleshooting page

This helped me to troubleshoot the error by pointing out that the .fcgi file can be executed manually from CLI.

StackOverflow, helpful as always

This post indicated I was using the wrong version of flup.

(Disclosure: Our website is a Bluehost affiliate and will receive a commission for purchases made through this link.)

10 thoughts on “Hosting Your Django Projects on Bluehost!

  1. I am getting an error on entering this command:
    ./configure –prefix=/home/zealexai/python27 –enable-unicode=ucs4

    The error msg is :
    checking for –enable-universalsdk… no
    checking for –with-universal-archs… 32-bit
    checking MACHDEP… linux2
    checking EXTRAPLATDIR…
    checking machine type as reported by uname -m… x86_64
    checking for –without-gcc… no
    checking for gcc… no
    checking for cc… no
    checking for cl.exe… no
    configure: error: in /home/zealexai/src/Python-2.7.3':
    configure: error: no acceptable C compiler found in $PATH
    See
    config.log’ for more details

    How can i install GCC once I ssh to my account? Please help. Thank you,

  2. Hey Matthew, great post thanks. I bought a 3 year bluehost commitment for WordPress then I went and learned Django lol. Good to know it can be deployed nonetheless with (relative) ease.

    1. Thanks ddiran!

      Heroku is also a nice free alternative for hobby dev for Django, and if you want something with a little more control over the backend, DigitalOcean has Django pre-built deployment.

  3. So do you just type all this stuff on your computer’s command line? Like, in step 2, where would I begin typing “cd mkdir…”?

Join the Discussion

%d bloggers like this: