Tuesday, June 29, 2010

Howto use SSH local and remote port forwarding

ssh [username]@[hostname] -p [portnumber]

Reference: http://www.debianadmin.com/howto-use-ssh-local-and-remote-port-forwarding.html

Monday, June 28, 2010

Create new user and password using linux terminal

Senario: you're just a sudoer and do not have full access (not a root user)

Adding new user:
/usr/sbin/useradd riariver

Setting up password for new user
/bin/passwd riariver




Adding user in sudoer file

[jdoe@Eng-Lab-004 ~]$ su -
Password: {user root’s password}
[root@Eng-Lab-010 ~]# gpasswd -a jdoe wheel
Adding user jdoe to group wheel
[root@Eng-Lab-010 ~]#

Tuesday, June 22, 2010

Git: You have some suspicious patch lines…

Monday, December 29th, 2008 at 7:46 pm

So, I’ve run into this a few times now and it seems like bizarre behaviour to me. While committing, git complains about files which have trailing white space, or spaces followed by a tab. While this may not be the nicest formatting, enforcing this to be fixed before committing a file seems odd.
It turns out this is being caused by a pre-commit hook. There are two options you can go with to circumvent the issue.
git commit --no-verify .
The –no-verify will bypass the pre-commit hooks. This only works on the current commit thought, so you have to add the flag each time you want to commit.
I’ve found that if you
cd .git/hooks/
chmod -x pre-commit
will disable the pre-commit hooks permanently by removing the executable rights on the file.
Apparently they are disabled by default in newer releases.
Hope this helps someone else out as well.

How to create GIT repository

    Set-up the new bare repo on the server

  • $ ssh myserver.com
        (type your password)

  • $ mkdir /opt/git/myapp.git
  • $ mkdir /opt/git/myapp.git
        (by convention, repo is created inside /opt folder)
        Note: be sure that you own the folder that you have created

  • $ git --bare init    
    Initialized empty Git repository in /var/git/myapp.git
  • $ exit


    Add the remote repository to your existing local git repo and push:
    

  • $ cd /var/www/myapp
  • $ git init
        (initializes the repository)

  • $ git add .
        (add those 'unknown' files)

  • $ git commit
        (commit all changes, edit changelog entry)

  • $ git rm --cached
        (ridiculously complicated command to undo, in case you forgot .gitignore)  

  • $ git remote add origin ssh://myserver.com/opt/git/myapp.git
  • $ git remote
  • origin
  • $ cat .git/config
  • [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
    [remote "origin"]
        url = ssh://myserver.com/opt/git/myapp.git
        fetch = +refs/heads/*:refs/remotes/origin/*
  • $ git push origin master

    How to pull files from remote server to empty local repo

  • $ cd /var/www/new_myapp
  • $ git init
        (initializes the repository)

  • $ git remote add origin ssh://myserver.com/opt/git/myapp.git
  • $ git remote
  • origin
  • $ cat .git/config
  • [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
    [remote "origin"]
        url = ssh://myserver.com/opt/git/myapp.git
        fetch = +refs/heads/*:refs/remotes/origin/*
  • $ git pull origin master

    How to push updates

  • $ cd /var/www/myapp
  • make some changes on the file(s)
  • $ git commit -a -m ""
  • $ git status
        (view the status)
  • $ git log
        (view the logs)
  • $ git push origin master
  • or
  • $ git push
  
    How to pull updates
  • $ cd /var/www/myapp
  • $ git fetch
  • $ git merge origin/master
  • or
  • $ git pull origin master
  
    note: if failed, try to commit first right after you fetch
    $ git diff            # to see the difference between files

    How to add files to remote repo

  • $ git add
  • $ git commit -a -m
  • $ git push origin master

    How to clone files from repo:
  • $ git clone ssh://myserver.com/opt/git/myapp.git

Monday, June 21, 2010

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2000): mysqlnd cannot connect to MySQL 4.1+ using old authentication

Reset your existing password to a new format.
This happened because you upgraded your mysql server to 5.x and passwords
are in 4.x format.
This will also happen if your database is accessed by
some outdated clients not supporting the new format.

Sunday, June 20, 2010

MYSQL: How to fetch the last inserted row

$last_date = mysql_query("SELECT date FROM data ORDER BY date DESC LIMIT 1");

MYSQL: How to fetch a single row

mysql_fetch_row — Get a result row as an enumerated array

Example:
<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // 42
echo $row[1]; // the email value
?>

Wednesday, June 16, 2010

FreePBX - Cannot receive incoming calls but can make outgoing calls

Situation : Dynamic IP 
  • Inform bandwidth.com for the new IP
  • Login to FreePBX admin panel
  • Go to "Trunks"
  • Select a trunk to edit
  • Change the externip of both outgoing and incoming settings to its new IP

How to connect to a remote mySQL database using PHP

  1. You need to access the remote server or get in touch with the remote server's tech support.
  2. Then
    use the_database_name;

    GRANT ALL PRIVILEGES ON
    the_database_name.*
    TO
    'the_user_in_php_code'@'%'
    IDENTIFIED BY
    'password_of_the_user_in_php_code';

    FLUSH PRIVILEGES; 
  3. If you are using phpmyadmin in your remote server, simply login and add a privileged for your host.
    - Select the database from the list
    - Click Privileges
    - Click "Open new phpMyAdmin window" which can be found in the bottom right corner
    - Click "Add a new User" which is located below the list.
    - Fill in the form.

    -- User name: desired_user_name
    -- Host: your_IP_given_by_your_internet_service_provider
    -- Password: desired_password
    -- Re-type: desired_password

    - Click "Go"
    - In the "Database-specific privileges" section select the database for the "Add privileges on the following database:" field.
    - Select "Check All" and Click "Go"
    - Done.
Note: edit /etc/mysql/my.cnf
bind-address            = local ip (example: 192.168.2.80)
restart mysql or restart computer

Sunday, June 13, 2010

How to setup multiple sites in magento

  1. Create a new folder and copy index.php and .httaccess file.
  2. Edit index.php to allow it to access the mage.php file.
  3. Create symbolic links for js, media, and skin.
  4. Create a root category for this website.
  5. Setup a website, store, and store view.
  6. Setup Web configuration for the new website
  7. Point the unsecure and secure base url for the new website url

Monday, June 7, 2010

How to create symbolic link in linux

ln -s /path/to/real/file /path/to/non-existant/file

how to create symbolic links to all contents of a certain folder

cd /destination_folder
ln -s /source_folder/* -t .

Tuesday, June 1, 2010

how to release/renew ip in linux

ifconfig eth0 down - release

ifconfig eth0 up  - renew