Wednesday, December 11, 2013

PHP Mcrypt on CentOS 6 64bit

PHP Mcrypt on CentOS 6
CentOS 6 still doesn’t by default include php mcrypt in it’s distribution on repositories. EPEL repo is the answer for this

Step 1: Install EPEL Repository
#rpm -ivh http://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
after installing epel rpm, we need to update the yum
#yum clean all
#yum list all

Step 2: Install php-mcrypt
#yum install php-mcrypt

Step 3: Add mcrypt entry to php.ini file
#vim /etc/php.ini
 add "extension=mcrypt.so"

Step 4: Restart Apache(httpd) Service
we need to restart apache service to make the changes reflect in php.
#service httpd restart

Step 5: Test it
if you need to check the details about installed mcrypt packages, run
#repoquery -i php-mcrypt
which will give you Name, verison, archi, size, repos, summary, etc.

Step by Step procedure for Sphinx installation and Configuration to fetch data from Oracle DB using ODBC on CentOS 6.4 Linux.

Step by Step procedure for Sphinx installation and Configuration to fetch data from Oracle DB using ODBC on CentOS 6.4 Linux.

Step1: Installing unixODBC
 Download unixODBC from http://www.unixodbc.org/unixODBC-2.3.1.tar.gz
 Extract the tar.gz file inside /opt folder &  Install UnixODBC using
# cd /opt/unixODBC-2.3.1
#./configure --enable-gui=no
# make
# make install

Step2: Installing Sphinx with unixODBC
 Download sphinx from http://sphinxsearch.com/downloads/sphinx-2.0.8-release.tar.gz
 Extract files to /opt folder
#cd /opt/sphinx-2.0.8-release
#./configure –prefix=/usr/local/sphinx –with-unixodbc

 Note :Here, you may replace ”/usr/local/sphinx" with the directory in which you want to install sphinx,"–with-unixodbc" parameter looks up for unixodbc installed on your system (which is done in step 1) and configures Sphinx to use unixODBC
# make
# make install
Sphinx is now installed.

Step 3: Installing Oracle Instant Client
Download the following files from Oracle - http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
Download the following files:
oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-devel-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-jdbc-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-odbc-12.1.0.1.0-1.x86_64
oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.x86_64

Install all the rpms by command line using “#rpm -ivh oracle-*”
Update your DB using command “#updatedb”

Step 4: Creating ORA files
The Oracle Instant Client contains Oracle ODBC Driver “libsqora.so.12.1”. We have to use this driver file in creating an ODBC DSN and connecting to the Oracle Database.
Locate the file using the command - #locate libsqora.so.12.1
This file must be located in /usr/lib/oracle/12.1/client64/lib folder.
Now create 3 files in /usr/lib/oracle/12.1/client64/bin folder as under:

#touch /usr/lib/oracle/12.1/client64/bin/tnsnames.ora
#touch /usr/lib/oracle/12.1/client64/bin/listener.ora
#touch /usr/lib/oracle/12.1/client64/bin/sqlnet.ora

 -> Edit listener.ora and enter the following in it. Replace HOST, SERVICE_NAME and SID Parameters with your values.

LISTENER =
 (DESCRIPTION_LIST =
    (DESCRIPTION =
       (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))
       )
       (SERVICE_NAME = YourServiceName)
       (SID = YourSID)
    )
 )

 -> Edit sqlnet.ora and enter the following in it.

SQLNET.AUTHENTICATION_SERVICES= (NONE)

 -> Edit tnsnames.ora and enter the following in it. Replace HOST, SERVICE_NAME and SID Parameters with your values.

MYDATABASE =
 (DESCRIPTION =
    (ADDRESS_LIST =
       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))
    )
 (CONNECT_DATA =
      (SERVICE_NAME=YourServiceName)
(SID=YourSID)
 ) )

Step 5: Setup ODBC Variables
Create a file named odbcinst.ini in /usr/local/etc using command “#touch /usr/local/etc/odbcinst.ini”
Edit odbcinst.ini and insert the following parameters in it and save:

[Oracle]
 Description= ODBC for Oracle
 Driver = /usr/lib/oracle/12.1/client64/lib/libsqora.so.12.1
 Setup =
 FileUsage = 1
 CPTimeout =
 CPReuse =

Create a file named odbc.ini in /usr/local/etc using command “#touch /usr/local/etc/odbc.ini”
Edit odbci.ini and insert the following parameters in it. Make sure you replace [mydsn], DSN = mydsn and ServerName = MYDATABASE with your values.

[mydsn]
 Application Attributes = T
 Attributes = W
 BatchAutocommitMode =
 IfAllSuccessful BindAsFLOAT = F
 CloseCursor = F
 DisableDPM = F
 DisableMTS = T
 Driver = Oracle
 DSN = mydsn
 EXECSchemaOpt =
 EXECSyntax = T
 Failover = T
 FailoverDelay = 10
 FailoverRetryCount = 10
 FetchBufferSize = 64000
 ForceWCHAR = F
 Lobs = T
 Longs = T
 MetadataIdDefault = F
 QueryTimeout = T
 ResultSets = T
 ServerName = MYDATABASE
 SQLGetData extensions = F
 Translation DLL =
 Translation Option = 0
 DisableRULEHint = T
 UserID =

Step 6: Setup Environment Variables
Edit #vim ~/.bash_profile and insert the following at the end:
LD_LIBRARY_PATH=“$LD_LIBRARY_PATH:/usr/lib/oracle/12.1/client64/lib:/usr/local/lib” export LD_LIBRARY_PATH
ODBCINI=”/usr/local/etc/odbc.ini” export ODBCINI
ODBCINST=”/usr/local/etc/odbcinst.ini” export ODBCINST
ORACLE_PATH=”/usr/lib/oracle/12.1/client64/bin” export ORACLE_PATH
TNS_ADMIN=”/usr/lib/oracle/12.1/client64/bin” export TNS_ADMIN
ORACLE_HOME=”/usr/lib/oracle/12.1/client64/bin” export ORACLE_HOME

Update the environment variables by executing command: “source ~/.bash_profile”

Step 7: 
Create a file oracle.conf in path.. /etc/ld.so.conf.d using the following command:
#touch /etc/ld.so.conf.d/oracle.conf
insert the following text in it and save.
/usr/lib/oracle/12.1/client64/lib
run  “#ldconfig” to update cache

Step 8: Test your environment

Test out isql utility : “isql -v mydsn user password” . This should connect you to the Oracle database using ODBC and give a prompt for issuing SQL Commands.
Test out sqlplus utility : “sqlplus user/pass@database”. This should connect you to the database and arrive at SQL Prompt.

Step 9:
Once the test environment is OK, edit sphinx.conf file, you should be able to derive data with the following parameters :

type = odbc
sql_host = 192.168.0.1
sql_user = user
sql_pass = password
sql_db = databasename
sql_port = 1521
odbc_dsn    = DSN=mydsn; Driver={'Oracle'};Dbq=192.168.3.121:1521/mydatabase;Uid=user;Pwd=password

Now your able to index from Oracle DB. :)

Friday, December 6, 2013

How to Access MS SQL Server from a unixODBC(FreeTDS) on CentOS 6.x ?

How to Access MS SQL Server from a unixODBC(FreeTDS) on CentOS 6.x ?

We assume that we have a recent version of unixODBC installed on your system and that we have MS SQL Server running somewhere & SQL Server should allow remote access and support connections using TCP/IP.

The communication protocol used by client software to communicate with MS SQL Server is called Tabular Data Stream (TDS). we are using FreeTDS


Download the latest version of FreeTDS from internet, 

Step 1: Un-compressing the tar file
# tar -zxvf freetds-0.63.tar.gz
# cd freetds-0.63

Step 2: Building FreeTDS
Now we need to configure with TDS version and path to unixodbc directory.
# ./configure --with-tdsver=8.0 --with-unixodbc=/usr/local
# make
# make install

Step 3: Register ODBC driver
Create a new file odbcinst.ini under /usr/local/etc/ directory.

[FreeTDS]    
Description = v0.63 with protocol v8.0    
Driver = /usr/local/freetds/lib/libtdsodbc.so   
Setup=/usr/lib64/libtdsS.so
FileUsage=1

Note : if your having 32 bit OS(i386 or i586) you should add "Setup=/usr/lib/libtdsS.so"

Now install the FreeTDS driver by
# odbcinst -i -d -f /usr/local/etc/odbcinst.ini

Step 4: Creating ODBC data source
Create a new file odbc.ini under /usr/local/etc/ directory.
[SQLServer]
Driver  = FreeTDS
Description = This is the Live Database
Trace   = No
Server  = 30.220.24.189
Port   = 1433
Database  = MainZoneCentral

Note: if we need log for the freetds, we can change Trace = Yes and redirect the logs to needed folder.

Note; we have executed previous commands as root (denoted by leading '#' character on given commands) but here we execute the command as a regular user. This is significant.
All users of the system should be accessable to the FreeTDS and the ODBC Drivers. So create the DSN as the user who is going to be using it.

$ odbcinst -i -s -f odbc.ini

Step 5: Check the connection
# tsql -S 30.220.24.189 -U sa -P pwd@123
where
-S Server IP
-U Username
-P Password

Sample Output
[java@ssserver ~]$ tsql -S 30.220.24.189 -U sa -P pwd@123
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>

which means your able to connect Successfully

Step 6: Enabling in PHP
edit the php.ini file in etc folder   
   
#vim /etc/php.ini and add

extension = odbc.so

Save and close the file

Restart the Apache(httpd) Service to reflect the changes
#service httpd restart

Now your sphinx index is able to connect the MS SQL Server and fetch the records as indexes :)

EXTRA SECTION
Additional Info
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
tsql -S DSN -U Username -P ‘Password’ #To check the connection