Practical Web Programming

Tuesday, April 15, 2014

Using scp (Secure Copy) to Copy Files from Remote Server

Copy a file from a remote host to a local machine

$ scp username@example.com:/home/kabalweg/my_archive.ta.gz /home/kabalweg/local

Copy a file from a local machine to a remote host

$ scp /home/kabalweg/local/my_archive.tar.gz username@example.com:/home/kabalweg
 

Compress/Uncompress in Linux/Unix

Compress the folder named sites inside the /home/kabalweg directory:

$ tar -zcvf my_archive.tar.gz /home/kabalweg/sites

Uncompress file into the current directory:

$ tar -zxvf my_archive.tar.gz

Where: 
z = compress archive using gzip program
c = create archive 
v = verbose i.e display progress while creating archive
f = archive File name 
x = extract files

Watching Log Files Using tail and less

Watch the error log and filter the output to the screen (using grep).

tail -f /var/log/apache/error.log | grep -v Exception | grep -v 'PHP Notice'

Output the error log to the screen, filter it before doing so (using grep).

less +F /var/log/apache/error.log | grep -v Exception | grep -v 'PHP Notice'

Note:

-v parameter in grep is reverse look up. It mean, all text except 'Exception' and 'PHP Notice'


Forward and Backward Search in less

/ – search for a pattern which will take you to the next occurrence. 
? – search for a pattern which will take you to the previous occurrence. 
n – for next match in backward direction 
N – for previous match in forward direction
Shift F - similar to tail -f

How to Create User in Mysql

Create the user that can access mysql via localhost:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';


If you want the user to access the database from anywhere, then use this:


CREATE USER 'username'@'%' IDENTIFIED BY 'password';


Give the new user permission to access all databases and all its tables:

GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';


Reload the privileges:

FLUSH PRIVILEGES;

Recent Post