Thursday, May 31, 2012


Set sudoer permission in admin group:

# nano /etc/group

Change/Add admin
*admin: name1, name2, name3

Ctrl X  >  Y  >  Enter

UBUNTU: How TO Install MySQL-Server

Case: Ubuntu Server  for Moodle Installation

Install MySQL (skip Postgresql)

sudo apt-get install mysql-server php5-mysql
  • Replace the following string NewRootDatabasePassword with a secure password of your own choosing.
There is no space between the -p and the password on the second command.
mysqladmin -u root password NewRootDatabasePassword
mysqladmin -u root -h localhost password NewRootDatabasePassword -pNewRootDatabasePassword
  • Create the Moodle database and Moodle user in MySQL.
The mysql command will prompt for your NewRootDatabasePassword (from above). Replace NewMoodleDatabasePassword with a secure password of your own choosing.
mysql -u root -p
> GRANT ALL PRIVILEGES ON moodle.* TO moodleuser@localhost IDENTIFIED BY 'NewMoodleDatabasePassword';
> GRANT SELECT,LOCK TABLES on moodle.* TO moodlebackup@localhost IDENTIFIED BY 'MoodleBackupPassword';
The above also creates a backup user moodlebackup so that you can use mysqldump to make database backups without incident.

UBUNTU: Add New Hard Disk in Virtual Server

Case: In Unlicensed vmware

1. Power off the server
2. Right Click on server  > Edit Setting
3. Add New Hard Disk  >  Next  >  Next
4. Disk Size: 25 GB  > Case for db server(don't click thin provisioning)
5. Specify Datastore > Datastore01
6. Next  > Next  > Finish  >  Ok

** Power on the server back.

How to present/mount New Hard Disk in Ubuntu?

1. To list the HD in server

# fdisk -l
/dev/sdb/ ..........

2. To Format the new Hard Disk# mkfs.ext3  /dev/sdb
# Yes: Y  >  Enter

# cd  /

3. To Mount New HD in Ubuntu Server
# mkdir  data  &&   mount /dev/sdb/   /data/
# df  -h

4. Configure/edit  fstab file
# nano  /etc/fstab

**Add line under the last row:(Can also refer to existing ubuntu server)
/dev/sdb  /data/   ext3  noatime   0    0

Ctrl X  >  Y   >  Enter  (to save & exit).

Wednesday, May 23, 2012

CodeIgniter: How to check CodeIgniter version.

Open CodeIgniter root file:

# cd /data/form/system/core
# ee CodeIgniter.php

Check the version in this code:
define('CI_VERSION', '2.0')

Monday, May 14, 2012

Drupal: Clean URL Error after migrate to Ubuntu Server

Clean URLs with Apache 2 on Ubuntu

Step 1 - Method A: "Virtual Host" Setup

First, from the Linux command line, enable the rewrite module for apache with this command:
sudo a2enmod rewrite
You can check to see if this worked by running:
apache2ctl -M
and seeing if it is on the list.
Next, use an editor (such as nano) to edit the appropriate Apache configuration file for your Drupal site in the /etc/apache2/sites-available/ directory. For a single site, the file is /etc/apache2/sites-available/default; if you have multiple sites, the file names should reflect the names of the sites to which they refer. Thus, to edit the default site configuration, use
sudo nano /etc/apache2/sites-available/default
Look for the Directory section referring to the folder where your Drupal site lives (in /etc/apache2/sites-available/default, this is typically ), and change the line:
AllowOverride None to AllowOverride All
(This directive permits an .htaccess file, such as Drupal's, to be used to override Apache's default settings, and is necessary to allow the URL rewriting to work. See for more information).
Save this file and then reload Apache as follows:
sudo /etc/init.d/apache2 reload

Subdomain Setup

Instead of creating multiple virtual host files, you can create one virtual host file that uses a wildcard in the ServerAlias. Both a simple multi-site Drupal setup and multiple Drupal versions can run this way, if the different subdomains are defined for each site in settings.php.
Consider the following and modify your configuration file to fit your needs.
  1. http://myproject.dr5.example/
  2. http://myproject.dr6.example/
  3. http://myproject2.dr6.example/
Here is a partial listing of a virtual host configuration file that would support the last two lines in the above example. Note this is not intended to be a COMPLETE configuration file, but rather provide guidance for your development setup.

DocumentRoot "/www/Dr6"
ServerName example
ServerAlias *.dr6.example

AllowOverride All
Edit & save your config file to suit your development needs. Assuming the site is already enabled, then reload Apache.

Step 1Method B: apache2.conf

In Apache version 2, httpd.conf has been deprecated and the new file is located at:
Thus, it's no longer necessary to do the following in httpd.conf to enable the rewrite module (mod_rewrite):
LoadModule rewrite_module modules/
AddModule mod_rewrite.c
Simply run the following from the Linux command line:
sudo a2enmod rewrite
To disable the module you can run:
sudo a2dismod rewrite
(**Note that this would cause clean URLs to break.)
Once mod_rewrite is enabled, open apache2.conf in a text editor. Note that it will probably be read-only, so you will need sudo privileges to edit it. Use a command such as:
sudo nano /etc/apache2/apache2.conf
Find where the sections are in your apache2.conf and add another one for your Drupal site similar to this:

    AllowOverride All
After you edit apache2.conf as listed above, you need to restart the server by:
sudo /etc/init.d/apache2 reload

Step 1 - Method C: Add Rewrite Rules Directly to Virtual Host or apache2.conf

If you do not wish to allow .htaccess overrides, you can add the rewrite rules directly to a virtual host file or apache2.conf. The following should work:

         RewriteEngine On
         RewriteBase /
         RewriteCond %{REQUEST_FILENAME} !-f
         RewriteCond %{REQUEST_FILENAME} !-d
         RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
This can provide slightly faster server performance since Apache will not look in every directory for an .htaccess file.
Note that, for proper security, you will need to add in the rules from the Drupal files directory's .htaccess file as well.
More info >>

Wednesday, May 9, 2012

FreeBSD: Enter full pathname of shell or RETURN for /bin/sh

I got this error after scp a big file yesterday.. I thought my server was crash.
But it actually run in single user shell.

Enter full pathname of shell or RETURN for /bin/sh:  > Enter
# Exit or ctrl-D to leave the single-user shell.

Then login like usual to your server.

**********Standard way of dealing with single user mode:
fsck -y
mount -u /
mount -a -t ufs
swapon -a

Linux/Ubuntu: How to extract .tgz file

.tgz and tar.gz files are pretty much the same. You extract them like this:
tar -xvzf file.tar.gz 
tar -xvzf file.tgz 


Linux/UBUNTU: Download Multiple Files(http) From Command Line

The following command is used to download a single file using wget:
wget URL
Replace URL with the exact url of the file to download.


Tuesday, May 8, 2012

Mysql: My Own Notes( Backup & rename )

  1. Get db backup for www from daily backup server
  2. Copy the db to the nearest linux server (eg: 75)
  3. Bunzip the file:
    #bunzip  filename_xxx.bz2
  4. Use vi command to rename the db
    #vi filename_xxx.sql
  5. Esc  >  Shift + :
    ** If the cursor already can move up and down then its done.

  6. Esc  >  Shift + :  >  :wq  >  Enter
    **Wait until the process finish

  7. mkdir folder
  8. mv  filename_xxx.sql  folder/
  9. tar -cjf  folder.tar.bz2  folder
  10. scp  folder.tar.bz2
  11. Open related db server to restore the db.Copy the file from yourlocation server.
    #scp folder.tar.bz2  ./
  12. Untar the file first:
    # tar -xjvf   folder.tar.bz2
  13. Open folder and restore the db in server
    # mysql -uroot -p --default-character-set=utf8  <   filename_xxx.sql
  14. Grant the privileges to the db
    # GRANT ALL PRIVILEGES on db.* to 'username'@'applicationserverhost' IDENTIFIED BY 'password'

  15. Check connection within the db and the application server.
    #telnet  applicationserverhost  3306;
  16. From application server, test connection to db server
    #mysql -uUSERNAME -p -h  IP_databaseserver

    eg:  mysql -urepo_admin -p -h  172.XX.XXX.XX
    ** If error, connection refuse ask Network Admin to allow telnet both server in firewall setting.
  17. Update the apps configuration file for the grant access. Check the application from browser.
  18. Done.

Mysql: Dump & Restore Database

Mysql Dump Syntax/Command

We use mysqldump command to do database backup

# mysqldump -uroot -p --databases filename > backupname.sql

eg: mysqldump -uroot -p --databases staff > staff130509.sql

Then, to dump back/restore the backup database to server, use this command:

#mysql -uroot -p < staff130509.sql

But, for UTF8 case, use this command:

#mysql -uroot -p --default-character-set=utf8 < staff130509.sql

Then to check the current process list in mysql server:

#mysql -uroot -pPASSWORD
mysql> show processlist;

To show processlist with out all the sleeping processes...
mysql> \P grep -v Sleep

Monday, May 7, 2012

Unix/Linux: Resetting a user’s password

Q. How do I reset a user's password under any Linux distribution from command prompt?
  1. Login as the root user
  2. Open terminal or shell prompt
  3. Type the following command:
# passwd usernameFor example, reset a tom's password, enter:
# passwd tom
Type a new password twice. Done!

MySQL: MySQL server has gone away

Issue: I need to restore quite big mysql db to local db server using mysql restore command, but got this error.
 ERROR 2006 (HY000) at line XXX: MySQL server has gone away


  1. Stop mysql-server
    # /usr/local/etc/rc.d/mysql-server stop
  2. Open file my.cnf in mysql directory 
  3. Add this 2 line:
    quick max_allowed_packet = 16M


  4. Start mysql-server back
    # /usr/local/etc/rc.d/mysql-server start
  5. Try restore the mysql db again
    # mysql -uroot -p --default-character-set=utf8  <  filenamexxxx.sql
    **It works for me. Try it yourself.


Sunday, May 6, 2012

Mysql: Reset your mysql root password

  1. Stop mysql first
    #/usl/local/etc/rc.d/mysql-server stop.
    #mysqld_safe --skip-grant-tables

  2. Than open new shell and go to the mysql-server
    #mysql --user=root mysql

  3. Now you enter the mysql server and run this command
    #update user set Password=PASSWORD('new-password') where user='root';

    #flush privileges;


  4. Start the server
    #/usl/local/etc/rc.d/mysql-server start

  5. Done

Mysql: Using Vi to Search and Replace

Case: Use vi in FreeBSD/ Linux server

# vi filename.sql
* Shift + :
: (use search command below)

Search (Wraped around at end of file):
 Search STRING forward :   / STRING.
 Search STRING backward:   ? STRING.

 Repeat search:   n
 Repeat search in opposite direction:  N  (SHIFT-n)

Replace: Same as with sed, Replace OLD with NEW:
First occurrence on current line:      :s/OLD/NEW

Globally (all) on current line:        :s/OLD/NEW/g

Between two lines #,#:                 :#,#s/OLD/NEW/g

Every occurrence in file:              :%s/OLD/NEW/g

Mysql: Repairing mysql database

Run this command:

# mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

Ubuntu: Monitor All SQL Queries in MySQL

Microsoft’s SQL Server has a tool called Profiler that you can use to monitor every SQL query that hits the database. This is extremely useful for programmers as well as database administrators to troubleshoot the exact queries generated by an application.

Having switched to using MySQL on a frequent basis, this was one of the first things I wanted to figure out how to do. How else can you see the actual SQL code generated by WordPress or phpBB?
The first thing we’ll need to do is turn on logging of queries in MySQL. Be warned that this should only be done in development… it really slows things down to log every single query to a file.
Find and open your MySQL configuration file, usually /etc/mysql/my.cnf on Ubuntu. Look for the section that says “Logging and Replication”
# * Logging and Replication
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
log = /var/log/mysql/mysql.log
Just uncomment the “log” variable to turn on logging. Restart MySQL with this command:
sudo /etc/init.d/mysql restart
Now we’re ready to start monitoring the queries as they come in. Open up a new terminal and run this command to scroll the log file, adjusting the path if necessary.
tail -f /var/log/mysql/mysql.log
Now run your application. You’ll see the database queries start flying by in your terminal window. (make sure you have scrolling and history enabled on the terminal)
I’m impressed, phpbb3 has fairly tight, optimized SQL code. WordPress, on the other hand, is very inefficient.
Taken & credit to

FreeBSD: Upgrade from 8.2 to 9.0

If you use this command to upgrade to latest release FreeBSD 9.0:

$ freebsd-update -r 9.0-RELEASE upgrade
You might see following error:
The update metadata is correctly signed, but failed an integrity check. Cowardly refusing to proceed any further.
This error indicate that it cannot accept % and @ characters which appear in FreeBSD 9 . To overcome this, run following command:
$ sed -i '' -e 's/=_/=%@_/' /usr/sbin/freebsd-update
Now start the upgrade process:
$ freebsd-update -r 9.0-RELEASE upgrade
Accept all prompted values and follow the wizard. This process downloads all files and patches required for upgrade so it takes time. You might need to press ‘Enter’ once to check /etc/hosts file. Once complete, run following command to start installing the updates:
$ freebsd-update install
After a while, you should see the system will prompt something as below:
Installing updates...rmdir: ///boot/kernel: Directory not empty   Kernel updates have been installed. Please reboot and run "/usr/sbin/freebsd-update install" again to finish installing updates.
Reboot the server:
$ init 6
Once up, it will boot to FreeBSD 9. Run again the installation command:
$ freebsd-update install
After the process completed, the system will ask you to build back all your application which installed using ports. Once done, you need to rerun again the above command to complete the upgrade process and you should something like below:
$ freebsd-update install Installing updates... Done
Your update should be completed now. To check the new version, run following command:
$ uname -r 9.0-RELEASE

Credit to :