How to setup Oracle Instant Client with XAMPP in macOS Mojave? - php

I am using macOS and have successfully installed and set up XAMPP on my system. But the problem is that I want to connect to an oracle database through PHP Easy Syntax like below:
$conn = oci_connect('xx', 'xx', '123.123.xxx.x/xxxx');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
But i get this error on running the page
Call to undefined function oci_connect()
After reading some article i found that i have to install oracle instant client but i really don't know the steps to download which version and then where to unzip the files in xampp folder. I am really a novice in this area.

This is what I did on macOS Mojave. I used the native installer XAMPP 7.4.9 from
xampp-osx-7.4.9-0-installer.dmg. I did a basic install with the Developer files
option selected - this was the default.
It seems like XAMPP for macOS doesn't have the OCI8 extension built. (I noticed
the XAMPP VM install from xampp-osx-7.4.9-0-vm.dmg also didn't have the OCI8
extension, but I haven't played with it yet.)
Sadly the 'obvious' method of installing OCI8 with the pecl command fails to
correctly find the right PHP version. E.g. running:
sudo /Applications/XAMPP/xamppfiles/bin/pecl install oci8
and answering:
instantclient,/Applications/XAMPP/xamppfiles/lib/instantclient-11.2.0.3.0/
fails with checking PHP version... Unknown option: n. The PECL config looked OK, but there must have been some conflict with the native PHP version.
Anyway, the slightly longer manual install of OCI8 works. The instructions are below.
I prefer to use a more recent Instant Client, so download the latest Instant
Client Basic and SDK packages from
here
and unzip them:
cd $HOME/Downloads
curl -O https://download.oracle.com/otn_software/mac/instantclient/instantclient-basic-macos.zip
curl -O https://download.oracle.com/otn_software/mac/instantclient/instantclient-sdk-macos.zip
Extract the Instant Client (substitute your download directory path):
cd /Applications/XAMPP/xamppfiles/lib
sudo unzip /Users/cjones/Downloads/instantclient-basic-macos.zip
sudo unzip /Users/cjones/Downloads/instantclient-sdk-macos.zip
You can optionally do some cleanup. Get rid of the old Instant Client:
sudo rm -rf /Applications/XAMPP/xamppfiles/lib/instantclient-11.2.0.3.0
and remove new libraries not needed by OCI8:
sudo rm -f /Applications/XAMPP/xamppfiles/lib/instantclient_19_3/{*jdbc*,*occi*,*mysql*,*jar,uidrvci,genezi,adrci}
Download the OCI8 extension from PECL and
extract it:
cd $HOME/Downloads
curl -O https://pecl.php.net/get/oci8-2.2.0.tgz
tar -xzf oci8-2.2.0.tgz
Build and install OCI8. You'll need some kind of compiler available; I have XCode installed:
cd oci8-2.2.0
/Applications/XAMPP/xamppfiles/bin/phpize
./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config --with-oci8=shared,instantclient,/Applications/XAMPP/xamppfiles/lib/instantclient_19_3
make
sudo make install
Then, tell XAMPP to enable the extension:
sudo /Applications/XAMPP/xamppfiles/xampp oci8
At the prompt, enter the path to the Instant Client directory /Applications/XAMPP/xamppfiles/lib/instantclient_19_3 like:
Please enter the path to your Oracle or Instant Client installation:
[/Applications/XAMPP/xamppfiles/lib/instantclient-11.2.0.3.0] /Applications/XAMPP/xamppfiles/lib/instantclient_19_3
installing symlink...
patching php.ini...
OCI8 add-on activation likely successful.
XAMPP: Stopping Apache...ok.
XAMPP: Starting Apache...ok.
Now when you check http://localhost/dashboard/phpinfo.php you should see the OCI8 section.
You may be interested in how to 'run' an Oracle DB on macOS, which can be done in a VirtualBox VM like: https://blogs.oracle.com/opal/the-easiest-way-to-install-oracle-database-on-apple-mac-os-x. Other people use a Docker container for the same thing.

Related

How to install OCI8 extension on PHP 7.4 on macOS Catalina or Big Sur?

I already have PHP 7.4.11 and Apache 2.4.46 installed on my Mac via Homebrew.
Then installed Oracle instant client & sqlplus (v19.3.0.0.0):
$ brew tap InstantClientTap/instantclient
$ brew install instantclient-basic
$ brew install instantclient-sqlplus
Next is to install the OCI8 extension, by running:
pecl install oci8
PECL prompted me this:
Please provide the path to the ORACLE_HOME directory. Use
'instantclient,/path/to/instant/client/lib' if you're compiling with
Oracle Instant Client [autodetect] :
I was not sure what is this /path/to/instant/client/lib, so I ran locate sqplus:
/usr/local/Cellar/instantclient-sqlplus
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/.brew
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/.brew/instantclient-sqlplus.rb
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/INSTALL_RECEIPT.json
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/bin
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/bin/sqlplus
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib/libsqlplus.dylib
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib/libsqlplusic.dylib
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/libexec
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/libexec/sqlplus
/usr/local/Homebrew/Library/Taps/instantclienttap/homebrew-instantclient/Formula/instantclient-sqlplus.rb
/usr/local/bin/sqlplus /usr/local/lib/libsqlplus.dylib
/usr/local/lib/libsqlplusic.dylib /usr/local/opt/instantclient-sqlplus
/usr/local/var/homebrew/linked/instantclient-sqlplus
OK, let's try these 2 directories:
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib
checking Oracle ORACLE_HOME install directory...
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib checking
ORACLE_HOME library validity... configure: error: Oracle library
directory not found in
/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib ERROR:
`/private/tmp/pear/temp/oci8/configure
--with-php-config=/usr/local/opt/php/bin/php-config --with-oci8=/usr/local/Cellar/instantclient-sqlplus/19.3.0.0.0dbru/lib' failed
/usr/local/lib/
checking Oracle Instant Client directory... /usr/local/lib/ checking
Oracle Instant Client SDK header directory... configure: error: Oracle
Instant Client SDK header files not found ERROR:
`/private/tmp/pear/temp/oci8/configure
--with-php-config=/usr/local/opt/php/bin/php-config --with-oci8=instantclient,/usr/local/lib/' failed
/path/to/instant/client/lib produced the same error like the former.
What's the correct one, then?
Personally I'd install the new Instant Client 19.8 DMGs from Oracle. The download page and the packages contain instructions. Also see the steps at Notarized macOS Oracle Instant Client Packages Make Installation Easier. Install the Basic and SDK packages - and maybe SQL*Plus if you want that too. The path you would give at the PECL prompt will be /Users/yourname/Downloads/instanclient_19_8 but you can move that directory if you want to put it somewhere else.
It could be that the brew packages are putting the header files in a place that the OCI8 install script isn't aware. By using the DMGs, the headers will be found.

Install phpredis MAC OSX

Can anyone help me install php-redis in MAC OSX .
brew install php-redis
not working.
pecl install php-redis
also not working getting -
invalid package name/package file "php-redis".
Homebrew Error:
homebrew_error
git clone https://www.github.com/phpredis/phpredis.git
cd phpredis
phpize && ./configure && make && sudo make install
Add extension=redis.so in your php.ini
brew services restart php#7.2
make test
You can check working or not
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
As of 2019, with homebrew php7.2 and up, pecl is now installed by default alongside the php binaries.
To see this for yourself type which pecl.
Steps to install
Check your version of redis, then find a suitable version of the extension here.
If unfamiliar with pecl, type pecl to see the options.
Issue pecl install redis-5.0.2. (or your version). Enter no to each question asked if you're not sure.
If that succeeds check the new file it created at: /usr/local/lib/php/pecl/20180731/redis.so
The install will have added extension="redis.so" to top of your php ini.
Check that by opening the file /usr/local/etc/php/7.3/php.ini.
(assuming you're on 7.3 there)
brew services restart php.
php -i | grep Redis
Redis Support => enabled
Redis Version => 5.0.2
This is what I just did in September 2019 and it works for me.
If what mwal wrote above doesn't work (please try his/her answer first),
first, try to uninstall first (if you have it but broken):
sudo pecl uninstall redis
and after that run:
sudo pecl install redis
After that, ini the php.ini, use full path for the extension.
Mine was /usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so (assuming you are using php#7.3)
so at the top of my php.ini file is like this:
extension="/usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so"
Here are steps to use pickle, for PHP >= 7.3 (tested with 8.1):
brew install pickle
pickle install redis
Find your php.ini location via php -i|grep php.ini
Edit the php.ini, insert extension=redis. Preferable at Dynamic Extensions section.
No restart of Apache httpd service is required. You may test your PHP code with Redis
Bonus
If you use VS Code, to enable intellisense / auto complete, at Preference -> paste intelephense.stubs at Search setting box -> Add Item -> select redis.
If you got the following error,
Please make sure the PHP Redis extension is installed and enabled
despite doing everything in the verified answer above, try valet restart . It worked for me
I have tried all these solutions but didn't work for me for a while so I tried this link https://developer.redis.com/develop/php/ from the original docs and it works as charm
If someone gets an error during sudo pecl install redis
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /opt/homebrew/Cellar/-----/pear/System.php on line 294
that means you need to create the broken directory manually.
Try to create the directory...
pecl config-get ext_dir | pbcopy
mkdir -p {paste clipboard value}
# in my case, it was
mkdir -p /opt/homebrew/lib/php/pecl/20200930
Now try to install any pecl extensions.
sudo pecl install redis
After installing any extension, restart php
brew services restart php
Happy coding :)

Cassandra php driver on MacOS - Class 'Cassandra\SimpleStatement' not found

Good day, everyone.
Usually I just using this Official Docs in *nix OS
But now i'm using MacOs and this instructions just doesn't work properly.
In case of pecl install cassandra I got this message:
checking for supported DataStax C/C++ driver version... awk: can't open file /include/cassandra.h
source line number 1
configure: error: not supported. Driver version 2.4.2+ required (found )
ERROR: `/private/tmp/pear/install/cassandra/configure --with-php-config=/usr/bin/php-config' failed
My logic tell me that in that case I need make DataStax C/C++ driver by my own. In folder php-driver\lib I deleting cpp-driver and using this instruction make new and fresh C/C++ driver without errors.
So in official doc it says:
Note The install.sh script will also compile and statically link into the extension a submoduled version of the DataStax C/C++ driver for Apache Cassandra. To use a version of cpp driver that you already have on your system, run phpize, ./configure and make install.
But when i trying to run ./configure from php-drive/ext I got almost the same error:
checking for supported DataStax C/C++ driver version... awk: can't open file /include/cassandra.h
source line number 1
configure: error: not supported. Driver version 2.4.2+ required (found )
Even if I continue and after that error run make install it gives me that log:
/bin/sh /Users/antvirgeo/php-driver/ext/libtool --mode=install cp ./cassandra.la /Users/antvirgeo/php-driver/ext/modules
cp ./.libs/cassandra.so /Users/antvirgeo/php-driver/ext/modules/cassandra.so
cp ./.libs/cassandra.lai /Users/antvirgeo/php-driver/ext/modules/cassandra.la
----------------------------------------------------------------------
Libraries have been installed in:
/Users/antvirgeo/php-driver/ext/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20121212/
cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/#INST#24727#: Operation not permitted
make: *** [install-modules] Error 1
Libraries have been installed in:
/Users/antvirgeo/php-driver/ext/modules
Even if I adding cassandra extension with that path to php.ini I still got error Class 'Cassandra\SimpleStatement' not found in my project.
php -d="extension=modules/cassandra.so" -m showing that cassandra in list of PHP Modules
What am I doing wrong?
PS: I have ubuntu OS in Parallels with this project with DataStax php driver installed with this instructions works fine.
____upd:
After all instructions of #Fero without ANY ERRORS, command /usr/local/bin/php -i | grep -A 10 "^cassandra$" showing me this:
cassandra
Cassandra support => enabled
C/C++ driver version => 2.4.2
Persistent Clusters => 0
Persistent Sessions => 0
Directive => Local Value => Master Value
cassandra.log => cassandra.log => cassandra.log
cassandra.log_level => ERROR => ERROR
And still the same error - Class 'Cassandra\SimpleStatement' not found
______________UPDATED LAST:
Aaaaand it's working! I wrote output phpinfo(); in my project and realize that apache using other php version and php.ini, where wasn't extension=cassandra.so at all.
You will need to install the DataStax C/C++ driver which is a dependency of the PHP driver. Using these instructions followed by make install after the driver has been successfully built will ensure this dependency is available when building the PHP driver. Using the PHP driver build instructions you will need to make sure that GMP and PHP dev libraries are also available before running pecl install cassandra.
EDIT:
Since you are using El Capitan you are running into issues with the System Integrity Protection and you will need to disable it in order to copy files into /usr. The better and recommended option is to install PHP using Homebrew; however you can also use MacPorts if preferred.
Below are the steps used to reproduce the installation of the PHP driver on a clean OSX El Capitan image with Xcode and Homebrew already installed:
brew install autoconf cmake libuv gmp openssl pcre homebrew/php/php55
brew link homebrew/php/php55
mkdir code
pushd code
git clone https://github.com/datastax/php-driver.git
pushd php-driver
git submodule update --init --recursive
pushd lib/cpp-driver
mkdir build
pushd build
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ..
make -j$(sysctl -n hw.ncpu)
sudo make install
popd
popd
mkdir build
pushd ext
/usr/local/bin/phpize
popd
pushd build
../ext/configure --with-php-config=/usr/local/bin/php-config
make -j$(sysctl -n hw.ncpu)
sudo make install
popd
popd
sudo sh -c 'echo "extension=cassandra.so" >> /usr/local/etc/php/5.5/php.ini'
You can then verify the installation using the following command:
/usr/local/bin/php -i | grep -A 10 "^cassandra$"
NOTE: PHP v5.5 is utilized above since that is the default version that comes with El Capitan; PHP v5.6 and v7.0 can also be used instead.
If you need to install the Cassandra PHP extension on MacOS, you can do this simply by installing it via PECL, without having to do anything with turning on or off System Integrity Protection. I've written a blog post with easy step-by-step instructions. It also includes a link to installing PHP from Homebrew since they removed the Homebrew/php tap back in April of this year.
It also by passes the incorrect instructions given on the DataStax website. In short ...
Install Dependencies (I run these commands one at a time to easily view any messages):
$ brew install autoconf
$ brew install cmake
$ brew install automake
$ brew install libtool
$ brew install gmp
$ brew install libuv
$ brew install openssl
Retrieve and build the C++ driver and then create a build directory inside the cpp-driver folder:
$ git clone https://github.com/datastax/cpp-driver.git --depth=1
$ mkdir cpp-driver/build
$ cd cpp-driver/build
Make and build the driver with a qualified call to OpenSSL:
$ cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/ -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib ..
$ make
$ make install
Now you're good to go to install the Cassandra PHP extension libraries using PECL:
$ pecl install cassandra
Check to make sure that the Cassandra extension was added to your PHP.ini file. If not add it.
[cassandra]
extension="cassandra.so"
Restart Apache and you're off and running with Cassandra in PHP.
If you want more detail on what's happening in the above instructions, refer to my blog post here:
https://medium.com/#crmcmullen/how-to-install-the-cassandra-php-driver-on-macos-10-13-high-sierra-and-10-14-mojave-c18263831ccb

Can't phpize or configure an extension in OS X 10.9 Mavericks

I am trying to build the memcached extension on OS X 10.9 Mavericks for use with the built in PHP 5.4, initially I tried pecl install memcached but that threw the following.
checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are located
ERROR: `/private/tmp/pear/install/memcached/configure' failed
So I created a tmp directory and executed pecl download memcached, unzipped the code and cd'd to the appropriate directory.
Trying to phpize it returned the following:
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
I had brew installed zlib a while ago and pointed ./configure at my installation.
./configure --with-zlib-dir=/usr/local/Cellar/zlib/1.2.8 I was greeted with the following error message:
checking for session includes... configure: error: Cannot find php_session.h
So now I'm wondering the best course of action here... /usr/include/ doesn't exist at all... is this a Mavericks thing? I don't remember having this problem in 10.8 at all.
I could try brew installing php-devel but I presume that isn't going to be the right version of what I need? Any help would be greatly appreciated here
Update
locate php_session.h reveals
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/php/ext/session/php_session.h
should I just ln -s this to the expected location or is there some way to do this via XCode? I have the command line tools installed...
run xcode-select --install to install the XCode5 Command Line Tools, then sudo pecl install memcache. You should be good to go.
After install XCode5 Command Line Tools as afessler sugest (xcode-select --install) I couldn't do the "sudo pecl install memcache" because pecl was missing.
I had to install PEAR and PECL following this guide: http://techtastico.com/post/como-instalar-pear-y-pecl-en-os-x-mavericks/.
Then all worked good. Thanks!
I had this problem and it was due to MAMP not having all the PHP sources.
I found this really helpful solution that explains how to download and configure them:
https://stackoverflow.com/a/11175197/369326
Note that the MAMP components doesn't include the extras for any versions of PHP higher than php 5.4.10 but you can download the extras from http://php.net/releases.
As said above but not using xcode install
Try installing pecl manually:
curl -O http://pear.php.net/go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar
and then:
sudo pecl install memcache
See more at: http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/#sthash.x2LKdqj6.dpuf

pdo_oci 64bit fedora 17 - cannot find include dir

I am on a 64bit Fedora 17 box, PHP5.4.8. I have Oracle Instant Client 11.2 installed. I am trying to install the pdo_oci package and I'm running into some issues.
I have the latest PDO_OCI package. I unpacked it and executed the following:
~$ > cd ../PDO_OCI-1.0
~$ > phpize
~$ > ./configure --with-pdo-oci=instantclient,/usr/lib/oracle/11.2/client64/lib
I get the error message:
"I'm too dumb to figure out where the include dir is in your instant client install"
As suggested by the pdo_oci manual in php.net, I created couple of paths with the minor version of the OIC as such
ln -s /usr/bin/include/oracle/11.2 /usr/include/oracle/11.2.0.1
Still I get the same error message. Does anybody have any idea?
The machine I'm running this on is not connected to the internet, so I have to run the installation using the previously downloaded packages.
I was running into the same problem. I an running centos 6.5 64bits, but fedora is a lot similar.
Supposing you already installed both basic and devel packages:
oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.4.0-1.i386.rpm
You should specify just the "/usr" directory, as the configure looks for oci.h in this way in configure:
$PDO_OCI_IC_PREFIX/lib/oracle/$PDO_OCI_IC_VERS/client/include/oci.h
so, after editing config.m4 to be able to do a 11.2 install (reference for the url in the end), do this:
./configure --with-pdo-oci=instantclient,/usr,11.2
I followed this tutorial:
http://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/

Categories