Thursday, March 27, 2008

Setting up for Django development on a Ubuntu Hardy Heron Beta desktop

Pretty standard set up for the desktop.

Install a LAMP server:

$ sudo tasksel install lamp-server

Make sure you set a root password for your MySQL database.

Or manually set your MySQL root password

mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password');
mysql> \q

To create a database and a user:

Sign in:

mysql -u root -p
mysql> CREATE DATABASE database1;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO 'yourusername'@'localhost' IDENTIFIED BY 'password';

Now we'll create a virtual host in Apache. Initally Apache creates a site called "default" at "/var/www". To create our own site, which we will manage from our home directory.

Copy the config at "/etc/apache2/sites-available/default" to a new config called "/etc/apache2/sites-available/django.conf"

$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/django.conf

And then edit the new config and change "DocumentRoot" and "Directory" from /var/www/ to "/home/[username]/django/www". Just so you know, I've put my django source, my various django projects and such in a folder in my home directory. Just to keep them neat.

$ sudo gedit /etc/apache2/sites-available/django.conf

Now we'll disable "default" and enable "mysite" in Apache

$ sudo a2dissite default && sudo a2ensite django.conf

As per instructions, we'll run:

$ sudo /etc/init.d/apache2 restart

Put in a test PHP or HTML page and go to http://localhost/ and it should all work.

The quickest way to set up the management of you MySQL databases is to set up PhpMyAdmin. It's quite simple:

$ sudo apt-get install phpmyadmin

To get to your phpmyadmin, just go to http://localhost/phpmyadmin

I've already got my Django code installed via SVN. Now I just need to finish setting up Apache to run it.

Install the adapter for the database (i.e. python-pysqlite2, python-psycopg, python-mysqldb):

$ sudo apt-get install python-mysqldb python-sqlite

To add Apache support, install mod-python:

$ sudo apt-get install libapache2-mod-python

Let's build a link to the Django scripts from the Python site-packages:

$ sudo ln -s /home/[username]/django/django-trunk/django /usr/lib/python2.5/site-packages/django

$ sudo ln -s /home/[username]/django/django-trunk/django/bin/django-admin.py /usr/bin

This should be most of the set up required. There may be a few extras that you'll have to set up, like certain python modules and such but we're on our way. Our next steps will be to set up apache to host the projects and to get to work.



1 comments:

hjkl said...

welcome to the wow power leveling, cheap service site,WoW Gold buy cheap wow gold,wow gold,world of warcraft buy wow power leveling