Saturday, August 14, 2010

Install MySQL for Python (MySQLdb) on Windows XP

There is no binary distribution of MySQLdb for Python 2.6 on Windows. I have to build it from the source. My environment is Windows XP. MySQL 5.1. Python 2.6 (windows version, not cygwin), and MySQL-python-1.2.3c1. Also, I have Microsoft Visual C++ 2008 Express Edition (Microsoft Visual Studio 9.0) installed, which is required to compile the C code in MySQL-python.
First of all, install Python setuptools, if you haven’t installed it. It is required in MySQL-python setup.py. I also added C:\Python26\Scripts into environment PATH, where easy_install is installed.
Then, make sure you have MySQL Developer Components installed. Download MySQL msi installer version, select “Developer Components” in Custom Setup. It will install C:\Program Files\MySQL\MySQL Server 5.1\include, lib\debug and lib\opt for you. They are not installed by default.
Uncompress MySQL-python-1.2.3c1.tar.gz into a directory. Open a command window (cmd), change to the directory.
Try to run,
setup.py build
I got this error in setup_windows.py:
in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key'])
WindowsError: [Error 2] The system cannot find the file specified
So I edited site.cfg, changed the MySQL version from 5.0 to 5.1 (since I am using 5.1)
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1
You can use regedit to check which version you are using. It is specified at: HKEY_LOCAL_MACHINE/SOFTWARE/MySQL AB/MySQL Server 5.1.
Now try to build it again. I got this error:
build\temp.win32-2.6\Release\_mysql.pyd.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
error: command ‘mt.exe’ failed with exit status 31
To fix this problem, go to C:\Python26\Lib\distutils, edit msvc9compiler.py, search for ‘MANIFESTFILE’, you will find the following line
ld_args.append(‘/MANIFESTFILE:’ + temp_manifest)
Then append the following line after the above line,
ld_args.append(‘/MANIFEST’)
Then go back to run “setup.py build”, it will succeed. Finally, run
setup.py install
Test it in python
>>> import MySQLdb
>>>

Wednesday, August 4, 2010

Why use LDAP?

Why LDAP?

The question is a good one and I think as LDAP proliferates across more systems, many people will have the same question - and it deserves a good answer, so here is my two-cents-worth.
What we are really talking about is directory services, not just the protocol. Directories have some serious advantages over DBMS. Databases are optimized for OLTP (online transaction processing), but not for performing quick searches of information that is frequently used, but not updated constantly. In other words, Directories can deliver data very quickly (read) compared to a DB, but handles updates (write) slower in comparison to databases.

Features and Benefits using LDAP

§ Cross-platform functionality and industry standards-based (important consideration for future growth and deployments)

§ Widely accepted standard for the Internet

§ Inexpensive since licensing is usually not based on number of connections or clients open source directories are widely available. Also, replication and synchronization features are usually built-in rather than requiring a separate license as is the case for many databases.

§ Replication and synchronization is easy compared to complex DBMS implementation with highly specific SQL script requirements.

§ ACI’s for delegated administration so you can setup accounts that are highly specific in what administration functions a group has {e.g. an account may only allow for phone numbers to be updated, another for new objects (name, email, phone number) to be inserted, but not deleted or existing objects modified}

§ High Performance, since directory data is store hieratical you have very high availability over DBMS, sometimes up to 10 times higher.

Sample Use Cases.

The following is a short list of common uses of directory services since these uses are data profiles that are fairly static and do not have deep relationships – they are stored as relatively “flat” trees.

§ Phone / Address book

§ Infrastructure Resource List (ip addresses, etc)

§ Public Certificates

§ User credentials, groups, roles (for authentication/ authorization)

Directories are also more secure and can keep credentials “locked” and unable to read or copy from an outside source, and you can do in a database. Directories are based on a hierarchal storage schema, a “tree” structure. Information that would be able bi-directionally in a database are not available in this manner in a directory. Items that are lower in the hierarchy could be read, but data higher in the hierarchy are not available to the client. So you could read a person’s contact information, but not necessarily be able to see what accounts he has, or other people in a group that she is a part of. In a database, records are stored relationally, so if you can read a person in a group, you can read the group and theoretically see the records of everyone in the group if you have direct access to the tables, not true in a directory

Wednesday, July 21, 2010

Installation of Db2 Client On linux & Compilation of Db2 with PHP


To connect database DB2 through PHP & Compilation of PHP with DB2
Step 1 :
1> Download the client ADCL (Application Development Client 8.1.2.156)
Install runtime client also


Download Location:
http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg21256051

Installation of ADCL(Following command will be used for installation purpose)
1 Go to the folder where the ADCL has been downloaded, untar it
Shell > tar -xf FP18_MI00291_ADCL_DB2.tar

Go to the folder & run the following command
Shell > ./db2_install –p DB2.ADCL

It will install the ADCL.
Step 2 > Instance Creation on the application server .generally thi
Then Ask your DBA to set instance on your Application server
Task is performed y the DBA . if DBA is not available then progarammer can also perform the same task . Documentation for the programmer is provided in the attachement.

After finishing the creation of the instance on the application server
Or You can follow the text file to set up the db2 instance


Once finish creating the instance & , u can check enviroment has been created like the following the attachement .I m attaching my environment please find it
Ste










Step-3>

We have created the text file in tmp directory its named bbb
Whenever we want to set up the enviroment we just run the following command
shell>. /tmp/bbb

Note :--
In any case problem occurs for installing the DB2 Client & compiling it with the PHP

So start the from step 1 to step 3 . before starting the step1 & step3 uninstall the db2 client . start everything freshly .

So I started from the beginning ,(I already had apache & PHP installation so I unstalled it Apache then recompile the php with apache with following command )

Uninstallation is very easy if you used previous installation from the source or Apache instead or rpm

So I just rename the folder of apache here for uninstallation which is in the /usr/local/apache2 so I renamed it /usr/local/apache2pre

Following is process of installation of Apache & PHP & compilation of PHP with DB2 Client .

Step -1 >
Then I downwloaded the apache (httpd2.2.11) & untar it & switch to that folder

& run the following command (remember this command is very important what parameter u r passing in that )






./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql \
--with-IBM_DB2=/opt/IBM/db2/V8.1 \
--enable-force-cgi-redirect \
--disable-cgi \
--with-xml=/usr/local \
--with-libxml-dir=/usr/local \
--with-xsl=/usr/local


Shell>Make
Shell>Make install

We have installed the Apache

Step – 2 > For Checking the apache installed properly or not
. Now that the binaries have been installed on your system you need to start the apache server.
/usr/local/apache2/bin/apachectl start
For future reference you can restart apache 2 by using the following command:
/usr/local/apache2/bin/apachectl restart
Or stop apache 2 using the following command:
/usr/local/apache2/bin/apachectl stop


8. You test this is running by using the following command on UNIX (must be on the same machine as apache):
telnet localhost 80

You should receive something like the following:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
echo


501 Method Not Implemented

Method Not Implemented


echo to /index.html.en not supported.




Apache/2.0.51 (Unix) mod_ssl/2.0.51 OpenSSL/0.9.7c Server at server7.crucialdns.com Port 80


Connection closed by foreign host.

************************optional start************************************
Have apache 2 start up automatically:
For FreeBSD add the following line to /etc/rc.local
/usr/local/apache2/bin/apachectl start
On Red Hat or Fedora 1 or 2:
Copy the apache startup script (apachectl) from the apache directory to the startup directory.
cp /usr/local/apache2/bin/apachectl /etc/init.d/
Add the following 2 lines to /etc/init.d/apachectl (after the #!/bin/sh)
# chkconfig: - 85 15
# description: Apache is a Web server used to serve HTML files and CGI.
Enable apache/httpd to startup automatically:
/sbin/chkconfig --add apachectl
************************ Optional End **********************************
After Finishing this
Step - 3> Installing PHP 5.2.9 with Apache2
1. Change directory into the PHP source directory (php-5.2.9).

As Our basic purpose is to configure extension IBM_DB2 with so
Download the ibm_db2 from
http://pecl.php.net/package/ibm_db2/download/1.0
ibm_db2-1.2.1 I tried 1.2.0 u can try more stable version is 1.8.2
& copy it in the source directory there is one ext folder copy it there
U have make folder IBM_DB2 or ibm_db2
Just like this php-5.2.9/ext/IBM_DB2
php-5.2.9/ext/ibm_db2
2. Configure PHP using the ./configure command, options are as follows:
--with-mysql \
--prefix=/usr/local/apache2/php \
./buildconf --force \
./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-IBM_DB2=/opt/IBM/db2/V8.1 \
--with-config-file-path=/usr/local/apache2/php \
--with-pear=/usr/local/apache2/php/lib/php \
--enable-force-cgi-redirect \
--disable-cgi \
--with-xml \
--with-libxml-dir=/usr/local \
--with-xsl=/usr/local
Above I needed so I used above command, following are optional to make connection by other way eg unixodbc or pdo(php data objects)
--with-pdo-odbc=ibm-db2,/opt/IBM/db2/V8.1 \
--with-unixODBC \
--prefix=/usr/local/apache2/php \
Shell>Make
shell>Make install

Step 4 > Configuration of file php.ini
add followinf line in php .ini file ()
in following two line either you can a> or b> line
For My configuration I added b> line
a>extension=ibm_db2.so
b>ibm_db2.instance_name=db2inst1

Step 5>module Copying if does not exist .
5. If /usr/local/apache2/modules/libphp5.so does not exist then run the following command:
cp -p .libs/libphp4.so /usr/local/apache2/modules
Step 6>Copying the php.ini configuration file if does not exist .
6. Copy the default configuration file to the PHP config directory:
cp -p php.ini-recommended /usr/local/apache2/php/php.ini
7. Open the apache2 logfile and make sure that the following lines exist:
LoadModule php4_module modules/libphp4.so
DirectoryIndex index.html index.php
AddType application/x-httpd-php php
AddType application/x-httpd-php-source phps
^ This one adds colouring to PHP syntax, not required
If these do not exist in your apache config files (/usr/local/apache2/conf/httpd.conf) then add then so as to allow PHP to function correctly.
8. Restart apache:
/usr/local/apache2/bin/apachectl restart
9. Check that PHP and apache are running, create the following directory in your html directory:
info.php







Check that ibm_db2 extension is enabled or not








Then try running the following script
$database = 'fdmdb1t';
$user = 'fdmusr1t';
$password = '*******';
//$port = 50000;
$conn = db2_connect($database, $user, $password);
if($conn){
echo "Connection succeeded.";
db2_close($conn);
}else{
echo "Connection failed.";}

That’s all ..thanks
Regards
Pradip
Pradip.bhoge@gmail.com

Friday, April 23, 2010

Apache Virtual Host

The term Virtual Host refers to the practice of maintaining more than one server on one machine, as differentiated by their apparent hostname. For example, it is often desirable for companies sharing a web server to have their own domains, with web servers accessible as www.company1.com and www.company2.com, without requiring the user to know any extra path information.

Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both, IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.

Here is the example of how to add an virtual hosts entry in your httpd.conf (/etc/httpd/conf)


DocumentRoot /var/www/html/wwwsitefolder
#ServerName 192.168.0.99
ServerName www.domain.com
RewriteEngine On
RewriteRule ^/image/(.*)$Â /image.php?do=readfile&filepath=$1
SetEnvIfNoCase Request_URI \ \.(?:gif|jpg|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
Header unset Pragma
FileETag None

Header set Cache-Control "max-age=2592000, must-revalidate"

CustomLog /var/log/httpd/test_access_log combined
ErrorLog /var/log/httpd/test_error.log

CronJob

Here is the crontab code:
# start apache on reboot
@reboot mount -t ext3 /dev/sdf /opt/
@reboot /etc/init.d/httpd start
# start mysqld on reboot
@reboot /etc/init.d/mysqld start
*/10 * * * * /usr/bin/php /opt/www/cron/test.php
10 * * * * /usr/bin/php /opt/www/cron/test1.php
25 14 * * * /opt/www/cron/rotatelogs.sh
*/02 * * * * sh /opt/www/cron/imagedata_upload.sh >> /opt/www/cron/imagedataoutput.log

To set crontab for a particular user like webdoc, use command :
crontab -e -u webdoc

Shell Script to back Up database & Script Folders

#!/bin/bash
cd /backuppath/
NOW=$(date +”%m-%d-%Y”)
tar -cjf backupsite_$NOW.bz2 /pathtoscriptfolder
tar -cjf backupcms_$NOW.bz2 /opt/www/cms
tar -cjf mysqlbackup_$NOW.bz2 /opt/lib/mysql