Installing extensions to the bundled PHP in OS X

2019-07-05 05:29发布

问题:

I needed to connect to an SQL Server from PHP on OS X 10.9, so I did:

brew install php55
brew install php55-pdo-dblib

This worked nicely, but I'm wondering: Is it possible to install the dblib extension (or any other PHP extension) into the bundled version of PHP in OS X, without compiling a totally new version of PHP?

Where do you find necessary downloads, and what do you do in general to add extensions to PHP? This is surprisingly unclear after researching the topic.

回答1:

The trick is to use phpize - which OSX ships, build the extension you wish to add as shared, and enable it in your php.ini file

The php manual has information about this here - http://php.net/manual/en/install.pecl.phpize.php

So you'll need to download the source for the extension you want to build and cd into it

run phpize (make sure you use the correct phpize, if you have homebrew with another PHP version installed you'll have two floating around so be safe and use complete paths - system phpize is generally in /usr/bin/phpize) You'll also need the matching php-config file (generally found in /bin wherever your php binaries are)

/path/to/phpize
./configure --with-php-config=/path/to/php-config
make
make install

then you need to look up the name of the module that was compiled and put that into your php.ini file

extension=pdo_dblib.so

and restart your server

NOTE: you may need to install autoconf, xcode for a compiler, or other tools. But if you already have homebrew installed I'm guessing you already have the tools you need.

If this seems too hard - using the --without-homebrew-php should install system php extension versions, but I've never been able to get that to work reliably - see link for more information on this

http://www.farces.com/wikis/naked-server/homebrew/homebrew-php-ext/