William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

CentOS: add a 3rd open-source application into PHP extension

CentOS: add a 3rd open-source into PHP extension

In a Linux CentOS 64-Bit server, I have 2 sets of web environment:(web-server, database-server, tools, commands etc)

  • 1 is default by CentOS itself;
  • 1 is from xampp (apachefriends.org) package.

Sometimes they are conflicts with each other: php commands, mysql commands, httpd, conf files, log, lock files etc.
if missing path, they will point to wrong path, so I have to use:
$ whereis, which, type
to find the right location.

This is not the worst. While I tried to add a 3rd-module as a php extension, the Ambiguous environments prevent it from working. I encountered some problems and when googled, I found the solutions are scattered and incomplete, so here I summarized what I did to make it successfully work from a very basic installed CentOS 6.2 server.

Get CentOS version

Because 3rd application needs Linux version supports, so first we need to find out CentOS server version, using the following commands:

$ cat /etc/redhat-release
$ cat /etc/issue
CentOS release 6.2 (Final)
//or:
$ rpm -q centos-release
centos-release-6-2.el6.centos.7.x86_64

Some potential issues

problems: xampp’s application are 32-bit LSB environments, which CentOS are 64-bits. It doesn’t matter 32-bit xampp can work in 64-bit CentOS. But 64-bit 3rd pacakge can not work in 32-bit xmp PHP environment.

$ file /opt/lampp/bin/php
php: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.2.0, stripped

$ file /usr/bin/php
php: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

So do for other commands. 32-bit and 64-bit shared dynamic objects are not Compatible, so the package runned by /opt/lampp/bin/php *CAN NOT* compatible with /usr/sbin/php environment. By default CentOS doesn’t include development tools; if need, I have to install by myself.

Since the server has very basic installation, I had to install the development tools before the php-extension.

The following development tools are needed to build the development environment:
1) g++/c++ enivronment(include autoconf, automake, m4, gnulib, libtool etc) which 3rd source codes are need to compile and build.
2) php development environment(include phpize, php-config etc) which extends 3rd library into PHP extension.

CentOS has wonderful yum for the package management, while Unbuntu has apt-get. Here we use yum to install system development environment:

 $ yum grouplist
//1. for ./configure, make, automake, autoconf.
$ sudo yum groupinstall 'Development tools'

//2. forphpize, php-chkconfig.
$ sudo yum install php-devel

Follow the prompt to install. That’s it.

General steps for 3rd open sources installation

After setup the environment, it’s time to install 3rd open-source PHP-extension. Suppose the library is called demo, Here I list the common steps to do so:

//1. download sources:
$ wget demo.tar.bz2
$ tar xvjf demo.tar.bz2
$ cd demo

//2. compile and make install
$ ./configure --prefix=...; make; sudo make install

//3. Here we generate .so, .la files. Then add the libaray as php extension:
$ cd php-extension

//4. make sure the path of phpize and php-config are correct, not confusion
$ whereis phpize; which php-config

//5. make sure 'phpize', 'php-config' are in the right path.
$ phpize
$./configure --with-demo=... --with-php-config=`which php-config`
$ make; make test; sudo make install

Configure the PHP extension

After demo module’s (demo.so) installation, the next step is to add it as a PHP extension in php.ini.

;[demo]
;extension = demo.so
;scws.default.charset = utf-8
;scws.default.fpath = /usr/local/demo/etc

Restart the http server to make it activate:
$ sudo /etc/init.d/httpd restart
Now there is a new item added into php core: the <demo> section will display correctly when view by phpinfo().

The key is to distinguish different pacakges in a single server, not to confuse with each other:
Which php, phpize, php-config are you using? You can do some extra work in $HOME/.bash_profile, .bashrc to set PATH, and also make sure what files are in what directory.

Also, the following file are common used for checking:

/etc/httpd/conf/httpd.conf
/etc/php.ini
/etc/my.cnf
Advertisements

2 responses to “CentOS: add a 3rd open-source application into PHP extension

  1. Byron 10/13/2012 at 7:30 pm

    Great blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple adjustements would really make
    my blog shine. Please let me know where you got your design.
    Thanks a lot

    Byron

    • williamjxj 10/14/2012 at 9:04 pm

      For the theme, I just chose from wordpress’s Appearance -> Theme Options.

      If you spend some time on it, you definitely can find a suitable theme which you are satisfied.

      Did you try the popular css framework twitter bootstrap? It is a very good place which is worth to dig into.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: