Wednesday, November 17, 2010

Installation of mysql, required php libraries and phpmyadmin at centOS

Here are the steps which I have followed:

/*************************************************commands***************************/
yum install mysql-server mysql
To start mysql server type the following command:
chkconfig mysqld on
/etc/init.d/mysqld start
Type the following command to setup a password for root user:
mysqladmin -u root password NEWPASSWORD
Test mysql connectivity

Type the following command to connect to MySQL server:
$ mysql -u root -p
/************************************************* end commands***************************/

/************** required commands for phpmyadmin**************************/
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
cd /tmp
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
rpm -ivh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
yum install php-mysql php-mbstring php-mcrypt phpmyadmin
/************** required commands**************************/
/**** changess to access phpmyadmin from not just localhost***/
Run command "mysql_secure_installation"
vi /etc/httpd/conf.d/phpmyadmin.conf
Comment as:
#
# Web application to manage MySQL
#

#<Directory "/usr/share/phpmyadmin">
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
#</Directory>

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

Edit phpmyadmin config
vi /usr/share/phpmyadmin/config.inc.php
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
Then we create the system startup links for Apache and start it:

chkconfig --levels 235 httpd on
/etc/init.d/httpd start

/**** end changess to access phpmyadmin from not just localhost***/

Enjoy Programming!!!

Friday, October 15, 2010

Printing selected portion of the page

Jquery plugin:
// Create a jquery plugin that prints the given element.
jQuery.fn.print = function(sitePath,titleUsed){
// NOTE: We are trimming the jQuery collection down to the
// first element in the collection.
if (this.size() > 1){
this.eq( 0 ).print();
return;
} else if (!this.size()){
return;
}

// ASSERT: At this point, we know that the current jQuery
// collection (as defined by THIS), contains only one
// printable element.

// Create a random name for the print frame.
var strFrameName = ("printer-" + (new Date()).getTime());

// Create an iFrame with the new name.
var jFrame = $( "<iframe name='" + strFrameName + "'>" );

// Hide the frame (sort of) and attach to the body.
jFrame
.css( "width", "1px" )
.css( "height", "1px" )
.css( "position", "absolute" )
.css( "left", "-9999px" )
.appendTo( $( "body:first" ) )
;

// Get a FRAMES reference to the new frame.
var objFrame = window.frames[ strFrameName ];

// Get a reference to the DOM in the new frame.
var objDoc = objFrame.document;

// Grab all the style tags and copy to the new
// document so that we capture look and feel of
// the current document.

// Create a temp document DIV to hold the style tags.
// This is the only way I could find to get the style
var cssLink = '<link rel="stylesheet" type="text/css" href="'+sitePath+'jprint.css" media="print"/>';

// Write the HTML for the document. In this, we will
// write out the HTML of the current element.
objDoc.open();
objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
objDoc.write( "<html>" );
objDoc.write( "<body>" );
objDoc.write( "<head>" );
objDoc.write( "<title>" );
objDoc.write(titleUsed);
objDoc.write( "</title>" );
objDoc.write(cssLink);
objDoc.write( "</head>" );
alert(this.html());
objDoc.write( this.html() );
objDoc.write( "</body>" );
objDoc.write( "</html>" );
objDoc.close();

// Print the document.
objFrame.focus();
objFrame.print();

// Have the frame remove itself in about a minute so that
// we don't build up too many of these frames.
setTimeout(
function(){
jFrame.remove();
},
(60 * 1000)
);
}
/********************************************************************/
jprint.css

body{
padding:0px;
margin:0px;
font:normal 12pt Arial, Helvetica, sans-serif;
background: #FFFFFF;
color: #000000;
}

.printable {
padding: 10px 10px 10px 10px ;
}
img{
background-color: #E0E0E0 ;
border: 1px solid #666666 ;
padding: 5px 5px 5px 5px ;
}
table{
width:99%;
border:#9e9e9e solid 1px;
margin:0 0 5px 0;
font:normal 13px Arial, Helvetica, sans-serif;
}

table th{
padding:10px 8px 12px 8px;
text-align:left;
background-color:#FAFAFA;

}
table td{
padding:8px;
text-align:left;
}

table tr{
background-color:#f2f2f2;
}

table tr.alternet{
background-color:#e0e0e0;
}

table td.Heading{
height:35px;
padding:0px 0 0 10px;
border-bottom:#9e9e9e solid 1px;
font:normal 15px Arial, Helvetica, sans-serif;
color:#fff;
}
a:link, a:visited {
color: #000000;
background: transparent;
font-weight: bold;
text-decoration: none;
}

/****************************************************************/
Usage

$(document).ready(function(){

// When the document is ready, initialize the link so
// that when it is clicked, the printable area of the
// page will print.
$(function(){
// Hook up the print link.
$( "a#print_icon" )
.attr( "href", "javascript:void( 0 )" )
.click(
function(){
// Print the DIV.
//@param1 - site URL
//@param2 - Title of the page
$( ".printable" ).print('<?php echo SITE_HTTP_URL;?>','Invoices');
// Cancel click event.
return( false );
}
);
});
});

PHP – Oracle

Initial requirement:
OCI8 module must be installed to use oracle database
Client to access database:
1. “Toad for Oracle” is the best option to access oracle database with “11.2.0” oracle client. You will need to install oracle client first from the oracle distribution CD and then Toad software will automatically detect oracle client.
2. Another option is default SQL*Plus

Friday, June 18, 2010

FFMPEG installation for Fedora11 and useful information to dive in video streaming using PHP

FFMPEG installation for Fedora11 and useful information to dive in video streaming using PHP:
1. Open the command prompt (terminal) window
2. Run the Su command if not log in as admin (root)
I. Su (Enter)
II. Enter root password
3. Run the command: yum install ffmpeg ffmpeg-devel
4. To check what audio/video formats are supported
I. Run the command: ffmpeg -formats > ffmpeg-format.txt
II. Open the ffmpeg-formats.txt to see the ooutput
D means decode
E means encode
V means video
A means audio
T = Truncated
5. Install FFMPEG-PHP Extension
I. FFmpeg-php is a very good extension and wrapper for PHP which can pull useful information about video through API interface. Inorder to install it you will need to download the source file and then compile and install extension in your server. You can download the source tarball : http://ffmpeg-php.sourceforge.net/
II. tar -xjf ffmpeg-php-X.x.x.tbz2
III. cd ffmpeg-php-X.x.x/
IV. phpize
Common Errors
I. If you get command not found error for phpize, then you will need to do yum install php-devel
II. If you get error like "ffmpeg headers not found" while configuring the source.
configure: error: ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the --enable-shared option
then it means you need to copy libraries to ffmpeg folder itself.
To Fix:
V. cp /usr/include/ffmpeg/lib*/* /usr/include/ffmpeg/
VI. ./configure
VII. make
VIII. make install
6. Editing php.ini (For me, path is etc/php.ini)
Put the below two lines at the end of the php.ini file
[ffmpeg]
extension=ffmpeg.so
7. You can check the installation by running php script
phpinfo();
?>

Reference Links:
1. http://www.mysql-apache-php.com/ffmpeg-install.htm
2. http://ffmpeg-php.sourceforge.net/
3. http://www.lampadmins.com/f9/ffmpeg-shared-libraries-header-files-663/
Useful Links:
1. http://vexxhost.com/blog/2006/12/20/what-ffmpeg-php-can-do-and-how-to-use-the-most-out-of-it/
2. http://www.phpclasses.org/package/3747-PHP-Manipulate-and-convert-videos-with-ffmpeg-program.html
3. http://howto-pages.org/ffmpeg/

Enjoy Programming !!!

Thursday, April 29, 2010

Flex Data Services and PHP

I really find this article helpful to start flex with PHP.

Have a look into it:

http://www.adobe.com/devnet/flex/articles/flex_php_architecture.html

Enjoy Programming!!

Monday, April 12, 2010

Comparing floating point numbers

How to compare floating point numbers.

I found this URL really nice if we are in need to compare floating point numbers:

http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

Enjoy Programming !!

Friday, March 26, 2010

Server migration of Magento

1. Take the back of backup of old database (backup/data.sql).
2. Take the backup of your Themes/Templates (app/design/frontend), Skins, Images (media), local.xml (app/etc/loca.xml) and Custom Modules folders.
3. Change your current directory to magento ((/var/www/html/magento).
4. Change permissions for some of the directories of magento folder.
i. mv php.ini.sample php.ini
ii. chmod o+w var var/.htaccess app/etc
iii. chmod -R o+w media
5. Place the backup of old database (backup/data.sql).
6. mysql -hDBHOST -uDBUSER -pDBPASS DBNAME < backup/data.sql
7. Run magento installer and follow the installation steps.

8. Replace the backup of Themes/Templates (app/design/frontend), Skins, Images (media) and Custom Modules folders.

9. Update
You need to edit a few things in the database if your changing domain names or if you’re using a test server that’s just an IP address. Using PHPMyAdmin, Navicat or something similar, connect to the database. Table core_config_data has rows that need to be changed and updated with the new url. For a single store installation you need to just update:
path: value:
web/unsecure/base_url http://[you_domain_here]/
web/secure/base_url https://[your_secure_domain_here]/
With multiple stores you need also change:
path: value:
web/unsecure/base_url http://[you_domain_here]/
web/secure/base_url https://[your_secure_domain_here]/
web/unsecure/base_link_url http://[your_domain_here]/
web/unsecure/base_skin_url http://[your_domain_here]/skin/
web/unsecure/base_media_url http://[your_domain_here]/media/
web/unsecure/base_js_url http://[your_domain_here]/js/
web/secure/base_link_url https://[your_secure_domain_here]/
web/secure/base_skin_url https://[your_secure_domain_here]/skin/
web/secure/base_media_url https://[your_secure_domain_here]/media/
web/secure/base_js_url https://[your_secure_domain_here]/js/

Enjoy Programming!!

Wednesday, March 17, 2010

WAP Redirect

Recently I add a new class for WAP redirection in php classes . It's link is http://www.phpclasses.org/browse/package/6060.html.

This class can be used to redirect mobile phone users.

It can check the user agent string sent by the user browser and redirect to different URLs depending on the type of device that is use to access the current page.

Currently it can redirect to different URLs depending on whether the user device is an iPhone, a PlayStation or another device that supports WML.

Enjoy Programming!!!

Wednesday, February 17, 2010

QR (Quick Response) Code

Abstract from the Wikipedia

"A QR Code is a matrix code (or two-dimensional bar code) created by Japanese corporation Denso-Wave in 1994. The "QR" is derived from "Quick Response", as the creator intended the code to allow its contents to be decoded at high speed.

QR Codes are common in Japan, where they are currently the most popular type of two dimensional codes. Moreover, most current Japanese mobile phones can read this code with their camera."

As a web developer, I see it's heavily use in implementations of the cloud systems.
Recently, I used this for one of my client from US. I expect it's support shortly in India too.

Enjoy Programming!!!

Thursday, January 21, 2010

How to write UTF-8 data in csv

I was facing problem in writing UTF-8 data (Espanol) in CSV.
Below is the solution in PHP:


$data = "Plan du site,jusqu'à 80 %,économiser";
$data = mb_convert_encoding( $data, 'UTF-16LE', 'UTF-8');
$filename = "data.csv";
//and then add a couple of extra magic bytes before the data:
$data = chr(255).chr(254).$data;
//Then send your headers and the data. $filename should be something meaningful ending in .csv. I suggest including a random number or timestamp to defeat caching.
$size = strlen($data);
header("Content-type: application/vnd.ms-excel; charset=UTF-16LE");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Length: $size");
echo $data;


Enjoy Programming!!!