Project

General

Profile

CreateLang80 » History » Revision 2

Revision 1 (Álvaro Herrera, 11/16/2005 01:17 PM) → Revision 2/3 (Álvaro Herrera, 11/16/2005 05:07 PM)

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

 In 8.0 you need to create the PL/php language using these commands: 

 {{{ 
 CREATE FUNCTION plphp_call_handler() RETURNS language_handler 
 LANGUAGE C AS '$libdir/plphp', 'plphp_call_handler'; 

 CREATE FUNCTION plphp_validator(oid) RETURNS language_handler 
 LANGUAGE C AS '$libdir/plphp', 'plphp_validator'; 

 CREATE TRUSTED LANGUAGE plphp  
 HANDLER plphp_call_handler; plphp_call_handler 
 VALIDATOR plphp_validator; 

 CREATE LANGUAGE plphpu  
 HANDLER plphp_call_handler; plphp_call_handler 
 VALIDATOR plphp_validator; 
 }}} 
 (note you '''DON'T''' have to edit the $libdir.    Leave it alone.    It will be expanded by PostgreSQL automatically.) 

 This will create entries for the trusted and untrusted versions of PL/php.    Note that you need to repeat these steps in every database you want to use PL/php in.    You may want to create it in the template1 database so that it's automatically created in new databases. 

 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.so": 
 libphp4.so: cannot open shared object file: No such file or directory 
 }}} 

 it means the Postmaster can't find the PHP shared library.    A solution 
 you may use is to define the 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 variable somewhere in your start script (/etc/init.d/postgresql or whatever).    This is too varied across Linux distributions or other operating systems so I'll leave it as an exercise to the reader.