Project

General

Profile

Actions

Creating the PL/php language in a PostgreSQL database

Installing the pg_pltemplate entries

The first thing you need is to have a PL/php entry in the pg_pltemplate system catalog.
This is done by executing the install.sql file when connected as a superuser to any database. On 8.2, you need to execute the install82.sql file instead.

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

Running CREATE LANGUAGE

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.

Common problems

If you receive an error similar to:

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

it means the Postmaster can't find the PHP shared library. You should probably define a LD_LIBRARY_PATH variable in the postmaster environment that points to the location where libphp.so is located (or add that path to /etc/ld.so.conf)

Updated by Álvaro Herrera over 14 years ago · 11 revisions