PHP 5.6.2 + Postgres + Apache 2.4 doesn't 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 was trying 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 extension

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

      

and add

extension=pdo_pgsql.so

sudo apachectl restart

      

2. Compilation by hand

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. Install phpbrew

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 to execute 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 am doing wrong. Can anyone help me?

UPDATE:

As per phpinfo

I have php.ini in/etc/php.ini

Executing this command with php help

php -c /etc/php.ini

      

And I have 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

      

Decision

I uninstalled everything and reinstalled everything, according to this post

+3


source to share


3 answers


You have two copies of PHP installed. Mac OS X ships with a copy of PHP installed in /usr/bin/php

. When you use a package manager homebrew

, it installs the packages into /usr/local/Cellar

and then symbolizes them (if necessary) into /usr/local/bin

. You can check 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 installed an homebrew

installed copy of PHP to use postgres

. If you run /usr/local/bin/php -r 'phpinfo()'

, you will see that it is installed postgres

.

The copy apache

you are running is configured to use the Mac OS X installed PHP copy instead of the installed copy homebrew

. You need to reconfigure Apache to use the correct PHP module.

Try editing the file /etc/apache2/httpd.conf

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

. Change the browser back to the file phpinfo()

and you should set it up correctly postgres

.

+2


source


Follow these steps.

1) run yum install php-pdo_pgsql

2) add these lines to php.ini



extension=pdo_pgsql.so
extension=pgsql.so

      

3) restart apache

Done

0


source


I fixed this problem using:

brew install php56 --with-mysql --with-homebrew-apache

Then add httpd.conf

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


source







All Articles