Project

General

Profile

CreateLang » History » Version 5

Álvaro Herrera, 12/13/2005 06:07 AM
Update with info about the new symlink approach

1 1 Álvaro Herrera
= Creating the PL/php language in a PostgreSQL database =
2
3
In 8.1 and beyond you need to have a PL/php entry in the pg_pltemplate system catalog.
4
You can insert one by issuing, as a superuser:
5
{{{
6
INSERT INTO pg_pltemplate VALUES
7 5 Álvaro Herrera
('plphp', 't', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);
8 1 Álvaro Herrera
9
INSERT INTO pg_pltemplate VALUES
10 5 Álvaro Herrera
('plphpu', 'f', 'plphp_call_handler', 'plphp_validator', '$libdir/plphp', NULL);
11 1 Álvaro Herrera
}}}
12 2 Álvaro Herrera
13 5 Álvaro Herrera
Note you '''DON'T''' have to edit the `$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.)
14
15 3 Álvaro Herrera
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.
16 1 Álvaro Herrera
17
In any database where you want to use PL/php you need to issue simply
18
19
{{{
20
CREATE LANGUAGE plphp;
21
}}}
22
23
or
24
{{{
25
CREATE LANGUAGE plphpu;
26
}}}
27
(the latter will create the untrusted version, which by default only superusers can write functions in).
28
29
Now the language is ready to be used.
30
31
If you receive an error similar to:
32
33 2 Álvaro Herrera
{{{
34 5 Álvaro Herrera
ERROR:  could not load library "/usr/local/lib/postgresql/plphp":
35 1 Álvaro Herrera
libphp4.so: cannot open shared object file: No such file or directory
36
}}}
37
38 5 Álvaro Herrera
it means the Postmaster can't find the PHP shared library.  The "make install" step should have created a symlink from the Apache2 PHP module to the `pg_config --libdir` directory.  If the link is broken, please fix it -- exactly where the library is located is left as an exercise to the reader, but the actual link creation should be something like
39 2 Álvaro Herrera
40 1 Álvaro Herrera
{{{
41 5 Álvaro Herrera
ln -sf /path/to/libphp4.so $(pg_config --libdir)
42 1 Álvaro Herrera
}}}