Tag Archives: pl-php

Install and Configure PL-PHP for Postgres 9.1

30 Oct

Prerequisite Packages

Note: Some or all of these packages might already be installed on your system. The Yum install command will notify you if that’s the case.

  • PHP Devel
  • Postgres Devel
  • Libxml
  • Libtool
  • Automake and Autoconf
  • GLIBC Devel
  1. yum install php-devel postgresql91-devel libtool libxml2-devel automake autoconf glibc-devel

Download PHP Source Code

 

  • If you have an existing PL-PHP version based on an older PHP version (for example, PHP 5.3.3) and want
    to upgrade to a later version (for example, 5.3.8) you will have to repeat the steps below. There is
    no automatic way to upgrade to a later version.

 

    • mkdir -p /opt/phpsrc
    • cd /opt/phpsrc
    • It’s possible you already have the latest PHP source code downloaded and extracted. If so, skip this step
    • Get the latest version of PHP from http://php.net/downloads.php#v5
    • tar -xvzf php-5.3.8.tar.gz

Build PHP using the “enable-embed” option

  • To build and install a shared PHP embed library, unpack the PHP tarball
  • cd /opt/phpsrc/php-5.3.8
  • make clean ( If this is first time you are building PHP this command will fail and that is ok )
    • this ensures the build is cleaned from previous runs if any.
  • ./configure –enable-embed
  • make
    • This command will build the libphp5.so file. Might take a few minutes to complete.
  • make install
  • The previous command will install the libphp5.so in /usr/local/lib. We need to copy this to the /usr/lib
    • cp /usr/local/lib/libphp5.so /usr/lib
  • Update Shared Library Configuration:
    • cd /etc/ld.so.conf.d
    • vi plphp-libs.conf (Create this file)
    • Enter /usr/lib/libphp5.so and save file
    • ldconfig
      • this will update the CentOS library path configuration.

Download Latest Version of Autoconf

  • Check latest version of autoconf
    • /usr/local/bin/autoconf –version
  • IF version shows as 2.68 then you can skip the steps to download and install below and continue on
    to Download and building PL-PHP
  • mkdir /opt/autoconf
  • cd /opt/autoconf
  • wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
  • tar xvfz autoconf-latest.tar.gz
  • cd autoconf-<LATEST_VERSION>
  • ./configure
  • make clean
  • make
  • make install
    • LATEST autoconf will be installed in /usr/local/bin

Download PL-PHP

{info:title=Make Note}

  • If you have an existing PL-PHP installation and want to upgrade to a later version you will have to repeat the steps below. There is no automatic way to upgrade to a later version.

{info}

Download and extract the PL-PHP source code at http://github.com/commandprompt/PL-php

Compile, Install PL-PHP and restart Postgres

  • Comple and Install PL-PHP
    • cd /opt/plphp/commandprompt-PL-php-8c2f8ef
    • /usr/local/bin/autoconf (generates the configure script)
    • Set Path so to the embedded PHP that was built earlier
      • PATH=/usr/local/bin:$PATH ; export PATH
    • ./configure –with-postgres=/usr/pgsql-9.1/
    • make clean ( If this is first time you are building PL-PHP this command will fail and that is ok )
    • make
    • make install
  • Restart Postgres
    • service postgresql-9.1 restart

Setup/Configure PL-PHP language support in Postgres

  • cd /opt/plphp/commandprompt-PL-php-8c2f8ef
  • export LD_LIBRARY_PATH=/usr/pgsql-9.1/lib:$LD_LIBRARY_PATH
    • this step is required because we have both Postgres 9.0 and 9.1 on the same machine
  • psql -d template1 -U postgres < install.sql
    • This will enter pl-php as a valid language in the pg_template tables
  • In the SQL window, run the following command which will create PL/PHP as a ‘trusted’ language in pgsql (https://public.commandprompt.com/projects/plphp/wiki/CreateLang):
    • CREATE LANGUAGE PLPHP
  • Copy/Paste the following command. The commented out section can be used to validate our php environment.
CREATE FUNCTION test_plphp() RETURNS text AS $$

  ob_start();
  phpinfo();
  $variable = ob_get_contents();
  ob_get_clean();
  return $variable;

$$ LANGUAGE 'plphp';
  • Validate PHP environment:
    • select test_plphp(); as a Postgres SQL command to view the phpinfo() output.

Configuring extension libraries setting for use in PL-PHP

  • IF YOU ARE UPGRADING FROM POSTGRES 9.0 to 9.x then you may skip the steps in this section.

Setup php.ini

  • PL/PHP looks for php.ini in /usr/local/lib by default.
  • If you have a copy in /etc/php.ini, copy it over to /usr/local/lib
    • cp /etc/php.ini /usr/local/lib
  • Otherwise, copy/paste the php.ini file from another location

Set the extension directory in php.ini

  • cd /usr/local/lib
  • gedit php.ini and edit the following entries
    • For 32 bit OS enter: extension_dir=/usr/lib/php/modules
    • For 64 bit OS enter: extension_dir=/usr/lib64/php/modules/

Restart Postgres

  • service postgresql-9.1 restart

PL-PHP USAGE

Advertisements