Enabling PostgreSQL support in PHP on Mac OS X

前端 未结 10 1321
执念已碎
执念已碎 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:57

    The PHP version that comes bundled with OS X doesn't include PostgreSQL. You'll have to compile the extension yourself. Here are some instructions:

    1. Find your version of PHP: php -v.
    2. Download the version of PHP that matches yours: curl -O http://us.php.net/distributions/php-5.3.3.tar.gz. (This example downloads PHP 5.3.3 but this must match your version)
    3. Extract the archive you downloaded: tar -xzvf php-5.3.3.tar.gz
    4. Change to the PostgreSQL's extension directory: cd php-5.3.3/ext/pgsql/
    5. Type phpize.
    6. Type ./configure.
    7. Type make.
    8. Type sudo make install.
    9. Add the extension to you php.ini file by adding extension=pgsql.so. (You may already have done this)
    10. Restart Apache.

    Update for OS X Mountain Lion Apple has removed autoconf from the newer versions of XCode so the procedure above will fail at #5. To solve that problem:

    1. Type /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)".
    2. Type sudo chown -R $USER /usr/local/Cellar.
    3. Type brew update.
    4. Type brew install autoconf.

    That should install autoconf and allow you to install the module using the instructions above.

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

    For those who installed php7/ngix/postgres with homebrew

    You can install the PostgreSQL module with:

    brew install php70-pdo-pgsql
    

    After that, you have to restart the php service:

    brew services restart php70
    
    0 讨论(0)
  • 2020-11-28 20:59

    For php56 via brew:

    brew install php56-pdo-pgsql
    
    0 讨论(0)
  • 2020-11-28 21:02

    For those of you having openssl error while make here is the solution

    OSX uses openssl 0.98 while installer is searching for 1.0.0

    refer this link for instructions

    psycopg2 installation error - Library not loaded: libssl.dylib

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