PHP-extensions

Error: While executing gem … (ArgumentError)

Posted on

After installing ruby with rails , I got few error to install gems packages manager seems to be broken. Everytime you try to use gem install gem_name, you get the following error:

ERROR:  While executing gem ... (Gem::GemNotFoundException)

I do the step below to upgrade rubygems, it will fine

gem install rubygems-update
update_rubygems

Now I can install gems whatever I needed.

 

 

info: How to install java on Ubuntu.

Posted on Updated on

JAVAJava is a object-oriented computer programming language developed by James Gosling  at Sun Microsystems and released in 1995 lated it has been migrated to

Oracle systems. The code that can runs on one platform does not need to be recompiled.

Ubuntu

Install oracle java 7 in ubuntu 12.04
Here I have described about one of the easiest installation method of Oracle-JAVA on Ubuntu using JAVA repository. for more information : http://en.wikipedia.org/wiki/Java_(programming_language)

Open the terminal and run the following commands

# java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
OpenJDK Server VM (build 20.0-b12, mixed mode)

# sudo add-apt-repository ppa:webupd8team/java
# sudo apt-get update
# sudo apt-get install oracle-java7-installer

Now check the new updated verison

# java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) Server VM (build 23.21-b01, mixed mode)

 

sdf

Check the installation directory:

anand@desktop:~$ ll /usr/lib/jvm/java-7-oracle/
total 19720
drwxr-xr-x 8 root root 4096 May 3 09:32 .
drwxr-xr-x 6 root root 4096 May 3 09:32 ..
drwxr-xr-x 2 root root 4096 May 3 09:32 bin
-r--r--r-- 1 root root 3339 May 3 09:32 COPYRIGHT
drwxr-xr-x 4 root root 4096 May 3 09:32 db
drwxr-xr-x 3 root root 4096 May 3 09:32 include
drwxr-xr-x 5 root root 4096 May 3 09:32 jre
drwxr-xr-x 3 root root 4096 May 3 09:32 lib
-r--r--r-- 1 root root 40 May 3 09:32 LICENSE
drwxr-xr-x 4 root root 4096 May 3 09:32 man
-r--r--r-- 1 root root 114 May 3 09:32 README.html
-rw-r--r-- 1 root root 443 May 3 09:32 release
-rw-r--r-- 1 root root 19838528 May 3 09:32 src.zip
-rw-r--r-- 1 root root 123324 May 3 09:32 THIRDPARTYLICENSEREADME-JAVAFX.txt
-r--r--r-- 1 root root 172252 May 3 09:32 THIRDPARTYLICENSEREADME.txt

 

That’s all 🙂

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

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..