Ubuntu – Problems using PostgreSQL with XAMPP

PHPpostgresqlserverxampp

I seem to have trouble getting PostgreSQL to work on XAMPP (using Lubuntu 14.02). I am new to working with both PHP, servers and databases, but I get the following error message.

Fatal error: Call to undefined function pg_escape_string() in /opt/lampp/htdocs/imageability/SkjemaDatabase.php on line 551

So it seems to me to be a problem with PostgreSQL. The same error message shows up for pg_connect(). I have tried a few things to get PostgreSQL to work with XAMPP, like uncommenting the following lines in my file php.ini and then restarting the server, without success.

extension=php_pdo_pgsql.dll

extension=php_pgsql.dll

I have also read you can try to copy the file libpq.dll to Apache folder, but I don't seem to have this file at all (searched with find). Can this be the problem?

I have also tried downloading Apache2, PHP5 and PostgreSQL seperately, but this doesn't seem to help me, as I in this case just get a blank page, without an error message even. The PHP files I am using are fine and working for other people and I can also get other PHP files to work on the server.

Grateful for any help!

Best Answer

My recommendation: Don't use XAMPP for this! It's supposed to be a simple way to get the usual Apache, MySQL, PHP, +Python/Perl stack to work. Leave the walled garden and your pretty much on your own…

Also: Even if you do get it to work there is no guarantee that it won't break the next time your system or XAMPP itself. This use-case is not supported by anybody and some of the components involved (especially PHP) aren't designed to handle modules not compiled for their specific version.

How to set up a developer environment natively on Debian/Ubuntu

  1. Open a Terminal window (MenuOtherLXTerminal)
  2. Stop all XAMPP services currently running
  3. Install the required packages:
    You may either use a GUI ("Software Center") for this or run this command on your Terminal:
    sudo apt-get install apache2 libapache2-mod-php5 postgresql php5-pgsql
    • apache2 (The Apache web server)
    • libapache2-mod-php5 (PHP support for Apache)
    • php5-pgsql (PostgreSQL client support for PHP)
    • postgresql (The PostgreSQL server)
  4. Open the file /etc/php5/apache2/php.ini in a text editor as root:
    In the Terminal window type the command
    gksudo leafpad /etc/php5/apache2/php.ini and press enter
  5. Locate the line display_errors = Off and change it to display_errors = On
    Screenshot of the display_errors line and documentation
  6. Save the file and close the editor
  7. Restart the Apache web server:
    Run the command sudo service apache2 restart in your Terminal window to restart the web server and reload its PHP module