Enabling PostgreSQL support in PHP on Mac OS X

前端 未结 10 1320
执念已碎
执念已碎 2020-11-28 20:28

I\'m having a terribly difficult time getting the command \"pg_connect()\" to work properly on my Mac. I\'m currently writing a PHP script (to be executed from console) to r

相关标签:
10条回答
  • 2020-11-28 20:39

    If you use home brew, you can solve this with a command as simple as:

    brew install php55-pdo-pgsql

    for other php version, search with:

    brew search pgsql

    0 讨论(0)
  • 2020-11-28 20:46

    OS X El Capitan users can simply upgrade their version of PHP 5.6. This is a one liner that will do that.

    curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6

    0 讨论(0)
  • 2020-11-28 20:48

    PostgreSQL by default is installed in a unusual place on MAC OS X:

    /Library/PostgreSQL/9.3
    

    Given the location above you can type this:

    ./configure --with-pgsql=/Library/PostgreSQL/9.3
    
    0 讨论(0)
  • 2020-11-28 20:49

    I downloaded PostgreSQL for Mac, and used the stack builder after installation to standup the entire EnterpriseDB Apache/PHP stack end-to-end. I mention this as a possible time saving option, probably not ideal for all situations. Should work OK if the apache and postgres shipped with Mac OS X were never started.

    To keep existing apache hosted applications (i.e. pre-PostgreSQL install legacy) stable, I would just install the newer EnterpriseDB apache on port 81 (stackbuilder will prompt for new port if legacy apache instance is already running). Then, use mod_proxy in httpd.conf for the apache running on port 80 to provide seamless user experience to applications hosted on PostgreSQL.

    0 讨论(0)
  • 2020-11-28 20:52

    I killed the whole day trying to make it work on El Capitan after I made an upgrade yesterday and it turned out that I forgot to modify httpd.conf and change the path from the default php module (version 5.5.27) to the one I installed (version 5.6.14). This should be done in httpd.conf by modifying your default LoadModule php5_module path to LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so. Just decided to leave it here as the potential solution for those who upgrade their OS or just the PHP version and face the same problem.

    0 讨论(0)
  • 2020-11-28 20:55

    This worked for me with OSX 10.9.4 «Mavericks»

    Install sources

    Download the PHP source code. Unlike on Mountain Lion, you don’t get any headers preinstalled to link against so need to put it in /usr/include/php. Mavericks ships with PHP 5.4.17, but the latest 5.4.x source from php.net should do:

    tar -jxvf php-5.4.20.tar.bz2
    sudo mkdir -p /usr/include
    sudo mv php-5.4.20 /usr/include/php
    

    Configure PHP

    cd /usr/include/php
    ./configure --without-iconv
    sudo cp /etc/php.ini.default /etc/php.ini
    

    Building a module

    I needed the pdo_pgsql module - the same pattern should apply to just about any module assuming you have the necessary dependencies installed:

    cd ext/pdo_pgsql
    

    In my case I had the following error:

    Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. ERROR: `phpize' failed

    So I had to use this command:

    brew install autoconf
    

    Then:

    phpize
    

    After that I tried to do: ./configure

    but I had the next problem:

    checking for pg_config... not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

    So the solution was to specify correct PostgreSQL installation path:

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

    That copies pdo_pgsql.so to /usr/lib/php/extensions/no-debug-non-zts-20100525.

    Then simply add

    extension=pdo_pgsql.so to /etc/php.ini 
    

    Run php -m to confirm everything went to plan.

    0 讨论(0)
提交回复
热议问题