I have a question that might point to a misunderstanding I have with Homebrew in relation to MongoDB:
I am running XAMPP (version) with PHP 7.2.1 (which I want to use) on Mac OSX 10.12.6 (Sierra). I installed MongoDB and created configuration and data storage folder. It runs fine on command line (when using mongod and mongodb by terminal).
Now, I want to install the PHP driver for PHP 7.2.1. I followed the instructions on http://php.net/manual/en/mongodb.installation.homebrew.php
and adapted them to version 7.2, therefore:
$ brew tap homebrew/homebrew-php
$ brew install php72-mongodb
this creates a php72 and a php72-mongodb folder in /usr/local/Cellar. However, my original (XAMPP based) PHP is in /Applications/XAMPP/ and the php there is in /Applications/XAMPP/etc/php.ini.
and simply adding:
extension="/usr/local/opt/php72-mongodb/mongodb.so"
won't do the trick. After adding this extension, Apache won't start any more. /Applications/XAMPP/logs/php_error.log shows the following error:
[27-Feb-2018 13:11:59 UTC] PHP Warning:
PHP Startup: Unable to load dynamic library 'mongodb.so'
(tried: /Applications/XAMPP/xamppfiles/lib/php/extensions
/no-debug-non-zts-20170718/mongodb.so
(dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/
no-debug-non-zts-20170718/mongodb.so, 9): image not found),
/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-
20170718/mongodb.so.so
(dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-
non-zts-20170718/mongodb.so.so, 9): image not found)) in Unknown on
line 0
What is the correct way to include/connect the driver I just installed with my existing XAMPP installation? Do I need to tell Homebrew somehow where my XAMPP install is?
Given that I also have a php folder in my Homebrew (and my /usr/local/opt folder) indicates that I have a second PHP installation right now. Is this the way it is supposed to be?
The PHP version coming with MAMP is incomplete, you need to get the full version here.
Then, replace your local include folder, with the include folder of that downloaded version.
Go to your terminal and run ./configure, this will install full copy of your MAMP php.
Now that you have prepared the PHP directory, install the mongodb extension:
cd /Applications/MAMP/bin/php/php(your version ex: 7.2)/bin
and then run pecl to install mongodb extension
./pecl install mongodb
Now you have installed mongodb but your php should know this.
Go to php.ini file and search for ;Extension
Under this add extension=mongodb.so
Then restart your server and you are good to go, I hope this helps!
Related
I have installed the lastest mongodb php driver on linux centos 6 with plesk onyx using the following commands.
yum install plesk-php56-devel make gcc openssl-devel
/opt/plesk/php/5.6/bin/pecl install mongodb
echo "mongodb.so" > /opt/plesk/php/5.6/etc/php.d/mongodb.ini
plesk bin php_handler --reread
I have also added extension=mongodb.so to the php.ini file.
I also changed the cli version from php 5.3 to 5.6 before running the install as php needed to be at least 5.4 for the install to continue.
The mongodb section in now in my phpinfo() page. However the extension is not loaded when I test it in a php page.
When I try to reinstall I get this message:
PHP Warning: PHP Startup: Unable to load dynamic library
'/opt/plesk/php/5.6/lib64/php/modules/mongo.so' -
/opt/plesk/php/5.6/lib64/php/modules/mongo.so: cannot open shared
object file: No such file or directory in Unknown on line 0
pecl/mongodb is already installed and is the same as the released
version 1.2.9 install failed
Also, the line that says /opt/plesk/php/5.6/lib64/php/modules/mongo.so
refers to mongo.so when in actual fact the file present in the modules folder is mongodb.so
Does anyone have any suggestions or experience with this please?
For those facing the same issue. This was fixed by changing the extension name in the following file /opt/plesk/php/5.6/etc/php.d/mongodb.ini from mongo.so to mongodb.so
And then remember to use the new mongo driver class ie MongoDB\Driver\
I followed the instructions outlined here:
Install PHP Internationalization extension (Intl) on XAMPP on Mac
Ran sudo pecl install intl
selected the correct files from the Cellar
then this error happened:
/private/tmp/pear/temp/intl/intl_error.h:24:10: fatal error:
'ext/standard/php_smart_str.h' file not found
include
^ 1 error generated. make: *** [php_intl.lo] Error 1 ERROR: `make' failed
No matter, did some research and found out that PHP 7.0.8 deprecated php.smart_str.h to php.smart_string.h
So given my scant knowledge of C++ I copied smart_string.h to smart_str.h and renamed all the headers from STRING to string.....
re-ran pecl -no luck....more errors......without knowing where the .c files are and remaking php (not really interested in going that far) since anyway I'm using XAMPP so that ended that option.
I have php 5.5 on my mac, deep in the usr/local/bin folder
so next step was to get pecl to use those files and generate an intl.so file....
Did that....I have the intl.so file so put it in the 'extensions' folder in XAMPP (for reference: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012)
Ran php and came up with this error:
Warning: PHP Startup: Unable to load dynamic library
'/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so'
- dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so,
9): Symbol not found: _zval_used_for_init Referenced from:
/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so
Expected in: flat namespace in
/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so
in Unknown on line 0
I imagine it has to do with different versions?
In any case I can't get pecl to install intl without a make error in PHP 7.0.8 on XAMPP. There is no documentation on this and you'd think that if you deprecate a header.h file you'd update all extensions?
Install intl.so in PHP 7 seems impossible?
After a lot of research I was finally able to resolve this. Detailed steps here:
before you begin, check which php path is set. it should be /Applications/XAMPP/xamppfiles/bin/php. If not you can change it by PATH="/Applications/XAMPP/xamppfiles/bin:${PATH}". more detail here
Overall idea is to build the intl-extension from PHP source code on your own. Before you begin make sure you have installed Xcode. Also, install the latest version of autoconf. this might help:
brew install autoconf
Next download the version of PHP you use in XAMPP from php.net. I am using 7.1.18. This version worked for me: php-7.1.31, I’m guessing if you follow the steps it might work for 7.0 or 7.2 as well. Do let me know if it does or doesnt, I’ll update this post. Do not use PHP 7.3 for Magento 2.3.0, it is not supported.
Extract the tar.gz file using (I extracted it inside ~/Downloads/ folder )
tar -xzvf php-7.1.31.tar.gz
cd into the extracted folder
cd php-7.1.31
change to subfolder ext/intl
cd ext/intl/
Run these commands to build the extension
/Applications/XAMPP/bin/phpize
./configure --enable-intl --with-php-config=/Applications/XAMPP/bin/php-config --with-icu-dir=/Applications/XAMPP/xamppfiles/
make
sudo make install
you can now delete all files you downloaded and also the extracted folders.
Open /Applications/XAMPP/xamppfiles/etc/php.ini , and add extension=intl.so
Restart your Apache using XAMPP GUI and it should work.
So far, it seems that extension intl.so for php is bundled with php
and should be compiled with php (intl --enabled). XAMPP does not support this (as of Oct 2016), MAMP does. I do not know about other distros. However, if you're willing to recompile PHP 7, it's worth it just to do that and enable it during compiling.
So....I ran with MAMP. Then I decided that I would simply install apache 2.4 and php 7 and Mysql without the stack and the junk that comes with MAMP or XAMPP and everything works like a charm... so if you need to use CakePHP or intl support etc... just drop XAMPP/MAMP and go with a standard install. I used homebrew (MacOS) and everything is working fine.
Update: As regards Windows, XAMPP does not default it, but you can add the module (dll) in php.ini and works like a charm
The error means that XAMPP doesn't have PHP compiled with intl. You may try:
pecl install intl
but probably it won't work as well.
See: PHP Bug #72879 Pecl install intl make error with PHP 7.0.8.
As for the workaround, try installing memcached extension instead of memcache, e.g.
pecl install memcached
Note: It also requires libmemcached package/library to be installed beforehand. For macOS, install via: brew install libmemcached.
If you wanna try without homebrew, with native apache and php, look at my aswer here: https://stackoverflow.com/a/55131868/3692846
I am running OSX El Capitan. I have installed the mongo driver using brew:
brew install php70-mongodb
The installation finished and it seems to work. When I do "php -m" on CLI it shows "mongo" installed. Running a script with Mongo driver works.
The problem occurs when I am trying to run the same script through via Apache2. Then, I get an error that Mongo is not installed, due to the following line of code:
if (!extension_loaded('mongo')) die("MongoDB is not installed!");
phpinfo() indeed shows Mongo not being installed.
I have created a php.ini file for apache using:
cp php.ini.default php.ini
and added the following line to the end of the file:
extension="/usr/local/opt/php56-mongo/mongo.so"
After restarting Apache, it still doesn't seem to load. I tried creating a copy of mongo.so in the same directory and give _www ownership (thought that may be the case), but still didn't work.
Strangely, the system tells me I have mail, which was sent from my Macbook to my Macbook, saying the following:
PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20131226
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
Any help on how to get the extension to load on Apache would be appreciated!......
Looks like I am running PHP version 5.5 and I did, per php.net's instructions
brew install php56-mongo
Apparently, I've missed that you must change this line based on the version installed. Therefore, after changing it to :
brew install php55-mongo
and following the brew instructions on how to remove the other versions installed (explanation on how to do that appears after you type in this command) - the new version has been installed.
Afterwards, I updated the /etc/php.ini to point to the right directory (which is different than the previous installation) - and it works!
I'm trying to run a Symfony 3 app with php 7 installed from source and I'm getting a Missing PDO driver exception. According to http://pecl.php.net/package/PDO_MYSQL the PDO_MYSQL extension is now part of PHP core.
Q1.a) If I have the PDO_MYSQL extension (which I must, since its core) does that mean that I also have the mysql pdo driver?
Q2.b) Is there further runtime configuration I have to do to make sure that the driver gets used?
I've tried adding
extension=php_pdo.so
extension=php_pdo_mysql.so
to my loaded php.ini file.
Q2.a) Are these the correct extension names? How could I find out?
Q2.b)Do I even have to provide extension references for core php elements?
Finally:
Q3. How can I check whether my PHP install included the mysql pdo driver and how do I make sure that it is being loaded at runtime?
Thanks for your input.
Edit 1: I'm running on Linux Mint.
Edit 2: Here are a couple more details on what I'm seeing on my end:
"On starting up the built in php server I get the following message:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20151012/php_pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0"
This message suggests to me that either the extension references are incorrect or the extension does not exist. I used "dpkg -L php-mysql" and found that the package was installed in "/usr/share/doc/php-mysql" however, when I check in the php-mysql directory, all I see is a changelog and a copyright file (with hiddens shown). Is this the true install location of the package and, if so, should there be more in this directory?
.so implies you are on Linux - did you install PHP as a package. You probably need to install the pdo/mysql package - PHP libraries may be "core", but not necessarily in the main package (confusing, but it just means it's not PEAR delivered, really).
sudo apt-get install php5-mysql
Or, if you're running PHP7:
sudo apt-get install php-mysql
This should restart the apache automatically, but to be sure you could do:
sudo service apache2 restart
The package installer for php-mysql should have put the .so libraries in /usr/lib/php/yyyymmdd/ - if you had installed PHP as a package, it would be looking here.
However, since you installed from source, it seems that PHP is looking elsewhere for the libraries. You can create symlinks from /usr/local/lib/php/extensions/no-debug-non-zts-20151012/ to the package installed libraries.
I followed the following steps to install mongo's php drivers with lampp.
http://abstract2paradox.wordpress.com/2012/01/26/adding-mongo-db-driver-to-xampp/
When I start lampp its gives the following error
Warning: PHP Startup: Unable to load dynamic library '/opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/mongo.so' - /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/mongo.so: wrong ELF class: ELFCLASS64 in Unknown on line 0
Any ideas?
Thanking you
This means that your PHP is compiled in 32-bit mode, but the mongo extension as 64-bit mode. I believe Apple's compiled PHP is in 32-bit mode as well, you can verify that with:
php -r 'echo PHP_INT_MAX, "\n";'
If that shows 9223372036854775807 you're on a 64-bit platform.
Now, in your case you will need to make sure that you compile the MongoDB extension with a 32-bit architecture. From http://artur.ejsmont.org/blog/content/how-to-build-mongodb-pecl-extension-in-32bit-for-php-52-on-macosx-snow-leaopard I believe you can do that with:
pecl download mongo
tar -xvzf mongo-1.2.7.tgz
cd mongo-1.2.7
CFLAGS="-m32"
phpize
./configure
make
make install
The problem was as is outlined by Derick above. Although the way the problem got solved was download a 32 bit version of the ubuntu os and running it as a virtual machine on my pc using vmware. Later followed the 'Manual Installation section' on this page for the php driver installation and it all worked. Got the php drivers from github as mentioned in the page.
Later i copied the file mongo.so from the php file extensions directory running on my virtual machine to my parent os and it all works now!