Archive for the ‘PHP/MySQL’ Category

Integrating ICICI Payment Gateway in Linux with Plesk or Cpanel

Thursday, May 5th, 2011

After multiple attempts we have finally being successful in integrating the ICICI Bank online payment gateway in our Linux severs with Plesk and cPanel. Below are the steps that may help you in configuring the same on your server.

Configuration for PLesk

1. Download the SFA files from the ICICI merchant area and extract on the webserver under ICICI folder.
Extract the sfa.jar file in “SFA_Dependencies” and edit the sfa.properties file with the following entries:
verbose=true
Key.Directory=/var/www/key
OS.Type=UNIX
traceLog=/var/log/tomcat5/icici.log
2. Copy the ICICI JAR files from “SFA_Dependencies” folder to the following folders
  • JAR Files to copy: cryptix32.jar, jcert.jar, jnet.jar, jsse.jar, servlet.jar, sfa.jar
  • Copied jar files to  /usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/ from /var/www/vhosts/domainname.com/httpdocs/ICICI/SFA_Dependencies [run this stape after installation of JavaBridge]
  • Reset permissions to these files to tomcat:tomcat under the lib folder
  • Also copy the jar files to /usr/share/tomcat5/common/lib folder
  • Change the owned and group of copied files as per the existing folder owner (Optional and ensure having 777 permissions on the above folder).
3. Download JavaBridge from below URL
  • # wget http://sourceforge.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_6.2.1/php-java-bridge_6.2.1_documentation.zip/download
Install JavaBridge with the following steps:
  • Unzip the php-java-bridge_6.1.2.1_documentation.zip
  • # java -classpath JavaBridge.war TestInstallation
  • # cp JavaBridge.war /var/lib/tomcat5/webapps/.
  • # service tomcat5 restart
  • Test the installation at http://plesk02.diadem-tech.com:8080/JavaBridge
Reference URLs:
  • http://php-java-bridge.sourceforge.net/pjb/tomcat6.php
  • http://php-java-bridge.sourceforge.net/pjb/installation.php
4. Edit the file /var/lib/tomcat5/webapps/JavaBridge/WEB-INF/cgi/php.ini with below lines.
;; -*- mode: Scheme; tab-width:4 -*-
;; A simple php.ini
;; extension_dir is this “cgi” directory
extension_dir=.
;; include php libraries from these directories
include_path=.:/usr/share/pear
java.classpath = /usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/cryptix32.jar;/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/jcert.jar;/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/jnet.jar;/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/jsse.jar;/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/servlet.jar;/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/sfa.jar;
5. Edit /root/.bash_profile to set CLASSPATH as env variable and add the below lines.
include_path=.:/usr/share/pear
CLASSPATH=$CLASSPATH:/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/cryptix32.jar;
CLASSPATH=$CLASSPATH:/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/jnet.jar;
CLASSPATH=$CLASSPATH:/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/servlet.jar;
CLASSPATH=$CLASSPATH:/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/sfa.jar;
CLASSPATH=$CLASSPATH:/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/jcert.jar;
CLASSPATH=$CLASSPATH:/usr/share/tomcat5/webapps/JavaBridge/WEB-INF/lib/jsse.jar;
export include_path
export CLASSPATH
Run the following commands from shell:
  • #. .bash_profile to set the environment variable.
  • # env to check the environment variables.
  • # service tomcat5 restart – Tomcat restart
6. Configure Tomcat to use SUN Java
  • # vim /etc/sysconfig/tomcat5
Comment the existing JAVA_HOME and add the below line
JAVA_HOME=”/usr/java/jdk1.6.0_20/” (The JDK version will change as per the installed version)
Restart Tomcat
  • # touch /var/log/tomcat5/icici.log
  • # chown tomcat.tomcat /var/log/tomcat5/icici.log
7. Stop Apache and Tomcat and then copy the following key files to the /var/www/key directory:
  • 0000XXXX.key
  • intermediate.cer
  • payseal.icicibank-chain-bundle.cer
The .cer files can be found under the cert_bundle folder provided by ICICI. The key file also needs to be downloaded from the merchant admin site or provided by ICICI.
  • Start Apache and Tomcat.
Run the following keyrestore command from the /var/www/key folder:
# keytool -import -alias pgIntermediateCA -file ./intermediate.cer -keystore /usr/java/jdk1.6.0_12/jre/lib/security/cacerts -storepass changeit
This might give an error like keytool error: gnu.javax.crypto.keyring.MalformedKeyringException: incorrect magic which can be ignored.
8. Update the TestSSL.php page and change the response URL and use the updated file:
$oMerchant->setMerchantDetails(“0000XXXX”,”0000XXXX”,”0000XXXX”,”193.545.34.33″,rand().”",”Ord123″,”http://10.10.10.147:8756/SFAResponse.php”,”POST”,”INR”,”INV123″,”req.Preauthorization”,”100″,”",”Ext1″,”true”,”Ext3″,”Ext4″,”Ext5″);
Also in SFAResponse.php and “./Sfa/PostLibPHP.php” file on line 2 would also change from
‘ require_once(“java/Java.php”);’ to ‘ require_once(“java/Java.inc”);’
Test the TestSSL and Testjava pages
  • http://domainname.com/ICICI/SFAClient/TestPages/testjava.php
  • http://domainname.com/ICICI/SFAClient/TestPages/TestSsl.php
Hopefully the above links would work and the error output log can be checked at:
  • # tail –v –f /var/www/vhosts/pgtest.domainname.com/statistics/logs/error.log

cPanel configuration

For cPanel you need to install Tomcat and FastCGI module in PHP to run ICICI PG, below are the steps.
1. Login WHM with root user
2. In the Main page  click on Software and then EasyApache (Apache Update)
3. Go through each step as follows.
a) Click “Start customizing based on profile”
b) Select Apache Version – Click Next to proceed with the current version.
c) Select PHP Major Version – Click Next to proceed with the current version.
d) Select PHP Minor version – Click Next to proceed with the current version.
e) Short option list – Click “Exhaustive Options List” to view full options.
Exhaustive Options List – From here you can select the PHP modules you needed
Select mod_fcgid (FCGI module for Apache), FCGI and Tomcat (you can also select other PHP module for future requirement e.g. GD, SOAP, curl, Zend, Zlib, Zip bizip, MySQLi )
f) Click “Save & Build” to start apache-php compilation.
4. Once the compilation over you can verify the installed PHP modules using the following command.
# php –m
And Tomcat from the URL: http://server ip:8080
5. After the installation of Tomcat defines the following important environment variables in /root/.bash_profile
CATALINA_HOME=/usr/local/jakarta/tomcat
CATALINA_BASE=/usr/local/jakarta/tomcat
JAVA_HOME=/usr/local/jdk/
export CATALINA_HOME CATALINA_BASE JAVA_HOME
Now run “#. .bash_profile” command from shell to set the environment variable.
All done now start the ICICI Payment Gateway Integration same as Plesk steps. Only the tomcat path is different i.e. /usr/local/jakarta/tomcat.

Tips to optimise MySQL server performance

Tuesday, January 11th, 2011

Here are a couple of tweaks which can improve your mysql server performance significantly. We implemented this on our hosted servers and the php/mysql queries for dynamic DB driven applications  improved by over 50%. The following are the relevant commands which can be inserted in the mysql conf file, which is normally located at /etc/my.cnf.

# Improves mysql server performance by disabling name resolution and remote mysql connections
skip-name-resolve
skip-networking

The skip-name-resolve option will disable name resolution for hostnames and the skip-networking option would disable remote connections to be made to the local MySQL server. This is a recommended setting and would improve your server security as well.

Feel free to post your queries and share any other optimisation tips as well!

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 2.50 out of 5)
Loading ... Loading ...

Setting up and getting DOMpdf to work in XAMPP on Windows

Monday, November 23rd, 2009

Setting up the Dompdf (a pdf generation package in php) in XAMPP in windows environment can sometimes be an issue.
After we have set up the package in the htdocs and go for testing the examples in the packages , error is encountered which is as follows-

A PHP Error was encountered
Severity: Warning
Message: domdocument::domdocument() expects at least 1 parameter, 0 given
Filename: include/dompdf.cls.php
Line Number: 165
Fatal error: Call to undefined method domdocument::loadHTML() in C:\xampp\htdocs\bambooinvoice\bamboo_system_files\plugins\dompdf\include\dompdf.cls.php on line 284


The error message is caused due to a conflict between DomDocument and DomXML extentions , so the first thing we did was to disable the domdocument extention in php.ini.
extension = php_domxml.dll

After restarting the apache and then again running the examples again blank pages were being rendered. The problem was due to the fact that dompdf uses PDFLib by default if it is available in the system and PDFLib is a commercial package which is not available by default in the system but its extention is enabled in php.ini by default in the system.

So what we did was to comment out the PDFLib extension extension=php_pdf.dll in the php.ini file. After the modifications we restarted the apache and then the examples could be run on the XAMPP environment.

Improve Security using php.ini

Wednesday, March 25th, 2009

PHP has some vulnerable functions which can be used to break into your server if your scripts are not coded securely. You can setup a list of functions in php.ini using disable_functions directive. This directive allows you to disable certain functions for security reasons. It takes on a comma-delimited list of function names. This disable_functions feature is not affected by Safe Mode. This directive must be set in php.ini For example, you cannot set this in httpd.conf

Open php.ini file:

#vi /etc/php.ini

Find disable_functions and set new list as follows:

disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_exec,

curl_multi_exec,parse_ini_file,show_source

Save and close the file. Restart httpd:

# service httpd restart

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

Creating image thumbnails in php

Thursday, March 19th, 2009

Thumbnail are used by graphic designers and photographers for a small image representation of a larger image. The main advantage of creating thumbnails is that it generates the new image with the proportional dimension of the large image and hence the image resolution and quality remain intact. As the thumbnails are smaller in size they load quickly and makes the page render faster as well.

We are using a thumbnail class to make code simpler and easy to use. Image extensions with jpg, gif and png are supported for creating thumbnail using this class.

Three easy steps to create and image thumbnail :

Step 1. Create a folder and named  as createThumb.  Create a file named thumbnail_Class.php in the createThumb folder and paste the code given below into it.

<?
function createThumb($srcname,$destname,$maxwidth,$maxheight)
{
$oldimg = $srcname;
$newimg = $destname;

list($imagewidth,$imageheight,$imagetype)=@getimagesize($oldimg);

$shrinkage = 1;
if ($imagewidth > $maxwidth)
$shrinkage = $maxwidth/$imagewidth;
if($shrinkage !=1)
{
$dest_height = $shrinkage * $imageheight;
$dest_width = $maxwidth;
}
else
{
$dest_height=$imageheight;
$dest_width=$imagewidth;
}
if($dest_height > $maxheight)
{
$shrinkage = $maxheight/$dest_height;
$dest_width = $shrinkage * $dest_width;
$dest_height = $maxheight;
}
if($imagetype==2)
{
$src_img = imagecreatefromjpeg($oldimg);
$dst_img = imagecreatetruecolor($dest_width, $dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
imagejpeg($dst_img, $newimg, 75);
imagedestroy($src_img);
imagedestroy($dst_img);
}

elseif ($imagetype == 3)
{
$src_img = imagecreatefrompng($oldimg);
$dst_img = imagecreatetruecolor($dest_width, $dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
imagepng($dst_img, $newimg, 75);
imagedestroy($src_img);
imagedestroy($dst_img);
}
else
{
$src_img = imagecreatefromgif($oldimg);
$dst_img = imagecreatetruecolor($dest_width, $dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
imagegif($dst_img, $newimg, 75);
imagedestroy($src_img);
imagedestroy($dst_img);
}
}
?>

Step 2. Create a file named index.php with in this folder and paste the code given below inside index.php. This is the file which you need to run from the browser. Place your image (e.g., grapes.jpg) to create thumbnail within the createThumb folder.

<?
include(‘thumbnail_Class.php’);

$filePath    =    ‘grapes.jpg’;
$destPath    =    ‘Thumb_grapes.jpg’;
$maxwidth        =    450;
$maxheight        =    300;
createThumb($filePath,$destPath,$maxwidth,$maxheight);

echo ‘Thumbnail Created.’;
?>

Step 3. Finally, Run the index.php from your browser and if your thumbnail is created successfully then you will get an message “Thumbnail Created” and the thumnail image will create in createThumb folder with name Thumb_grapes.jpg.
(more…)