I've looked around several other questions like this one, guide like this or this but I still had no luck.
Here's what i've done so far:
Downloaded gmp with brew using brew install autoconf gmp
Downloaded PHP (i'm using version 7.3.24) from source
Copied Gmp directory to /Applications/MAMP/bin/php/php7.3.24/include/php/ext
Entered that dir and launched phpize
Launched ./configure --with-php-config=/Applications/MAMP/bin/php/php7.3.24/bin/php-config
Launched make
Launched make install
So far, so good. No errors, all seems fine but if i look at this point to my cli php -m (or php -i) there's no gmp extension loaded. So i went to my cli php.ini file and my web php.ini file and manually added extension=gmp.so (the file exist in this path /Applications/MAMP/bin/php/php7.3.24/include/php/ext/gmp/modules/gmp.so).
I even tried to specify the full path, but still no luck. Neither my cli or my phpinfo(); shows GMP enabled. I'm kinda confused atm and can't think about anything else.
What am I missing? Obviously, I restarted MAMP PRO like a dozen times, even my mac itself.
MacOs version: 11.4 Big Sur on iMac 24' M1
MAMP PRO Version: 6.3.1
PHP Version used: 7.3.24
Update 08/07/21
I updated MAMP PRO and it installed PHP version 7.3.27 so i went all over it again, download php from source https://github.com/php/php-src/releases?after=php-8.0.4RC1, copied ext/gmp into
/Applications/MAMP/bin/php/php7.3.27/include/php/ext, launched /Applications/MAMP/bin/php/php7.3.27/bin/phpize, ./configure --with-php-config=/Applications/MAMP/bin/php/php7.3.27/bin/php-config, make and make install. No errors.
Output of make install is:
Installing shared extensions: /Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/
Installing header files: /Applications/MAMP/bin/php/php7.3.27/include/php/
shtool:install:Warning: source and destination are the same - skipped
I added extension=gmp.so to php.ini via MAMP interface, file, edit template -> php -> php7.3.27. Restarted MAMP and nothing new on phpinfo();
Update 12/07/21
As per Hakre request i've run the following command into cli and this is the result:
[~]$ php -n -d extension=gmp.so -i
PHP Warning: PHP Startup: Unable to load dynamic library 'gmp.so' (tried: /Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so (dlopen(/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so, 9): no suitable image found. Did find:
/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so: mach-o, but wrong architecture
/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so: mach-o, but wrong architecture), /Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so.so (dlopen(/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so.so, 9): image not found)) in Unknown on line 0
phpinfo()
PHP Version => 7.3.27
which is quite interesting if you look at this img
The extension actually exists
For Raptor:
This is the output of the commands you've asked.
[~]$ which php
/Applications/MAMP/bin/php/php7.3.27/bin/php
[~]$ php --ini | grep "Loaded Configuration File"
Loaded Configuration File: /Applications/MAMP/bin/php/php7.3.27/conf/php.ini
[~]$ php --version
PHP 7.3.27 (cli) (built: Mar 16 2021 12:04:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.27, Copyright (c) 1998-2018 Zend Technologies
[~]$
Ofc there are multiple php's installed since MAMP alone fill it with like 4-5 version + there's the default one from MacOSx which i've overwrote with .zshrc bash profile
export PATH=/Applications/MAMP/bin/php/php7.3.27/bin:$PATH
That line is from my .zshrc
Could the issue be related to the new M1 chip? I'm using a new iMac bought just at the end of June2021.
Maybe is this related?
For Haridarshan:
Let me start saying that i tried to use .configure with no additional params, then i tried with CC="gcc -arch i386" CXX="g++ -arch i386" and even with CC="gcc -arch arm64" CXX="g++ -arch arm64" (i found arm64 in configure.log). None of them produced a valid .so, if i didn't miss any other info from the command line.
About the test u've asked me to make, this is the result:
[~]$ file /Applications/MAMP/bin/php/php7.3.27/bin/php
/Applications/MAMP/bin/php/php7.3.27/bin/php: Mach-O 64-bit executable x86_64
There can be many reasons why a PHP extension is not loaded, but it is not always easy to directly point to reasons (and fixes) as the distance between compiling from sources to showing phpinfo() and then finally missing the extension is large.
Get the real error message first
One way to reduce the distance in trouble-shooting is to see if the extension can be loaded by PHP and if not, showing an error message.
A common test for that is to use the CLI SAPI (PHP on the commandlineDocs) as it allows to reduce and easier control the PHP runtime environment while being compatible with the extension.
To start PHP with the default configuration (no .ini files), loading only the single extension binary to test and showing the configuration information, run:
$ php -n -d extension=gmp.so -i
Excerpt from OptionsDocs, also there is php --help:
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-i PHP information
This should provoke an error (shown in the terminal on standard error) or show the extension loaded in the PHP information output (on standard output).
Alternatively, to reduce the output and only check for the error, execute an empty PHP statement with the -r command-line switch:
-r <code> Run PHP <code> without using script tags <?..?>
The example with the GMP extension in question:
$ php -n -d extension=gmp.so -r ';'
This will exit non-zero (exit status) if there is a problem loading the extension displaying and error message on standard error and would exit with zero status in case the extension could be loaded:
$ php -n -d extension=gmp.so -r ';'
PHP Warning: PHP Startup: Unable to load dynamic library 'gmp.so' (tried: /Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so (dlopen(/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so, 9): no suitable image found. Did find:
/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so: mach-o, but wrong architecture
/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so: mach-o, but wrong architecture), /Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so.so (dlopen(/Applications/MAMP/bin/php/php7.3.27/lib/php/extensions/no-debug-non-zts-20180731/gmp.so.so, 9): image not found)) in Unknown on line 0
$ echo $?
254
As the example shows, the error is already in "PHP Startup" which is the typical phase where PHP signals diagnosis messages loading extensions.
Dlopen 9: no suitable image found: mach-o, but wrong architecture
The error message above shows that a) PHP is first of all unable to load the extension (as a dynamic library, .so file, a shared object file, that is the compiled extension) and b) that it failed to load as no suitable image was found:
PHP Warning: PHP Startup: Unable to load dynamic library 'gmp.so' (tried: <path> (dlopen(<path>, 9): no suitable image found. Did find: <path>: mach-o, but wrong architecture ...), <path>
(dlopen(<path>.so, 9): image not found)) in Unknown on line 0
That means the file is available on disk (can be opened) but the image is not suitable, which means it does not match the architecture.
(there is some noise in the try for gmp.so.so that is done by php so one can pass -d extension=gmp without the extension to work directly, e.g. in a php-.ini to work on both *nix (.so) or windows (.dll). This part can be ignored, that is "image not found" as the file does not exists which is expected)
It must be the same architecture as PHP itself as PHP is already running and wants to load the binary extension - they need to fit.
To get the architecture of PHP, locate the PHP command:
$ which php
/Applications/MAMP/bin/php/php7.3.27/bin/php
This is the absolute path to the php binary. With it, it is now possible with the file(1) utility to obtain more information about it:
$ file /Applications/MAMP/bin/php/php7.3.27/bin/php
/Applications/MAMP/bin/php/php7.3.27/bin/php: Mach-O 64-bit executable x86_64
(or call $ file "$(which php)" for running both at once)
It shows the php binaries info incl. the x86_64 architecture at the end:
Mach-O 64-bit executable x86_64
As the shared object image to load (the compiled php extension gmp.so file) also needs to match it, the same file(1) utility can be used on the compiled extensions .so file in the same manner.
The comparison then should show the difference.
With this information at hand finally the extension can be compiled with the appropriate architecture.
Closing notes:
On Apple Silicon M1 I'm not specifically profound of compiling and its architectures and others can tell it better. From what I've seen you manged it by running brew with the arch(1) utility setting the architecture by arch -x86_64 <command> to x86_64. On Apple Silicon this may require more tooling, namely Rosetta.
It seems to be something common M1 users blog about (via Austen Cameron in Nov 2020) but this is entirely not my system.
From my own understanding it should be possible to set the architecture with compiler flags or on the configure line and thats normally it.
As brew has the information how to compile an extension on a system (the brew formula, here for gmp) it is perhaps most straight forward to go with it and run the install under the correct architecture.
With the caveat that you need to start brew in (?) the correct architecture with the arch(1) utility as well (and the brew install).
I'm running the default version of PHP that is packaged with Mojave. PHP 7.1.19. I've installed the PECL mongodb driver 1.5.3. To get the PECL mongodb driver install I had to disable csrutil in recover mode. When csrutil is disabled the driver works. When I re-enable csrutil the driver can no longer be loaded.
I receive this error.
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so, 0x0009): code signature in (/usr/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so) not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed. in Unknown on line 0
From the looks of it, it seems like it's because of an unsigned package. I have no idea what I can do to resolve this issue. Does anyone have any thoughts?
I ended up just tossing out the default mac os version of PHP and used Homebrews PHP 7.2 version. This solved my issues. By using Homebrews version you don't need to turn off csrutil.
Good reference for help with the install.
https://getgrav.org/blog/macos-mojave-apache-multiple-php-versions
I'm trying to install Laravel4 on my 10.6 Mac / PHP 5.4.14. And I seem to be going down a rabbit hole.
After "composer install"ing Laravel4 .. command line showed that I needed the Mcrypt PHP extension. So I tried to install that and I was told I had to have Mhash installed. So I installed Mhash .. then went back and installed Mcrypt
extension = mcrypt.so
Libraries have been installed in:
/Users/****/downloads/php-5.4.14/ext/mcrypt/modules
Then I went back to installing Laravel 4 and now I'm showing this
PHP Warning: PHP Startup: Unable to load dynamic library '/opt/local/lib/php/extensions/no-debug-non-zts-20100525/intl.so' - dlopen(/opt/local/lib/php/extensions/no-debug-non-zts-20100525/intl.so, 9): image not found in Unknown on line 0
Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating autoload files
PHP Warning: PHP Startup: Unable to load dynamic library '/opt/local/lib/php/extensions/no-debug-non-zts-20100525/intl.so' - dlopen(/opt/local/lib/php/extensions/no-debug-non-zts-20100525/intl.so, 9): image not found in Unknown on line 0
Laravel requires the Mcrypt PHP extension.
.. and I thought I had already taken care of that intl.so issue .. but it seems I installed an old version?
Module compiled with module API=20090626
PHP compiled with module API=20100525
These options need to match
in Unknown on line 0
Laravel requires the Mcrypt PHP extension.
So can someone maybe give me a bit of perspective on this and point me in the right direction? I'm a little fuzzy with compiling PHP.
Your command line might be using a different version of PHP. You'll have to update your path variable in your .bash_profile file to point to the correct version of PHP.
How are you installing PHP?
I'm thinking the 5.4 version you installed is getting mixed up with the built-in 5.3 version that comes with OS X.
I am trying to load a PHP extension (sdo.so) but I am getting the following error when I try to run XAMPP.
PHP Warning: PHP Startup: Unable to load dynamic library '/opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/sdo.so' - /opt/lampp/lib/php/extensions/no-debug-non-zts-20060613/sdo.so: wrong ELF class: ELFCLASS64 in Unknown on line 0
From what I've seen other people say it seems to be something to do with it being compiled on a 64bit machine and it needs 32bit. Is this the root of the problem? If so how would I compile it as 32bit in Fedora 17 as I've only seen solutions for Ubuntu and couldn't get them to work for me.
From what I've seen other people say it seems to be something to do with it being compiled on a 64bit machine
It doesn't matter on which machine you compile (the build host). What matters is for what machine you compile (the target host).
You are (apparently) running a 32-bit ix86 PHP, so you need to compile sdo.so for 32-bit ix86 as well.
how would I compile it as 32bit in Fedora 17
./configure CC='gcc -m32' CXX='g++ -m32' && make && make install
should be about it.
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!