OpenSSL not found on MacOS Sierra - php

I am trying to install a PHP MongoDB driver but the installation is failing because it cannot locate the OpenSSL.
/Users/username/mongo-php-driver/src/libmongoc/src/mongoc/mongoc-crypto-openssl.c:24:10: fatal error: 'openssl/sha.h' file not found
#include <openssl/sha.h>
^
1 error generated.
make: *** [src/libmongoc/src/mongoc/mongoc-crypto-openssl.lo] Error 1
I read that this has something to do with the latest version of MacOS? Is there a way to do it, as I really need to install this driver.

This is the only solution that worked for me.
cd /usr/local/include
ln -s ../opt/openssl/include/openssl .
Source: https://www.anintegratedworld.com/mac-osx-fatal-error-opensslsha-h-file-not-found/

You’ll need to install OpenSSL using homebrew, and tell homebrew to create symlinks:
brew install openssl
brew link openssl --force
If you don’t already have homebrew installed, you can get it by running this:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
And before all that, if you haven’t already installed XCode and the XCode command-line tools:
xcode-select --install

First install libressl using brew:
brew install libressl
Then run the following:
export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/lib \
-L/usr/local/opt/expat/lib" && export CFLAGS="-I/usr/local/opt/openssl/include/ \
-I/usr/local/include -I/usr/local/opt/expat/include" && export \
CPPFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include \
-I/usr/local/opt/expat/include"

You can use environment variable C_INCLUDE_PATH to tell the compiler to include the path to openssl header files.
For example, if you just want to do it once:
sudo C_INCLUDE_PATH=/usr/local/opt/openssl/include pecl install mongo
Reference: charles.lescampeurs.org

Related

Can't install php Intl extension on MacosX

I'm following this link to install this PHP extension but I'm stuck in the middle.
When I try to run this command pecl install intl I get this message:
Specify where ICU libraries and headers can be found [DEFAULT] :
And I don't know where the ICU libraries are located.
If I press Enter I get this error:
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
ERROR: `/private/tmp/pear/install/intl/configure --with-php-config=/usr/bin/php-config --with-icu-dir=DEFAULT' failed
How can I locate the correct path of ICU libraries ?
I'm using High Sierra and MAMP with PHP version 7.1
ICU stands for ICU - International Components for Unicode
Install it with brew
brew update
brew search icu # returns 'icu4c'
brew install icu4c
OR
Install it with pecl
sudo pecl update-channels
sudo pecl install intl
installing intl package on osx
EDIT: after a better look in php#5.6 it seems that it is already compiled with 'intl'
php -i | grep intl
... '--enable-intl' ...
So my answer is normally useless for php#5.6 (but can be useful in some cases I guess)
I'm facing the same issue today trying to switch from php56 to php#5.6.
After lot of digging, here is the workaround.
Make sure to have a clean install of php#5.6 and to have it at the current version
php -v
PHP 5.6.35 (cli) (built: Mar 31 2018 20:21:31)
Make also sure to have icu4c
brew update
brew install icu4c
Next, we will install and compile intl manually
cd /usr/local/src/
wget https://pecl.php.net/get/intl-3.0.0.tg
tar zxf intl-3.0.0.tgz
cd intl-3.0.0/
phpize --clean
phpize
./configure
And here is the trick, edit Makefile
vi Makefile
Modify the line CXXFLAGS as follow
CXXFLAGS = -g -O2 -std=c++11
AND the line CPPFLAGS as follow
CPPFLAGS = -DHAVE_CONFIG_H -DU_USING_ICU_NAMESPACE=1
Next, save, and compile
make
make install
And voila
Installing shared extensions: /usr/local/Cellar/php#5.6/5.6.35/pecl/20131226/
Don't forget to add extension="intl.so" to your php.ini
vi /usr/local/etc/php/5.6/php.ini
(and to restart apache)
Sources:
https://gist.github.com/redefinelab/4188331
https://github.com/Homebrew/homebrew-php/commit/d7a3e0b6487780e0d983b35b8f42aad0fd01bf78
download the version of PHP you use in XAMPP from php.net. I am using 7.3. This version worked for me: php-7.3,
I’m guessing if you follow the steps it might work for 7.0 or 7.2 as well.
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
That’s it! Restart your Apache using XAMPP GUI and it should work. You have to run these commands each time you install a new version of XAMPP.

Using pecl to install the Mongodb driver on OS X El Capitan (v10.11.1)

I am trying to install the php mongo driver for OS X. I've tried following these instructions to no avail.
$ which pecl -> /usr/local/Cellar/php56/5.6.13_2/bin/pecl
$ sudo pecl install mongo -> full build results here but the problem the is the error:
In file included from /private/tmp/pear/install/mongo/io_stream.c:34:
/private/tmp/pear/install/mongo/contrib/php-ssl.h:33:10: fatal error: 'openssl/evp.h' file not found
#include <openssl/evp.h>
My Xcode command-line tools are up to date (I used $ xcode-select --install to be sure).
I'm sure how to fix this problem.
I managed to get around this by installing OpenSSL using Homebrew (as suggested here):
$ brew install openssl
$ brew link openssl --force
Then
$ sudo pecl install mongodb
Do this
$ cd /usr/local/include
$ ln -s ../opt/openssl/include/openssl
I recommend using http://phpbrew.github.io/phpbrew/ for this type of thing. It let's you easily install any extensions to any php version you require.
When installing a new version of php, I usually keep an eye on the log while it compiles. There might be dependencies that need installing first. Also, make sure you have an updated version of homebrew installed.
You need to disable the Mac OSX El Capitán rootless mechanism:
Boot with Cmd-R
Open Terminal
Type csrutil disable
Reboot
On the Mac, You need to install Xcode, and build the symlink for the openssl comes with Xcode, i.e.
cd /usr/include;
sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdk/MacOSX.sdk/usr/include/openssl

io_stream.lo Error 1 when installing php extension

I'm trying to install mongo php extension on OSX 10.11 but the command:
sudo pecl install mongo
gives the following error:
...
In file included from /private/tmp/pear/install/mongo/io_stream.c:34:
/private/tmp/pear/install/mongo/contrib/php-ssl.h:33:10: fatal error: 'openssl/evp.h' file not found
#include <openssl/evp.h>
^
1 error generated.
make: *** [io_stream.lo] Error 1
ERROR: `make' failed
brew install openssl
ln -s /usr/local/Cellar/openssl/1.0.2d_1/include/openssl /usr/local/include/openssl
You need to disable the Mac OSX El Capitán rootless mechanism:
Boot with Cmd-R
Open Terminal
Type csrutil disable
Reboot
On the Mac, You need to install Xcode, and build the symlink for the openssl comes with Xcode,
i.e.
cd /usr/include;
sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdk/MacOSX.sdk/usr/include/openssl .
i.e. /usr/include/openssl points to Xcode library.
Build your mongo php library.
Once it is done, you should have to enable the rootless security protection:
Boot with Cmd-R
Open Terminal
Type csrutil enable
Reboot
evp is high-level cryptographic functions.
Try to install development libraries:
Ubuntu: sudo apt-get install libssl-dev
CentOS: yum install openssl-devel
Source: Error while installing mongo driver for PHP on amazon linux
I am using OS X and have a custom build of openssl in /usr/local/openssl
so:
ln -s /usr/local/openssl/include/openssl /usr/local/include/openssl
The solution from Scott Wiersdorf seems to worked for me https://solitum.net/openssl-os-x-el-capitan-and-brew/
install opnessl through brew
brew install openssl
Link the openssl
$ cd /usr/local/include
$ ln -s ../opt/openssl/include/openssl

Error compiling mysqlnd_qc with apc

Running the command pecl install mysqlnd_qc to install the caching with APC enabled I receive the following error:
configure: error: APC is onlysupported if both APC and MySQL Query Cache are compiled statically
ERROR: `/var/tmp/mysqlnd_qc/configure --enable-mysqlnd-qc-apc=yes --enable-qc-memcache=no --enable-qc-sqlite=no' failed
Without the APC enabled it compiles fine...
PHP version: 5.3.17
Running on Amazon RDS.
What does it mean to compile APC and MySQL Query Cache statically?
How is it done?
Update 1:
As I haven't managed to compile mysqlnd_qc with APC, I tried compiling it with memcached.
Here was an interesting issue. The ./configure command didn't recognize the the option the pecl gave for memcache. I found out that the option was entered incorrectly...
So I killed the pecl installation when it was asking for the options and ran the following commands myself:
sudo ./configure --enable-mysqlnd-qc-memcache --with-libmemcached-dir=/usr/
sudo make
sudo make install
So with memcached it now works.
If running on Fedora (I guess also RedHat and CentOS) there is available a rpm:
sudo yum install php-pecl-mysqlnd-qc
Update 2:
I managed to compile with APC, see the detailed answer below.
Well found the solution:
Here is what I did:
Get php 5.3.17:
wget https://github.com/php/php-src/archive/PHP-5.3.17.zip
unzip PHP-5.3.17.zip
Get mysqlnd_qc:
wget http://pecl.php.net/get/mysqlnd_qc-1.1.1.tgz
tar -zxvf http://pecl.php.net/get/mysqlnd_qc-1.1.1.tgz
mkdir -p php-src-PHP-5.3.17/ext/mysqlnd_qc
cp -R mysqlnd_qc-1.1.1/* php-src-PHP-5.3.17/ext/mysqlnd_qc
Get APC:
wget http://pecl.php.net/get/APC-3.1.13.tgz
tar -xzvf APC-3.1.13.tgz
mkdir -p php-src-PHP-5.3.17/ext/apc
cp -R APC-3.1.13/* php-src-PHP-5.3.17/ext/apc/
Compile: (maybe don't need all on other systems)
sudo yum install bison
sudo yum install libxml2 libxml2-devel
sudo yum install autoconf213
sudo yum install httpd-devel
sudo yum install bzip2 lbzip2 bzip2-libs bzip2-devel
export PHP_AUTOCONF=/usr/bin/autoconf-2.13
./buildconf --force
make clean && make
(for me the linkage failed and had to add '-lpthread' to linkage)
make test
sudo make install
I used also the following 2 commands but I don't remember for what and when...
phpize
aclocal
Run the same ./configure as in phpinfo and add these options:
--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-qc --enable-mysqlnd-qc-apc --enable-mysqlnd --enable-apc --enable-static=apc
All the --with must be replaced.
It looks like you have to compile from source giving the right .configure options.
pecl install just gives you a .so, which is a dynamic module extension, you can add via php.ini
So if you really need mysqlnd_qc with apc (do you?), you have to get the php src, and compile it
with the needed modules.
If you don´t need it, just say no or hit return when pecl install mysqlnd_qc ask you about it.

Install PECL SSH2 extension for PHP

I am trying to install this
http://fr2.php.net/manual/en/book.ssh2.php
on a Centos 5 (a fork of RHEL 5).
I installed libssh2 (yum install libssh2) which is located in /usr/lib, and when I install SSH2 extension (via pecl install -f ssh2) I get this message
checking for ssh2 files in default path... not found
configure: error: The required libssh2 library was not found. You can obtain that package from http://sourceforge.net/projects/libssh2/
ERROR: `/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr' failed
If I set /usr/lib, I get the same message
ERROR: `/tmp/pear/download/ssh2-0.11.0/configure --with-ssh2=/usr/lib' failed
Where is the problem?
Installing libssh2 via tar.gz from http://sourceforge.net/projects/libssh2/ help a lot (--with-ssh2=/usr/local/include/).
But :
yum install libssh2-devel
...is a better idea.
$ sudo pecl channel-update pecl.php.net
$ sudo apt-get install libssh2-1-dev
$ sudo pecl install -a ssh2-0.12
$ echo 'extension=ssh2.so' | sudo tee /etc/php5/mods-available/ssh2.ini > /dev/null
$ sudo php5enmod ssh2
yum install libssh2-devel didn't work for me:
No package libssh2-devel available.
So I downloaded rpm package from rpmfind and installed with rpm -ivh
After that just added extension=ssh2.so to /etc/php.d/ssh2.ini
This is updated answer from #klay + modification from #avn from comment under working solution for PHP 7.x.
$ sudo pecl channel-update pecl.php.net
$ sudo apt-get install libssh2-1-dev
$ sudo pecl install -a ssh2-1.0
$ echo 'extension=ssh2.so' | sudo tee /etc/php/7.2/mods-available/ssh2.ini > /dev/null
$ sudo phpenmod ssh2
Regarding line:
echo 'extension=ssh2.so' | sudo tee /etc/php/7.2/mods-available/ssh2.ini > /dev/null
Make sure that path /etc/php/7.2/mods-available is valid and there is a match with your php version.
I'm running on Centos, none of these answer were the entire solution for me. I followed these instructions:
$ sudo yum install -y gcc php-devel php-pear libssh2 libssh2-devel
But php-devel would not install, complaining about conflicts. I searched yum to find what php devel packages I had available
$> yum search php|grep devel
...
php55u-devel.x86_64 : Files needed for building PHP extensions
php56u-devel.x86_64 : Files needed for building PHP extensions
php70u-devel.x86_64 : Files needed for building PHP extensions
...
So I ran
$> sudo yum install -y php56u-devel
And it installed cleanly. Then, continuing with the instructions, I ran
$ pecl install -f ssh2
And it compiled. Then I added the extension to php
$ touch /etc/php.d/ssh2.ini
$ echo extension=ssh2.so > /etc/php.d/ssh2.ini
And on my system, instead of
$ /etc/init.d/httpd restart
I had to do
$ sudo /bin/systemctl restart php-fpm.service
So that was all the steps to install. And finally to confirm:
$> php -m|grep ssh2
ssh2
I had this problem:
I'm on a Pair.com "Advanced" hosted account, so I'm a little limited on what I'm allowed to do. I don't think I can yum nor aptitude nor any of the other pre-compiled packages.
I've downloaded and compiled libssh2. During the pecl process, it asks where the library is located. It's in "~/usr/local/lib" and I've tried several variations, including fully qualified. But I kept getting the same error.
The error message doesn't spell out precisely which file it's looking for. libssh2.so is in that directory. I know the output is supposed to be ssh2.so. I wondered if there is supposed to be an ss2.something, or libssh.nothing?
I fixed it thus. In my case, after compiling libssh2 I downloaded the PEAR tarball. The trick was:
./configure --with-ssh2=<libssh2 location> --prefix=<libssh2 location>
Another trick is that, since Pair.com is running FreeBSD, I have to do a "cd ." after the ./configure command. Otherwise, make produces a "Permission denied" error. Apparently, this is necessary on all *nix BSD flavors.
The error:
checking for ssh2 files in default path... not found
configure: error: The required libssh2 library was not found.
...can be seen in the source code.
The logic in the code reveals that it will throw this error if it cannot find /include/libssh2.h in either /usr/local, /usr or in the path supplied by the optional --with-ssh2=[DIR] directive. In other words, without customising the directive, it needs to find one of the following:
/usr/local/include/libssh2.h
/usr/include/libssh2.h
If it passes this check, it then assumes it can find the libssh2 lib at /usr/local/lib or /usr/lib.
Hopefully the info above is enough to help someone debug their issue. My own case is fairly specific and unusual (macOS with Homebrew in a custom install path), but in case it helps anyone else, here's my horrifically hacky workaround. Works perfectly lol
In a nutshell I'm creating two temporary symlinks so that pecl can find ssh2 where it expects.
# First check that neither /usr/local/include nor /usr/local/lib exists
sudo ln -s /usr/local/CustomInstallPath/Homebrew/Cellar/libssh2/1.9.0_1/include /usr/local/include
sudo ln -s /usr/local/CustomInstallPath/Homebrew/Cellar/libssh2/1.9.0_1/lib /usr/local/lib
pecl install -a ssh2-1.3.1
sudo rm -rf /usr/local/include
sudo rm -rf /usr/local/lib

Categories