简体   繁体   中英

PHP, mongo.so failed to write

Any help would be great. I've been stuck on this for hours. I'm trying to install Mongo to work with PHP on a Mac. I have Pear/pecl installed and working. When I call sudo pecl install mongo , everything looks like it's compiling/building successfully, but at the end I get this message.

Build process completed successfully Installing '/usr/lib/php/extensions/no-debug-non-zts-20121212/mongo.so' ERROR: failed to write /usr/lib/php/extensions/no-debug-non-zts-20121212/mongo.so (copy(/usr/lib/php/extensions/no-debug-non-zts-20121212/mongo.so): failed to open stream: Operation not permitted)

And the mongo.so never gets written. Can someone help? I'm using MAMP on Mac OSX El Capitan.

I've solved this problem by changing extension_dir in php.ini .

Create a local extension dir and copy your existing extensions into

mkdir -p /usr/local/lib/php/extensions
cp /usr/lib/php/extensions/no-debug-non-zts-20121212/* /usr/local/lib/php/extensions/

Update your php.ini , change the extension_dir and enable mongo:

extension_dir = "/usr/local/lib/php/extensions/"
extension=mongo.so

Now the extension dir is writeable you can copy the mongo.so there.


Here's how to compile a mongo.so

wget http://pecl.php.net/get/mongo
tar xzvf mongo
cd mongo-1.6.12
phpize
./configure --with-php-config=/usr/bin/php-config --with-mongo-sasl=no
make

You can find the compiled library in .libs folder: .libs/mongo.so Copy it to extensions dir

cp .libs/mongo.so /usr/local/bin/php/extensions/

Finally, you can check whether it's working or not, by typing php -m | grep mongo php -m | grep mongo in the command line.

Robert has solved this problem in this answer. stackoverflow.com/a/31884146 .

Basically the issue is the El Capitan's Rootless feature. Its needs to be disabled in recovery mode, perform the pecl install and that enable it back again .

For some reason , pecl did not install it into my php extensions directly so, I had to copy the mongo extension pecl generated from the local library to my php extension folder xampp files for it to work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM