Project

General

Profile

CreateLang80 » History » Version 3

Álvaro Herrera, 11/16/2005 05:07 PM

1 1 Álvaro Herrera
2 3 Álvaro Herrera
h1. Creating the PL/php language in a [[PostgreSQL]] 8.0 database
3
4
5 1 Álvaro Herrera
In 8.0 you need to create the PL/php language using these commands:
6
7 3 Álvaro Herrera
<pre>
8 1 Álvaro Herrera
CREATE FUNCTION plphp_call_handler() RETURNS language_handler
9
LANGUAGE C AS '$libdir/plphp', 'plphp_call_handler';
10
11
CREATE TRUSTED LANGUAGE plphp 
12
HANDLER plphp_call_handler;
13
14
CREATE LANGUAGE plphpu 
15 2 Álvaro Herrera
HANDLER plphp_call_handler;
16 3 Álvaro Herrera
</pre>
17
(note you *DON'T* have to edit the $libdir.  Leave it alone.  It will be expanded by [[PostgreSQL]] automatically.)
18 1 Álvaro Herrera
19
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.
20
21
Now the language is ready to be used.
22
23
If you receive an error similar to:
24
25 3 Álvaro Herrera
<pre>
26 1 Álvaro Herrera
ERROR:  could not load library "/usr/local/lib/postgresql/plphp.so":
27
libphp4.so: cannot open shared object file: No such file or directory
28 3 Álvaro Herrera
</pre>
29 1 Álvaro Herrera
30
it means the Postmaster can't find the PHP shared library.  A solution
31
you may use is to define the LD_LIBRARY_PATH to postmaster, like so:
32
33 3 Álvaro Herrera
<pre>
34 1 Álvaro Herrera
LD_LIBRARY_PATH=/usr/lib/apache2/modules:$LD_LIBRARY_PATH postmaster
35 3 Álvaro Herrera
</pre>
36 1 Álvaro Herrera
37
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.