Install MongoDB driver for PHP on XAMPP for Mac OSX
You need to have the following installed in your Mac:
- MongoDB
- XAMPP for Mac OSX
- Homebrew Package Manager
Type the following in your terminal :
brew install wget
brew install autoconf
sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo
Add extension=mongo.so to your php.ini file which can be found at /Applications/XAMPP/xamppfiles/etc by default.
Restart Apache.
Installing AutoConf and Fixing Phpsize on OSX 10.9
When setting up my development environment on my new Mac (running OSX 10.8) I noticed autoconf was missing. Autoconf is used by phpize to compile php extensions like xdebug and is something I use on a reasonably frequent basis.
The error I got when trying to run php on the xdebug extension was:
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
ERROR: `phpize’ failed
When running previous versions of OSX autoconf has either been included (<10.6) or available by installing xcode and the development command line tools. However after installing the latest version of xcode (4.3) I found autoconf absent from there as well!
The solution I came up with was to compile autoconf from source and set the environment variable which points to autoconf required by phpize.
Download autoconf
curl http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz > autoconf.tar.gz
Untar the autoconf archive
tar -xvzf autoconf.tar.gz
Configure and make – note the folder un-archived may have a different name.
cd autoconf-2.69
./configure
sudo make && sudo make install
This installs autoconf to ‘/usr/local/bin/autoconf’. In order to get phpize to work set the PHP_AUTOCONF environment variable to point to the newly installed autoconf.
export PHP_AUTOCONF=/usr/local/bin/autoconf
Running phpize when attempting to compile a php extension should now work.
Installing the PHP/MongoDB extension on Mac OSX 10.8
Installing PHP/MongoDB extension is a two steps task on OSX:
- Install the autoconf tool required for compiling the extension
- Install the Mongo extension
You have to install autoconf in order to avoid the following error:
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
ERROR: `phpize’ failed
ERROR: `phpize’ failed
Enough talk, hands on work…
Step 1. Install the autoconf tool
Download the latest source version:
cd
mkdir autoconf
cd autoconf
curl http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz > autoconf.tar.gz
mkdir autoconf
cd autoconf
curl http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz > autoconf.tar.gz
Untar it
tar -xvzf autoconf.tar.gz
Configure and make
cd autoconf-2.69
./configure
make
sudo make install
export PHP_AUTOCONF=/usr/local/bin/autoconf
./configure
make
sudo make install
export PHP_AUTOCONF=/usr/local/bin/autoconf
autoconf is installed on /usr/local/bin/autoconf by default.
Step 2. Install the Mongo extension
cd
mkdir mongo-php-driver
cd mongo-php-driver
curl https://codeload.github.com/mongodb/mongo-php-driver/zip/master > mongo-php-driver-master.zip
mkdir mongo-php-driver
cd mongo-php-driver
curl https://codeload.github.com/mongodb/mongo-php-driver/zip/master > mongo-php-driver-master.zip
Unzip it
unzip mongo-php-driver-master.zip
cd mongo-php-driver-master
cd mongo-php-driver-master
Configure and build
phpize
./configure
make all
sudo make install
./configure
make all
sudo make install
Check that the extension was successfully created:
ls /usr/lib/php/extensions/no-debug-non-zts-20090626/
You should see the mongo.so extension file in there.
Make sure the previous directory is the same as the PHP extension directory by running:
php -i | grep extension_dir
extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20090626 =>
/usr/lib/php/extensions/no-debug-non-zts-20090626
extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20090626 =>
/usr/lib/php/extensions/no-debug-non-zts-20090626
If it’s not, change the extension_dir in php.ini or move mongo.so. (See below if you don’t have a php.ini file)
To load the extension on PHP startup, add the following line to your php.ini file:
extension=mongo.so
If you don’t have a php.ini file you have to copy it from your php.ini.default file like this:
sudo cp /private/etc/php.ini.default /private/etc/php.ini
sudo nano /private/etc/php.ini
sudo nano /private/etc/php.ini
Add the previous “extension” line to your file, save it and restart apache
sudo apachectl restart
Enjoy
No comments:
Post a Comment