Friday 18 May 2012

PostgreSQL with PHP in Ubuntu on Localhost [STEPS TO RUN phpPgAdmin (postgresql 9.1) ]


Installation

Install PostgreSQL:
sudo apt-get install postgresql
Install GUI Administration application:
sudo apt-get install pgadmin3
Install PHP based Web Administration site (like phpMyAdmin for MySQL database):
sudo apt-get install phppgadmin

Configuration

Configure so that you can access via localhost:
gksudo gedit /etc/postgresql/9.1/main/postgresql.conf 
It witll open the file for editing, Add following line at the end of the file:
listen_addresses = 'localhost'
Save and close the file. Open another file for editing:
gksuso gedit /etc/postgresql/9.1/main/pg_hba.conf
Replace “local all all ident sameuser” with:
local   all         all                               md5

Change Password for root user

In PostGRE, root user is “postgres” which by default, does not have any password. Enter following line in terminal to set a password for it:
sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';
\q

Create a new User & a new Database

sudo -u postgres createuser -d -R -P new_username
sudo -u postgres createdb -O new_username new_database_name
This will create a new user, with username “new_username” and create a new database“new_database_name” and set “new_username” it’s owner.

Configure phpPgAdmin

I assume you already installed phpPgAdmin by:
sudo apt-get install phppgadmin
Then, configure Apache:
gksudo gedit /etc/apache2/apache2.conf
Add following line at the end of the file:
Include /etc/phppgadmin/apache.conf
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/postgresql-9.1 restart

Access phpPgAdmin

type http://localhost/phppgadmin in your browser & log in by the username you just created (new_username)

HOW TO INSTALL POSTGRESQL9.1 ON UBUNTU

First install python-software-properties:

$sudo apt-get install python-software-properties

Add PPA repository and update apt:

$sudo add-apt-repository ppa:pitti/postgresql

Now install postgresql:

$sudo apt-get install postgresql-9.1 libpq-dev

Check the installation:

$locate postgresql 

$psql -V             # check psql version
psql (PostgreSQL) 9.1
 
$finger postgres     # check if user postgres is created 

Login: postgres          Name: PostgreSQL administrator
Directory: /var/lib/postgresql       Shell: /bin/bash
Never logged in.
No mail.
No Plan.


$ su postgres          # switch user to postgres
$ psql                 # launch psql as postgres and check the server version
psql (9.1)
 
postgres=# select version();
 

Setup Root User 'posrgres':

The installer has created a unix user postgres without a password. So first I give a (unix) password to this special user. The user postgress is a root user (database administrator) of PostgreSQL Server but without a (PostgreSQL) password. So I give it one here as well.
 
$ sudo passwd postgres # give the postgres user a (unix) password
$ su postgres           # switch to the user postgres
$ psql                   # launch psql to give postgres PostgreSQL passord
postgres=# alter user postgres with password 'secret';  # new password for postgres 
ALTER ROLE
postgres=# \q            # quit psql
$ exit                   # exit from user 'postgres'
exit
 

Configure PostgreSQL Server:

$ su postgres    # switch to the user postgres
$ cd /etc/postgresql/9.1/main
$ ls -la 
 
postgres@ubuntu-pc:/etc/postgresql/9.1/main$ cp pg_hba.conf pg_hba.conf.bak.original 
postgres@ubuntu-pc:/etc/postgresql/9.1/main$ cp postgresql.conf postgresql.conf.bak.original 

postgres@ubuntu-pc:/etc/postgresql/9.1/main$ ls -la
 

Make changes to pg_hba.config (authetification methods).


host    all         all       127.0.0.1/32       trust          # md5 -> trust

Make changes to postgresql.conf for error log.

#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------
log_destination = 'stderr'  # 2011.07.04 - enabled
logging_collector = on   # 2011.07.04 - enabled and turned on
log_directory = 'pg_log'  # 2011.07.04 - enabled. I will create this folder (see below).
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # 2011.07.04 - enabled
log_truncate_on_rotation = off  # 2011.07.04 - enabled and keep it off
log_rotation_age = 1d   # 2011.07.04 - enabled
log_rotation_size = 10MB  # 2011.07.04 - enabled


Create a log directory as specified in the config above:

$ su postgres         # switch to postgres user
$ cd ~/9.1/main/      # /var/postgresql/9.0/main
$ mkdir pg_log        # create a new log directory as specified in the config file above
$ ls -F               # confirm the new directory 'pg_log'
PG_VERSION  pg_log/ ...
$ exit

 

Restart the server:

$ sudo /etc/init.d/postgresql restart
 * Restarting PostgreSQL 9.1 database server  
$ sudo /etc/init.d/postgresql status
Running clusters: 9.1/main 
 

Check the new log:

$ sudo ls /var/lib/postgresql/9.1/main/pg_log
postgresql-2011-07-23_135126.log  
 

 Finally Install pgAdmin III (GUI tool for PostgreSQL) :

$ sudo apt-get install pgadmin3   # install the latest pgAdminIII
$ pgadmin3                        # launch it  
 
 
  

Tuesday 15 May 2012

Follow the following steps to install TCC automation

 NOTE:
  • For installing TCC automation software, make sure that your computer has MYSQL and Django installed.
  • This application is tested for Django version 1.4.
  • In this documentation, replace the "user name " with the name of your system.
  • Also run following command commands in the terminal :                          sudo apt-get install apache2 libapache2-mod-wsgi

    (mod-wsgi is necessary for running the software on localhost using apache.)
                                                                     sudo apt-get installmysql-server python-mysqldb
  1. First step to install the TCC software is to download the “TCC.tar.bz2 “ of office automation from the http://sarovar.org/frs/download.php/1327/TCC.tar.bz2 .Then, extract it and place the extracted folder in the home folder. Change the name of the folder from "TCC" to "TCC11_12".
  2. Open the TCC folder and make the changes in the apache folder and settings.py file. In apache folder there is a “django.wsgi” file which contains sys.path.append(‘/home/user name/’), in this give  "user name" of your system. In settings.py file,where there is a user name and password, give the user name and the password of your phpmyadmin. Then open phpmyadmin and create the database (say "tcc") and then again open the settings.py file and change the name of the database as created in the phpmyadmin (say "tcc"). 


          DATABASES = {
                  'default': {
                  'ENGINE': 'django.db.backends.mysql',
                  'NAME': 'tcc',                      
                  'USER': 'root',                    
                  'PASSWORD': 'q',
                  'HOST': 'localhost',            
                  'PORT': '',                      
              }

        also change 'HOST':''  to  'HOST': 'localhost', in the above database.

  • In the settings.py file change



         LOCAL_URL = 'http://192.168.2.178/'      to                                                                          LOCAL_URL = 'http://localhost/'

          and
          MEDIA_URL = 'http://192.168.2.178/media/'     to                                                             MEDIA_URL = 'http://localhost/media/'     


  •      Give the path in TEMPLATE_DIRS = (“/home/username/“) in settings.py file of your templates of       TCC application as:



              TEMPLATE_DIRS = ("/home/USER NAME/TCC11_12/templates"                                                 
               <replace USER NAME with the    "user name" of your system> 



    3. Write the following command in terminal to go into the TCC project:

          cd TCC11_12

        Then, run the following command in order to create the tables in the database

          python manage.py syncdb



    4. Then, go to phpmyadmin and in the above database from the tables created above we have to     drop two tables: automation_teachers and automation_variables. The procedure to drop the tables is : Select the tables that are to be dropped and at the end there is “with selected” click on this and select “drop” and then at the end on the right side there is “go”, click on “go”.After click on “go”,your selected tables was dropped.


5. Now, we have to import the dropped tables: automation_teachers and automation_variable. And the procedure is : When you go to the phpmyadmin and open the database of the TCC project, at the top, click on the import.
Then, in order to import the tables browse the “tcc_11-12.sql” file.The ”tcc_11-12.sql” file is given below and you have to first copy it on the desktop first and then browse it in the import portion of the phpmyadmin .Then, at the end there is “go”. Click on “go”.

This will import the tables in your database.


6. Save following text in a file  (/etc/apache2/httpd.conf) Change the path of media folder to your own path that you follow instead of the path given.(instead of goraya give your own user name)
     

Alias /media/ /usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/contrib/admin/media/

<Directory /usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/contrib/admin/media/>
Options Indexes
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias  /polls /home/goraya/TCC11_12/apache/django.wsgi
<Directory /home/goraya/TCC11_12/apache/>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias  /tcc11_12 /home/goraya/TCC11_12/apache/django.wsgi
<Directory /home/goraya/TCC11_12/apache/>
Order allow,deny
Allow from all
</Directory>






  • One most important thing that must be done is to copy the media file and replace it on the media path i.e/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/contrib/admin/media/
    .Given link is the link of the media.tar.gz , compressed file of the media file, you will have to first save, extract it and then copy it and replace it on the above path of the media file.
             
          http://202.164.53.122/~satinderpal/media.tar.gz



7. Then, at last final step is go into the browser and type -http://localhost/tcc11_12/. This will open the TCC software in the browser. 


8. When you installed the software completely if there is problem in opening the “credit and feedback” link in running software make the following changes in /home/goraya/TCC11_12/contact/views.py:

from TCC.contact.forms import *
to
from TCC11_12.contact.forms import *