Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Monday, March 4, 2013

Django with MySql set up (on Ubuntu)

This post describes the installing Django with MySql set up in a succinct way. 
Install Django and MySql
Note: Switch to root in the terminal and do the following:
 
$ sudo apt-get install python-django
$ sudo apt-get install mysql-server
$ sudo apt-get install python-mysqldb
MySql database and use Set up:
Note, use the password you entered when installing MySql

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE django_db;
Query OK, 1 row affected (0.01 sec)

mysql> GRANT ALL ON django_db.* TO 'djangouser'@'localhost' IDENTIFIED BY 'mypassword';
Query OK, 0 rows affected (0.03 sec)

mysql> quit
Bye
Create a Django Project
$ django-admin startproject mysite
Edit the Django database settings
Edit mysite/settings.py:
DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
DATABASE_NAME = 'django_db'             # Or path to database file if using sqlite3.
DATABASE_USER = 'djangouser'             # Not used with sqlite3.
DATABASE_PASSWORD = 'mypassword'         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
Use Django to create the database tables
$ cd mysite
$ python manage.py syncdb
Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'sofeng'):    
E-mail address: sofeng@email.com
Password: 
Password (again): 
Superuser created successfully.
Installing index for auth.Message model
Installing index for auth.Permission model
Loading 'initial_data' fixtures...
No fixtures found.
Run the development server
$ python manage.py runserver
Validating models...
0 errors found.

Django version 0.96.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[30/Jul/2008 16:37:23] "GET / HTTP/1.1" 404 2053
Point your browser at http://127.0.0.1:8000 and you should see the Django It worked! page.

one more online source: Baby Steps with Django - part 2 database setup

Wednesday, December 12, 2012

Proxy settings system wide for Linux Operating Systems

 
 The six (6) simple steps to set the system wide proxy settings,

Step 1: Installing redsocks 
  1. Firstly, download the following files: red sock file for 64 bit: redsocks_0.4+dfsg-1_amd64.deb and for 32 bit: redsocks_0.4+dfsg-1_i386.deb 
  2. Install redsocks with the command:
    • for 64 bit: $ sudo dpkg -i redsocks_0.4+dfsg-1_amd64.deb
    • for 32 bit: $ sudo dpkg -i redsocks_0.4+dfsg-1_i386.deb  
Step 2: Installing iptables 
  1. install iptables-persistent with the command
    • $ sudo apt-get install  iptables-persistent

Step 3: Configuring the redsocks
Create an empty file for redsocks.conf with the path /etc/redsocks.conf as $ sudo /etc/redsocks.conf
Copy the below code into it and also set your login and password

base {
    log_debug = off;
    log_info = off;
    log = "syslog:daemon";
    daemon = on;
    user = redsocks;
    group = redsocks;
    redirector = iptables;
}

redsocks {
    local_ip = 127.0.0.1;
    local_port = 5123;

    ip = 10.201.13.50;
    port = 80;

    type = http-relay;

    login = "user";
    password = "password";
}

redsocks {
    local_ip = 127.0.0.1;
    local_port = 5124;

    ip = 10.201.13.50;
    port = 80;

    type = http-connect;

    login = "user";
    password = "password";
}



Step 4: Configuring the rules v4
Create an empty file for rules.vs with the path /etc/iptables/rules.v4 as $ sudo /etc/iptables/rules.v4

Copy the below code into it,

*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A OUTPUT -d 10.0.0.0/8 -j RETURN
-A OUTPUT -d 127.0.0.0/8 -j RETURN
-A OUTPUT -d 192.168.0.0/16 -j RETURN

 

-A OUTPUT -p tcp --dport 443 -m tcp -j REDIRECT --to-ports 5124
-A OUTPUT -p tcp -m tcp -j REDIRECT --to-ports 5123
-A OUTPUT -p udp -m udp -j REDIRECT --to-ports 5123
COMMIT



Step 5: Setting startup variable to Yes

Change the startup variable to "yes" in the  /etc/defaults/redsocks.

Step 6: Final step
Remove proxy settings at browser or anywhere if you set up early and then restart the system. 


If you need any further help, please comment it below.