Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.6.2 + Postgres + Apache 2.4 does not work on Yosemite

I decided to upgrade my mac to Yosemite, but now Postgres is not working.

This is my environment

apachectl -v

Server version: Apache/2.4.9 (Unix)
Server built:   Sep  9 2014 14:48:20

php -v

PHP 5.6.2 (cli) (built: Oct 24 2014 15:50:08) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

PostgreSQL 9.3

What I tried to do:

1. Install with brew

brew tap josegonzalez/php
brew install php56 --with-apache --with-mysql  --with-intl --with-pgsql=/Library/PostgreSQL/9.3/
brew link --overwrite php56

enable the extension

sudo nano /usr/local/etc/php/5.6/php.ini

and add

extension=pdo_pgsql.so

sudo apachectl restart

2. Manual compilation

sudo pecl download pdo_pgsql
sudo tar xzf PDO_PGSQL-1.0.2.tgz
sudo cd PDO_PGSQL-1.0.2
sudo phpize

sudo ./configure --with-pgsql=/Library/PostgreSQL/9.3/
sudo make
sudo make -j5 test
sudo make -j5 install

3. phpbrew Installation

sudo phpbrew install --mirror http://br1.php.net  5.6.2 +pdo+pgsql=/Library/PostgreSQL/9.3/bin/

It definitely doesn't work when I try with this file:

<?php

  ini_set ("display_errors", "1");
  error_reporting(E_ALL);  
  $host        = "host=127.0.0.1";
  $port        = "port=5432";
  $dbname      = "dbname=peajetron";
  $credentials = "user=peajetron password=peajetron";

  $db = pg_connect( "$host $port $dbname $credentials"  ) or die('Could not connect');;
  if(!$db){
      echo "Error : Unable to open database\n";
  } else {
      echo "Opened database successfully\n";
  }
?>

When I try this code I get the same error:

Fatal error: Call to undefined function pg_connect() in /Library/WebServer/Documents/testConnection.php on line 10

I don't know what I'm doing wrong. Can anyone help me?

UPDATE:

Acording with the phpinfo I've the php.ini in /etc/php.ini

Acording with php help I run this command

php -c /etc/php.ini

And I've the following error:

PHP Warning:  PHP Startup: Unable to load dynamic library 
'/usr/local/Cellar/php56/5.6.2/lib/php/extensions/no-debug-non-zts-20131226/php_pdo_pgsql.so' 
- dlopen(/usr/local/Cellar/php56/5.6.2/lib/php/extensions/no-debug-non-zts-20131226 
 /php_pdo_pgsql.so, 9): image not found in Unknown on line 0
 PHP Warning:  PHP Startup: Unable to load dynamic library 
'/usr/local/Cellar/php56/5.6.2/lib/php/extensions/no-debug-non-zts-20131226/php_pgsql.so' 
- dlopen(/usr/local/Cellar/php56/5.6.2/lib/php/extensions/no-debug-non-zts-20131226/php_pgsql.so,
 9): image not found in Unknown on line 0

Solution

I uninstalled All and reinstalled all , according with this post

like image 885
Cristian Avatar asked Nov 27 '25 04:11

Cristian


1 Answers

You have two copies of PHP installed. Mac OS X comes with a copy of PHP installed at /usr/bin/php. When you use the homebrew package manager, it installs packages in /usr/local/Cellar and then symlinks them (when appropriate) into /usr/local/bin. You can verify this by typing /usr/bin/php -v and /usr/local/bin/php -v and you should get two different outputs.

When you installed postgres with homebrew, it configured the homebrew installed copy of PHP to use postgres. If you run /usr/local/bin/php -r 'phpinfo()', you should see that postgres is installed.

The copy of apache that you have running is configured to use the copy of PHP that is installed by Mac OS X, instead of the copy that homebrew installed. You need to reconfigure Apache to use the correct PHP module.

Try editing the /etc/apache2/httpd.conf file with your favorite text editor. Find the line that says:

LoadModule php5_module libexec/apache2/libphp5.so

Change it to:

LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so

Save the file, then run sudo apachectl configtest and sudo apachectl restart. Point your browser back to the phpinfo() file and you should see postgres configured correctly.

like image 155
Ben Harold Avatar answered Nov 28 '25 17:11

Ben Harold