Project

General

Profile

CreateLang » History » Revision 5

Revision 4 (Álvaro Herrera, 12/05/2005 08:30 AM) → Revision 5/11 (Álvaro Herrera, 12/13/2005 06:07 AM)

= Creating the PL/php language in a PostgreSQL database = 

 In 8.1 and beyond you need to have a PL/php entry in the pg_pltemplate system catalog. 
 You can insert one by issuing, as a superuser: 
 {{{ 
 INSERT INTO pg_pltemplate VALUES 
 ('plphp', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', '$libdir/plphp.so', NULL); 

 INSERT INTO pg_pltemplate VALUES 
 ('plphpu', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', '$libdir/plphp.so', NULL); 
 }}} 

 Note 
 (note you '''DON'T''' have to edit the `$libdir`. $libdir.    Leave it alone.    It will be expanded by PostgreSQL automatically.    You don't need to add the `.so` suffix either (or whatever it's called on your platform.) automatically.) 

 This will create entries for the trusted and untrusted versions of PL/php.    Note that pg_pltemplate is a shared catalog, which means you have to do it only once in any database and it will be available in all your databases automatically. 

 In any database where you want to use PL/php you need to issue simply 

 {{{ 
 CREATE LANGUAGE plphp; 
 }}} 

 or 
 {{{ 
 CREATE LANGUAGE plphpu; 
 }}} 
 (the latter will create the untrusted version, which by default only superusers can write functions in). 

 Now the language is ready to be used. 

 If you receive an error similar to: 

 {{{ 
 ERROR:    could not load library "/usr/local/lib/postgresql/plphp": "/usr/local/lib/postgresql/plphp.so": 
 libphp4.so: cannot open shared object file: No such file or directory 
 }}} 

 it means the Postmaster can't find the PHP shared library.    The "make install" step should have created a symlink from A solution 
 you may use is to define the Apache2 PHP module LD_LIBRARY_PATH to postmaster, like so: 

 {{{ 
 LD_LIBRARY_PATH=/usr/lib/apache2/modules:$LD_LIBRARY_PATH postmaster 
 }}} 

 Of course this isn't ideal.    You may want to define the `pg_config --libdir` directory. variable somewhere in your start script (/etc/init.d/postgresql or whatever).    If the link This is broken, please fix too varied across Linux distributions or other operating systems so I'll leave it -- exactly where the library is located is left as an exercise to the reader, but the actual link creation should be something like 

 {{{ 
 ln -sf /path/to/libphp4.so $(pg_config --libdir) 
 }}} reader.