Step 14: Upload to a server

This is the hardest step, I guess, because there are so many different servers, and they have different setups.  I am going to give very specific advice for what it took for me to get my websites running on servers run by Hostgator

Like I said before, this is no plug for them, it is simply because I run some of my websites with them, and had to go through a rather large learning curve to get it done. 

I also have to admit, I am kind of stupid about this stuff.  I don't understand the ins and outs of Apache very well at all.  I have read some of the documentation, but there is a lot of documentation and I don't hosts sites, I only want to be able get it on there, not get hacked and serve my site.  I would rather be building new apps and adding content to my websites than waste time becoming an Apache guru.  So, follow this bit if you like, but you may well be better off asking someone else. 

I'll add here, if you are the mother of all Apache gurus, and you want to re-write this section for me, well, you would rock…

There are two web pages that basically spell out most of what I am going to say here, and you can rather work with them if you like. 

Okay, lets do some preparation before we actually change anything on the server.  I'll me spell this stuff out in point form:

  • First up, before we start to get our site ready, make sure, with your Hostgator site, that you have the right package to be able to run a website with Django and fastcgi. 
  • Okay, now ask your contact person for FLUP, fastcgi, and MySQLdb. 
  • You will also need to have SSH, which you may have to pay extra for. 
  • If you don't already, you will need to know your username and password for the website. 
  • Under your project directory, where we currently have nothing but the main 'zing' directory, create an new directory and call it 'guts'.  If you don't like that name, call it 'public_html' or anything else, but we are going to use this for the none Django stuff. 
  • Under that directory, open a terminal and type the following:
    vernon@slick:~/project/guts$ ftp your_domain_name
    Where 'your_domain_name' is, of course, your domain name.  In my case, I would be typing sandcurves.com.  Note the lack of 'http://' in front of it.  Just the name and the dot_whatever (.com). 
  • You may have some fancy-dandy ftp program - suit yourself.  I will stick with basic terminal ftping, just because it'll help us stay on the same page. 
  • Okay, do like so:
    Connected to sandcurves.com. 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
    220-You are user number 1 of 50 allowed.
    220-Local time is now 05:08. Server port: 21.
    220 You will be disconnected after 15 minutes of inactivity.
    Name (your_domain.something:your_name): your_username
    and then…
    331 User your_username OK. Password required
    Password: your_password
  • Okay, like I said, I am assuming that your set-up is just like mine, and so we are going to download some files from the location I have them.  If you don't find these files where I am telling you, ask your contacts to help.  For the most part, this kind of set-up is fairy standard for Apache shared host environments. 
  • You'll have your nice little 'ftp>" prompt, and so now do this:
    ftp> get .bashrc
    local: .bashrc remote: .bashrc
    200 PORT command successful
    150 Connecting to port 56619
    226-File successfully transferred
    226 0.012 seconds (measured here), 17.79 Kbytes per second
    214 bytes received in 0.01 secs (14.6 kB/s)
    ftp>
  • Okay, that file isn't so important, but the next one is.  We will need to change directories on the server, and then fetch the file.  Changing directories on the other site is just the same as doing it on your own machine.  If you needed to change directories on your own site, while using ftp, use 'lcd' instead.  FTP is very easy to work with, and if you want to be a web guru, you should know your FTP basics very well. 
  • ftp> cd public_html
    250 OK. Current directory is /public_html
    ftp> get .htaccess
    local: .htaccess remote: .htaccess
    200 PORT command successful
    and so on …

    ftp> bye
    221-Goodbye. You uploaded 0 and downloaded 2 kbytes.
    221 Logout.
    vernon@slick:~/project/guts$
    You can always log out of ftp using the term 'bye' or 'exit'.&nbps;
  • Okay, I'm going to show you basically what I have in there:
    # -FrontPage-
    AddHandler fcgid-script .fcgi
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /

    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*


    order deny,allow
    deny from all
    allow from all


    order deny,allow
    deny from all



    AuthName domain_name.com
    AuthUserFile /home/user_name/public_html/_vti_pvt/service.pwd
    AuthGroupFile /home/user_name/public_html/_vti_pvt/service.grp
    AddType text/x-python .py


    RewriteRule ^media/(.*)$ - [L]
    RewriteRule ^admin-media/(.*)$ - [L]
    RewriteCond %{REQUEST_URI} !(zing.fcgi)
    RewriteRule ^(.*)$ zing.fcgi/$1 [QSA,L]
  • What is going to be important is those first few lines (I think lines 2 to 5) and then all the stuff in the last few lines (the whole last block, where the lines start with 'RewriteRule'). 
  • The stuff in between is probably similar to what you have already in that file.  So just change your first and last bits to be exactly like mine - where the reference to 'zing.fcgi' can stay 'zing' or be changed to whatever you like. 
  • The next step, then, is to create that fcgi file, so open up a file in the 'guts' directory called 'zing.fcgi' (of course, changing the name to whatever you called it in your .htaccess file. 
  • Okay, this next bit assumes that your python path is the same as mine.  You can check on that.  At the moment I still have python2.4 on the server - you may need to check that (you can ask, or ssh and run a python shell, which will show you the version).
    #!/usr/local/bin/python
    import os, sys

    sys.path.insert(0, "/usr/lib/python2.4")
    sys.path.insert(0, "/home/domain_name/dj")
    sys.path.insert(0, "/home/domain_name/dj/django")
    sys.path.insert(0, "/home/domain_name/dj/project")
    sys.path.insert(0, "/home/domain_name/dj/project/zing")

    # Set the DJANGO_SETTINGS_MODULE environment variable.
    os.environ['DJANGO_SETTINGS_MODULE'] = "zing.settings"

    from django.core.servers.fastcgi import runfastcgi
    runfastcgi(method='threaded', daemonize='false')
  • Next, copy your settings.py file from the 'zing' directory to the 'guts' directory.  When we run the site on the host server, for the most part the only thing we want to have different is the settings.py file.  So we are going to keep the one in the 'zing' directory as it is, and make the needed changes to the other one for what we need on our site. 
  • There is one other file we are going to keep a different version of on our home site to our server's site, the base.html.  So copy it form the 'template' directory to the 'guts' directory. 
  • The reason is that we want to separate CSS from the HTML.  Look for this line we wrote oh so long ago:
    <link rel="stylesheet" type="text/css" href="/media/css/style.css">
  • Copy all the content between the open <style> tag and the closing </style> tag.  Now, paste that into a file called 'style.css' 
    /* Zing Stylesheet */

    /* Page */
    body{padding:0;margin:0;font-family:Arial, Helvetica, Tahoma, sans-serif;}
    /* Title section */
    #title{float:left;width:100%;padding:0;margin:0;border:0;border-bottom:1px solid #cccccc;}
    #title h1{padding:10px 0 0 50px;font-size:60pt;margin:0;font-family:"Myriad Pro", Arial, Helvetica, Tahoma, sans-serif;}
    #title h2{margin:0;padding:0;text-align:center;}
    /* Content section */
    #content{float:left;border:0;margin:0;padding:10px 2% 0 2%;width:75%;}
    /* Sidebar section */
    #sidebar{float:left;border:0;border-left:1px solid #cccccc;padding;10px 2% 0 2%;width:20%;margin:0;}
    /* Footer section */
    #footer{float:left;border:0;border-top:1px solid #cccccc;padding:0;margin:0;width:100%;text-align:center;}

  • For the most part, I have tried to leave out as much unnecessary stuff as possible, but one thing that makes such a difference is having aliases when you are working with ssh.  Under bash (the terminal thingi) we can have one word that we define to mean some script to run.  In our case, all we are going to do is set some 'cd' commands, so that we can quickly get to the directories used most. 
  • Open the '.bashrc' file (remember that with both this file and the .htaccess file, they are hidden files under linux.  If you have a problem seeing them, just run 'ls -a' in our terminal to see the hidden files listed and 'emacs .bashrc' to open it up with emacs. 
  • At the bottom of the file, just append these lines, and then close and save it.  You'll have to change 'user_name' for your set-up. 
    # User specific aliases and functions
    alias zing='cd /home/user_name/dj/project/zing'
    alias stylo='cd /home/user_name/media/css'

So far we haven't broken anything on our webserver yet.  Take a deep breath, play Sodoku, go get coffee, clear your head.  We are about to start tinkering with the insides, the guts, of your host server. 

Ssh is a fantastic tool where you have command line access to remote computers through a secure tunnel.  Unlike FTP, where we were just bringing and taking, with SSH we are actually going to go onto our host server's computer and tinker. 

With SSH access to the server computer you can only do a limited amount of thing, so I don't think you need to worry about breaking their computer (I hope), but you can totally destroy your own website - actually, when we start our, that is exactly what we are going to do anyway.  But, hopefully, we'll also be getting it to work very soon. 

The first time you try to connect it is going to ask you if you want to continue, because it doesn't know the site.  Answer 'yes' of course.  To get into your webserver with ssh, do the following:

vernon@slick:~/project/guts$ ssh -p 2222 username@domain_name.com

And to exit, simply type exit:

whatever@whatever:~$ exit

Remember each time to exit, same as FTP. 

Okay, now, lets get things going.  ssh into your server again (it doesn't matter from which directory you are in your home computer right now). 

You are at your root directory when you log in.  The first thing you want to do is see if python is working.  At the terminal, type 'python' and hit enter. It should enter the familiar Python shell.

Next is to see if Django is installed.  While still in Python, type "import django" If nothing happens, and python just moves on to an empty python prompt ('>>>') then django is there and you don't have to worry.

Hit 'Ctrl-d' to get out of python, and make a new directory ('mkdir dj') called 'dj'.  cd into it.  If you didn't have Django, you can get it with svn.  See this page to help install the development version

Okay, if that has all gone well, lets make our project directory 'mkdir project' and cd into it. 

Create your new django project here, with 'django-admin.py startproject zing'.  This is the second time around, so this should be familiar ground. 

Again, repeating ourselves, make the directory 'mkdir template' for the templates. Then make the 'blog' sub-directory, 'mkdir template/blog'

And our blog application, 'python manage.py startapp blog'. 

Type cd to get back to your root directory, and create a new one, 'media'.  Then make a sub-directory, 'mkdir media/css' And then exit.


Share |
« Previous Page  |  Return To Contents Page  |  Next Page »

 

Thank you for visiting

This is my personal blog, but I try to write things that you may find interesting or useful.  I'm currently working on a six month long project digging into the elements that make a blog meaningful. For more on that, visit MEANINGFUL BLOG PROJECT page

You may want to know a little about me personally, so start at the about page. 

If you find some of what is here interesting, or you want to follow the project through, why not subscribe.

Tweet