- Download maven from Apache website (http://maven.apache.org/download.cgi)
- Extract the downloaded file, put the extracted file to /usr/bin
tar xzvf apache-maven-[version]-bin.tar.gz C /usr/bin
-
Then go to the /usr/bin directory and create symlink (symbolic link) for maven.
cd /usr/bin ln -s apache-maven-[version] maven
- Then, do the following:
vi /etc/profile.d/maven.sh
Put below code into the vi editor and save it:
export M2_HOME=/usr/local/maven export PATH=${M2_HOME}/bin:${PATH}
- Then log-out and log-in again to activate the above environment setting.
- To check maven is running ok on your computer, type the following using terminal:
mvn -version
Sunday, February 23, 2014
Install Maven on CentOS 6.5
Thursday, December 5, 2013
[Linux] Put backslash \ to the filename that contains space
Let say you have folder like below:
Type the command like below:
Output:
myFolder |_ text file one.txt |_ text file two.txt |_ text file three.txt
Type the command like below:
ls myFolder/* | sed 's/ /\\ /g'
Output:
myFolder/text\ file\ one.txt myFolder/text\ file\ two.txt myFolder/text\ file\ three.txt
Sunday, November 10, 2013
[PHP] - Download mutiple BLOB data and convert into file system
Last
week I was struggled on how to convert data that stored on DB BLOB into
the file system. There are more than 100 rows on that tables.
Whoooaaaarrgghhhh!!. So how I’m gonna save it? The user needs those
files in soft copy (I mean the file will be save in a thumbdrive). After
few hours googling and read some forums, I came out with the solution
that can be useful to others.
Now go to the $path folder that you declared in above script. Select all files, right click and save to thumbdrive.
/**
* @author MJMZ
* @copyright 2012
* Description : This file will be used to convert all the BLOB
* contents and save into the file system.
*
*/
include("../../../lib/db_common.php");
/* get document_id, document_name, folder_id, document_fileType, document_fileName */
$sql = 'SELECT document_id,
document_name,
folder_id,
document_fileType,
document_fileName
FROM portal_document_upload';
$result = $db->query($sql);
$doc = array();
while($rows = mysql_fetch_array($result))
{
$doc[] = array('docId' => $rows['document_id'],
'exacFilename' => $rows['document_fileName'],
'filename' => $rows['document_name'],
'filetype' => $rows['document_fileType']);
}
foreach($doc as $a => $key)
{
// get the file extension : This code will only work only
// if file got 1 extension. If the file got many extension
// such as filename.tar.gz, this code will not work at all.
// Try find another solution for that particular file.
$fileXtension = pathinfo($key['exacFilename'], PATHINFO_EXTENSION);
// If we select the blob in the first query, it will
// cause bad queries @ mysql log.
// So we select the blob in foreach based on their document_id.
$sql_file_contents = "SELECT document_fileData
FROM portal_document_upload
WHERE document_id ='".$key['docId']."'";
$theFile = $db->query($sql_file_contents);
$row = mysql_fetch_array($theFile);
// For precaution, we find the empty string @ filename
// and replace them with _ (underscore) in order to avoid
// the filename missing their extension.
$rawFile = str_replace(" ","_", $key['filename']).".".$fileXtension;
// the path for downloaded file.
$path = "/home/httpd/files_convert/".$rawFile;
if (file_put_contents($path, $row['document_fileData']) === FALSE ) {
echo "Could not write PDF File";
} else {
file_put_contents($path, $row['document_fileData']);
}
}
?>
Now go to the $path folder that you declared in above script. Select all files, right click and save to thumbdrive.
[Linux] - Automatically backup project and database @ Midnight using cron
Since the tragedy happened cause by someone, the entire server
of our application "SRM" will not be recovered at all. This including the program’s source
code and MySQL database. So we decided to do a daily backup of both the
database and source code during 00:00:00 o’clock. This script will only
work on linux server. You can use the same code. Just change certain
variable value.
Save this code as “backup” and chmod this script to 755 and put it under /etc/cron.daily (make sure you have the root permission).
Now your daily backup will be stored in folder that you declared in step 1 of this script (in this example, it will put on folder /backup).
################################################ # Backup source code and MySQL DB # softboxkid - 09 Mar 2012 ################################################ # Please change the value of below variables: # DO NOT CHANGE THE VARIABLE NAME. DBNAME=your_db_name DBPASS=your_db_password DBUSER=your_db_user FOLDER_NAME=the_folder_name_for_backup DATE=`date +%Y%m%d_%H%M` echo "Backup in progress..." echo "Start time". $(date +%k:%M:%S) # Step 1: prepare to backup application source code begin here. mkdir /backup/$FOLDER_NAME-$DATE cp /your/source_code/path -r /backup/$FOLDER_NAME-$DATE # Step 2: prepare to backup mysql database begin here. echo "Start time". $(date +%k:%M:%S) mysqldump -u $DBUSER -p$DBPASS $DBNAME > /backup/$FOLDER_NAME-$DATE/$DBNAME.sql echo "end time". $(date +%k:%M:%S) # Step 3: prepare archive tar.gz for FOLDER_NAME cd /backup tar -cvf $FOLDER_NAME-$DATE.tar $FOLDER_NAME-$DATE gzip $FOLDER_NAME-$DATE.tar # Step 4: remove non-zip file/folder rm -r $FOLDER_NAME-$DATE echo "Your source code and MySQL has been backup $FOLDER_NAME-$DATE.tar.gz time finished time" echo "end time". $(date +%k:%M:%S)
Save this code as “backup” and chmod this script to 755 and put it under /etc/cron.daily (make sure you have the root permission).
Now your daily backup will be stored in folder that you declared in step 1 of this script (in this example, it will put on folder /backup).
Monday, October 28, 2013
[MySQL] - Host 'xxx.xxx.x.xx' is not allowed to connect to this MySQL server
This problem happen when the mysql server doesn't allow remote connection.
So first, go to the mysql server that you want to access.
- Use putty (for windows) or terminal (for unix/linux) and perform the ssh
ssh root@xxx.xxx.x.xx
Enter password:(enter the server's password) - Then type:
mysql -u root -p
Enter password:(enter the mysql password) - Then type the following command:
GRANT ALL PRIVILEGES ON *.* TO your_mysql_user@'%' IDENTIFIED BY 'your_mysql_password';
your_mysql_user and your_mysql_password.Now you can access the mysql server through remote connection.
Friday, October 25, 2013
[Centos] - Yum with proxy
Just add the following on environment variable in .bash_profile file:
Now you can yum as usual.
export http_proxy=http://ip:port
Now you can yum as usual.
Tuesday, October 1, 2013
[PHP] - Encode / Decode paramater on the URL using base64
function my_base64_encode($input) {
return strtr(base64_encode($input), 'AEIOUj', '+-_,');
}
function my_base64_decode($input){
return base64_decode(strtr($input, '+-_,', 'AEIOUj'));
}
$texttoencode = 'RAIHAN';
$b = my_base64_encode($texttoencode);
// the value of $b now is UkFJS-F,
$c = my_base64_decode($b);
// the value of $c is RAIHAN
Subscribe to:
Posts (Atom)