Monday, February 20, 2012

Everything you need to setup Django on Ubuntu with Postgresql

This is a very simple run down of everything I did from a basic Ubuntu 10.04 setup to get Django running on my server.

  1. sudo apt-get install apache2 
    This will install apache on your server
    - The httpd service should automatically be started. You can test it by going to the IP of your server (localhost if it is on your computer)

  2. sudo apt-get install postgresql 
    This installs PostgresSQL 8.4.
    I chose to use PostgreSQL. You may use different types of databases for your setup.
    If you are not familiar with Postgres, please visit www.postgresql.org for more information.
    We want to make sure that we can connect to postgres from localhost. While logged in to the machine with Postgres on it, do the following:
    pico /etc/postgresql/8.4/main/postgresql.conf 
    This will open the file where you will need to add access to localhost. Locate #listen_addresses = 'localhost' and remove the # symbol. This will tell postgres to allow connections to the databases as long as the connection is from that server.

    We still have more ways to go. PostgreSQL has a server role of 'postgres' that we will use later to connect to the database. However, there is no password (or the password is unknown). We need to connect to it as an admin and change the password (we will also connect to a default database on postgres - 'template1'). The next step will be to change the password.
    >#sudo -u postgres psql template1
    >template1=#ALTER USER postgres with encrypted password 'your_password';
    The confirmation to above will be 'ALTER ROLE' printed on it's own line. (Type \q to quit)
    Now we want to use MD5 authentication for postgres
    pico /etc/postgresql/8.4/main/pg_hba.conf 
    we scroll down to 'local    all    postgres     ident' and change 'ident' to 'md5'
    Now to reset the connection:
    sudo /etc/init.d/postgresql-8.4 restart
    To test the connection simply type
    psql -U postgres
    You will be prompted to enter the password, after which you will be in 'postgres'
    Most of this information is from https://help.ubuntu.com/8.04/serverguide/C/postgresql.html
     
  3. Install Django (2 options)
    sudo apt-get install python-django
    This will install Django 1.1.1 (depending on what version linux you are on). If you just want to play around it's fine. If you want to install a specific version of Django (as I needed to do), you have to do the following:
          - Go to Django website ( https://www.djangoproject.com/download/ )
          - Find the exact download path of the version you need to download
          - Use "wget exact.address.to/file.zip"
          - Use 'tar' command to extract the file.
               * tar xzvf Django-1.2.7.tar.gz
               * cd Django-1.2.7/
               * sudo pyton setup.py install
          - Go into the folder you extracted, and run "python setup.py install"
  4. For some features in Django you might need more plugins such as psycopg2 (I believe* this step is optional for most)
Now you are ready to start actually setting up your project [I will be making another update for that]

No comments:

Post a Comment