PHP

Howto: Installing GnuPG for php 5.3 on Centos6

Posted on Updated on

What is GnuPG ?

GNU Privacy Guard(gnupg) is a cryptographic software mostly used for Filecrypt, it is available for the following tools bash,php,python,perl modules. The statergy for using GnuPG is to be secure the data while digital transportation.

Please refer the Wiki for more information : http://en.wikipedia.org/wiki/GNU_Privacy_Guard

I followed the below steps to install GnuPG.

1, Install Dependency packages gnupg libgpg-error gpgme libgpg-error-devel gpgme-devel
2, Install/Enable PHP module
3, Restart Apache

Install dependencies:

[root@planetcure:~]# yum install gnupg libgpg-error gpgme libgpg-error-devel gpgme-devel php-devel

Installing PHP module using PECL repository

[root@planetcure:~]# pecl install gnupg

Enabling php support

[root@planetcure:~]# echo -e '; Enable GnuPG extension module\nextension=gnupg.so' > $(php --ini | grep "additional .ini" | awk -F: '{print $2}')/gnupg.ini

Verifying installation

[root@planetcure:~]# php --info | grep gnupg
gnupg
gnupg support => enabled

Restarting Httpd

[root@planetcure:~]# service httpd restart

If you need to check through PHP info , create a file info.php with the below code and place it into the web root directory. then call the file through browser it will be looks like the below image.

cat info.php
<?php
phpinfo();
?>

gnupg

 

ERROR: SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified

Posted on Updated on

One of our server getting odbc_connection error after migration, this will usually  happens because ODBC module has not enabled on the server,  While I tried to set up ODBC with freeTDS in order to connect to a MSSQL server faced several issues.

MSSQL uses Tabular Data Stream (TDS) as a communication protocol which is same like in Sybase. freeTDS is an implementation of TDS protocol.

Before trying to connect with freetds to the mssql server, make sure, that your MSSQL server has remote access to connect.

[02-May-2013 02:21:31 America/Denver] PHP Warning: odbc_connect() [<a href='function.odbc-connect'>function.odbc-connect</a>]: SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /home/anand/public_html/mssql2000.php on line 69

We need below packages installed to get this done.

1, php-odbc
2, unixODBC
3, freetds

Installation : 

#pecl  install php-odbc
#yum install unixODBC-devel unixODBC freetds-devel freetds

Or,

Download unixODBC and untar it

#wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.0.tar.gz
#tar –xzf unixODBC-2.3.0.tar.gz
#cd unixODBC-2.3.0 ; ./configure ; make ; make install

Installing freeTDS
Set environmental variable at /etc/profile. Add following lines at end

#vi /etc/profile
 # TDS
SYBASE=/usr/local 
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$SYBASE/lib 
export SYBASE LD_LIBRARY_PATH 
#http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
#tar –xzf freetds*.tar.gz ; cd freetds* ; ./configure --with-tdsver=8.0 --with-unixodbc=/usr/local ; make ; make install

Configuration:
Note: tdsver=8.0 if you use SQL 2000, tdsver=7.0 if you use SQL 7.0, More info about freetds.conf here

root@server [~]# cat /etc/freetds.conf
[MSSQLSERVER]               
host = 11.222.333.44
port = 1433
tds version = 8.0

Setup ODBC:
Create template for both driver and configuration. before creating make sure that the driver files are valid.

root@server [~]# vi tds.driver.template
#Driver for MS SQL
[FreeTDS]                       #"FreeTDS" is the unique name for this driver
Description = FreeTDS driver
Driver = /usr/lib64/libtdsodbc.so.0
Setup = /usr/lib64/libtdsS.so.1
FileUsage = 1
UsageCount =1

root@server [~]# vi tds.datasource.template
[MSSQL]               #"MSSQL" is the DSN name that we call to connect database
Driver = FreeTDS      # name that we specified in the driver file
Description = MSSQL ReflectiveLearning
Trace = No
TraceFile = /var/log/freetds.log
Servername = MSSQLSERVER    # this  name specified in the freetds.conf
Port = 1433
Database = reflective_Live
TDS_Version = 8.0
 Now install the data source and driver

The below commands will create configuration file for odbc but odbc.ini has create in users home dir by default we have to move it manually to /etc/

odbcinst -i -d -f tds.driver.template
odbcinst -i -s -f tds.datasource.template
cp -rpf ~/.odbc.ini /etc/odbc.ini
mv /etc/odbc.ini /usr/local/etc
mv /etc/odbcinst.ini /usr/local/etc
cd /etc
ln -s /usr/local/etc/odbc.ini
ln -s /usr/local/etc/odbcinst.ini
chmod 0664 /usr/local/etc/odbc*.ini
cd ~

check by using command line
#tsql -H Hostname_OR_IP -p PortNumber -U Username

root@server [~]# isql -v DSNname Username 'Password'
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> quit
That’s all, now the application will works fine.
some PHP code to connect to it
<?php
//*************************************************************************
//Open Database Connection
//************************************************************************* 
$dbserver="ipaddress";
$dbusername="tester4";
$dbpassword="password1234";
$defaultdb="testdb";
$cn = mssql_connect($dbserver,$dbusername,$dbpassword) or die("Connection Error");
$db = mssql_select_db($defaultdb,$cn) or die("Database Error");
echo "Connection Success"
?>

Some of the useful commands,

odbcinst -j         # to check the ODBC version and configuration.
odbcinst -q -d   # View loaded drivers.
odbcinst -q -s   # View DSN entry
tsql -LH 22.33.55.44   #To list MSSQL server instant name,version etc.,
osql -S DSN -U Username -P ‘Password’ #list the configuration files loaded to connect ODBC

Install / Enable PHP MsSQL Extension in cPanel/WHM Server

Posted on

For enabling mssql support in PHP on cpanel/WHM installed server we can’t use easyapache in this case,  we need FreeTDS installed and configured which is a set of Unix/Linux libraries that implement the TDS protocol. First we will need to download and install FreeTDS, you can find more information and download link at http://www.freetds.org URL. Note the exact installation steps below :

Packages :
1. unixODBC
2. freeTDS
3. mssql.so
step :1  unixODBC

yum install  unixODBC unixODBC-devel

Step :2  freeTDS

cd /usr/local/src
wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar zfvx freetds-stable.tgzcd freetds-*;
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld; make ; make install 
echo "--with-mssql=/usr/local/freetds" >> /var/cpanel/easy/apache/rawopts/all_php5
touch /usr/local/freetds/lib/libtds.a
touch /usr/local/freetds/include/tds.h

Use this line if you get any error like no such file or directory

ln -s /usr/include/sqlext.h /usr/local/include/sqlext.h

If it it is a 64 bit server then make the following softlink

ln -s /usr/local/freetds/lib/  /usr/local/freetds/lib64

Step :3  mssql.so

Now run Easy Apache and make sure that Mysql, Mysql of the system, amd Mysqli are all selected.

/scripts/easyapache

 Now you can check Mysql enabled

root@server [~]# php --info |grep  "mssql"
MSSQL Support => enabled

Howto: Installing Imagick on PHP

Posted on Updated on

I have recently been installing ImageMagick on my server for use on my other site

First to install ImageMagick:

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar zxvf ImageMagick.tar.gz
cd ImageMagick-
./configure --prefix=$HOME/local -with-gslib --with-gs-font-dir=/usr/share/fonts/type1/gsfonts/ --without-perl
make
make install
Usually you would use --with-perl-options but for some reason versions of ImageMagick after 6.4.5 don’t , You don’t really need it when using ImageMagick with PHP anyway.

Installing Imagick

Installing Imagick. It took a little bit of time but I managed to get it installed. You first need to download, compile & install autoconf & then Imagick.

mkdir ~/source
cd ~/source
wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.63.tar.gz
tar xzf autoconf-2.63.tar.gz
cd autoconf-2.63
./configure --prefix=$HOME/source
nice -n 19 make
make install
export PATH=/home/{username}/source/bin:$PATH
cd ~/
wget http://pecl.php.net/get/imagick-2.2.2.tgz
tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2
phpize
./configure -prefix=$HOME/imagick --with-imagick=$HOME/local --with-php-config=$HOME/php5/bin/php-config
make
make install
Don’t forget to change {username} on line 9 to your username or you’ll get a error.
After that it should tell you the path to imagick.so which you need to instuct your PHP.ini to find. Scroll all the way down until you find extension_dir='./' and change it to the FULL.
path to the folder given by the build of imagick before. Now find the list of extensions which look like ‘;extension=thing_some.dll’ and after the last one add ‘extension=imagick.so’. Now press ESC then colon ‘w’ ‘q’ and enter to quit and save.

Howto: Installing mcrypt, mhash on Apache with PHP5

Posted on Updated on

Get and Install mhash

wget http://internap.dl.sourceforge.net/sourceforge/mhash/mhash-0.9.9.9.tar.gz
or go to sourceforge and find the latest.
tar -xvzf mhash-0.9.9.tar.gz
cd mhash-0.9.9
./configure --prefix=/usr/local/mhash
make
make install

Get and install libmcrypt

wget http://space.dl.sourceforge.net/project/mcrypt/Libmcrypt/Production/libmcrypt-2.5.7.tar.gz

tar -xvzf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt --disable-posix-threads
make
make install

Get and install mcrypt.

wget http://superb-west.dl.sourceforge.net/sourceforge/mcrypt/mcrypt-2.6.8.tar.gz

or go to source forge and get the latest.

tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make
make install

Create the mcrypt php5 module to load.

Find you source code for your php version.

use:

find / -name "php"

mine was found here

/usr/src/redhat/SOURCES/php-5.1.6/
cd to php-5.2.6/ext/mcrypt
phpize
aclocal
./configure
make clean
make
make install

If you are using a 64 bit computer, create a symbolic link.

cd /usr/lib64/modules
ln -s /usr/local/lib/php/extensions/no-debug-non-zts-20050922/mcrypt.so ./mcrypt.so

Create a new file named mcrypt.so in /etc/php.d directory and enter the following.

;Enable mcrypt extension module
extension=mcrypt.so

Create the mhash extension:

cd to php-5.2.6/ext/mhash
phpize
aclocal
./configure
make clean
make
make install
cd /usr/lib64/modules
[root modules]# ln -s /usr/local/lib/php/extensions/no-debug-non-zts-20050922/mhash.so ./mhash.so

Create a new file named mcrypt.so in /etc/php.d directory and enter the following.

;Enable mhash extension module
extension=mhash.so

Bounce Apache

[root /]#service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

Check Apache for mcrypt loaded.
Move to your website loaction and create a file named phpinfo.php and enter.

<?=phpinfo();?>

Now open a brower and point it to your site /phpinfo.php

PHP 5.3 installation on CentOS 5.5

Posted on Updated on

To install, first you must tell rpm to accept rpm’s signed by me, then add the yum repository information to yum:

rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
yum --enablerepo=webtatic install php
yum --enablerepo=webtatic update php

Packages

Package Provides
php mod_php
php-bcmath
php-cli php-cgi, php-pcntl, php-readline
php-common php-api, php-bz2, php-calendar, php-ctype, php-curl, php-date, php-exif, php-fileinfo, php-ftp, php-gettext, php-gmp, php-hash, php-iconv, php-json, php-libxml, php-openssl, php-pcre, php-pecl-Fileinfo, php-pecl-phar, php-pecl-zip, php-reflection, php-session, php-shmop, php-simplexml, php-sockets, php-spl, php-tokenizer, php-zend-abi, php-zip, php-zlib
php-dba
php-devel
php-eaccelerator
php-embedded php-embedded-devel
php-fpm
php-gd
php-imap
php-intl
php-ldap
php-mbstring
php-mcrypt
php-pecl-apc
php-pecl-memcache
php-pecl-xdebug
php-mssql php-pdo_dblib
php-mysql php-mysqli, php-pdo_mysql, php_database
php-odbc php-pdo_odbc, php_database
php-pdo
php-pgsql php-pdo_pgsql, php_database
php-process php-posix, php-sysvmsg, php-sysvsem, php-sysvshm
php-pspell
php-recode
php-snmp
php-soap
php-suhosin
php-tidy
php-xml php-dom, php-domxml, php-wddx, php-xsl
php-xmlrpc
php-zts

“Depsolving” problems

If you get depsolving problems when updating, you may have currently installed some extensions that have been removed, e.g. php-mhash, php-ncurses.

You will need to remove them before upgrading.

yum remove php-mhash php-ncurses

Howto : Enabling memcached extension on php.

Posted on Updated on

Memcached is a general-purpose distributed memory caching system, but is now used by many other sites. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read. Memcached runs on Unix, Windows and MacOS and is distributed under a permissive free software license.

Installation :

You may simply install mamcached using pacl library, but it need the dependency package libmencached download , When compailing you might got an error mamcached not found so tha you may use some parameters with configuring like  –without-memcached

error Output:

checking for memcached session support... enabled
checking for memcached igbinary support... disabled
checking for memcached location... configure: error: libmemcached support requires libmemcached. Use --with-memcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located
ERROR: `/tmp/pear/temp/memcached/configure' failed

Step :1- (Libmamcached Installation )

1.# wget http://launchpadlibrarian.net/73843684/libmemcached-0.50.tar.g
2.# tar -zxvf libmemcached-0.50.tar.g
3.# cd libmemcached-0.5
4.#./configure --without-memcached && make && make install

Step:2 (Memcached installation)

1.#pecl install memcache
2.#echo "extension=/usr/lib/extensions/no-debug-zts-20060613/memcached.so" >> /etc/php.ini

Success Output :

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2" install
Installing shared extensions:     /tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2/usr/lib/extensions/no-debug-zts-20060613/
running: find "/tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2" | xargs ls -dils
1974089   4 drwxr-xr-x 3 root root   4096 2011-07-27 11:17 /tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2
1974111   4 drwxr-xr-x 3 root root   4096 2011-07-27 11:17 /tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2/usr
1974112   4 drwxr-xr-x 3 root root   4096 2011-07-27 11:17 /tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2/usr/lib
1974113   4 drwxr-xr-x 3 root root   4096 2011-07-27 11:17 /tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2/usr/lib/extensions
1974114   4 drwxr-xr-x 2 root root   4096 2011-07-27 11:17 /tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2/usr/lib/extensions/no-debug-zts-20060613
1974110 180 -rwxr-xr-x 1 root root 184221 2011-07-27 11:17 /tmp/pear/temp/pear-build-rootmdfn1M/install-memcached-1.0.2/usr/lib/extensions/no-debug-zts-20060613/memcached.so

Build process completed successfully
Installing '/usr/lib/extensions/no-debug-zts-20060613/memcached.so'
install ok: channel://pecl.php.net/memcached-1.0.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcached.so" to php.ini

Thats it..

Howto: Enable IMAP extension on php

Posted on Updated on

#yum install libc-client-devel
#cd /home/installation/php-5.2.12/ext/imap
#phpize
# ./configure --with-imap  --with-kerberos  --with-imap-ssl
[root@rc-90 imap]# make
 [root@rc-90 imap]# make install
 [root@rc-90 imap]# vi /etc/php.ini Add the extension entry in it
 extension=imap.so
 [root@rc-90 imap]# service httpd restart
 Stopping httpd:                                            [  OK  ]
 Starting httpd:                                             [  OK

Howto:Enable xmlrpc on php

Posted on Updated on

Resolved as follows:

1. Into the php source directory in the ext directory

[root@rc-090 ~]# cd /home/installation/php-5.2.14/ext/xmlrpc/
[root@rc-090 xmlrpc]# /usr/bin/phpize
[root@rc-090 xmlrpc]# ./configure –with-xmlrpc –with-php-config=/usr/bin/php-config
[root@rc-090 xmlrpc]# make && make install

Build complete.
Don’t forget to run ‘make test’.

Installing shared extensions:     /usr/lib/extensions/no-debug-non-zts-20060613/

This is the massage when installation completed sucessfully.

Then we have to add below entry to php.ini file

extension=”xmlrpc.so”

Now you check the module enable or not thorugh this.

[root@rc-090 ]# php -m |grep “xmlrpc” will returns
xmlrpc

I f you need to view the XMLRPC entry on phpinfo do this step also

[root@rc-090 ~]# service httpd restart
Stopping httpd:                                             [  OK  ]
Starting httpd:                                               [  OK  ]

That’s it