Installing OCI8 for use with UCV and MAMP PRO

The following steps are to get the oci8 extension running locally with MAMP PRO. oci8 is necessary in order to access our Oracle databases in Laravel.

These instructions assume that we are starting from scratch, so if you have already completed some of the steps, feel free to repeat them by uninstalling and re-installing or simply skip them (this is not recommended because it'll be harder to track down where things went wrong in the case of accidents).

First, you need to disable your system integrity protection (SIP). This will allow you to make changes to your system files. (We will re-enable this later, so no worries!)

After you've rebooted your machine with SIP disabled, install MAMP PRO.

Once your MAMP PRO instance is registered, open up the application and in the sidebar under the "Languages" section, click on PHP. Change the default version to 7.1.32 (in our example) or anything around there. Save and restart your servers.

You'll want to add some aliases so that the oci8 module gets installed on the PHP files that MAMP will be using. Open up terminal and type:

$ sudo nano ~/.bash_profile

Your .bash_profile should be appear in terminal after entering your system password. Paste these lines to the file:

##MAMP PHP PATH
export PATH="/Applications/MAMP/bin/php/php7.1.32/bin:$PATH"

##MAMP ALIASES
alias php='/Applications/MAMP/bin/php/php7.1.32/bin/php -c "/Library/Application Support/appsolute/MAMP PRO/conf/php.ini"'
alias pear='/Applications/MAMP/bin/php/php7.1.32/bin/pear'
alias pecl='/Applications/MAMP/bin/php/php7.1.32/bin/pecl' 

Make sure that the php version in the alias strings match that of the default version you set in MAMP PRO. To save your file, press CONTROL-X, y, and return.

Source your .bash_profile file

$ source ~/.bash_profile
            

Install Homebrew locally by running this command in terminal:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

After that is complete, we need to install the autoconf package through Homebrew to supplement the installation of oci8. Do so by running this command next:

$ brew install autoconf

Prepare Oracle Instant Client for the oci8 install.

You're going to want to download both the basic package and the SDK package. At the time this was written, we downloaded version 19.3.0.0.0's packages.

Once those are downloaded, un-zip them both. Place the sdk folder from the un-zipped SDK package folder into your unzipped basic package folder. Rename the folder with the basic package contents and the sdk folder to instantclient.

Create a new folder, lib in your usr/local/ folder. If you can't find the usr directory, make sure you have hidden files showing in your finder. Move your instantclient folder to the usr/local/lib folder.

Update permissions on your usr/local directory:

$ sudo chmod -R 777 /usr/local

Next, install download PEAR & PECL. In terminal (making sure you are currently in your home directory first), run:

$ cd ~
$ curl -O https://pear.php.net/go-pear.phar

Then run:

$ sudo php -d detect_unicode=0 go-pear.phar

When prompted, enter 1, then /usr/local/pear, then enter. Then, type 4, then /usr/local/bin, and enter.
You will hit enter one more time to install PEAR. When prompted to change the contents of php.ini, type n, and then enter once more.

You should now see a thank-you message if these steps were properly taken.

Check if PEAR works with this command:

$ sudo pear version

You should now see the PEAR and PHP version in terminal.

Now we can install the oci8 module. In terminal, type:

$ sudo pecl install oci8

When prompted, enter:

instantclient,/usr/local/lib/instantclient

Open up MAMP PRO to edit your php.ini file. To do so, click on PHP under the Languages section again. Next to the default PHP version is an arrow. Click on that arrow. A text editor with php.ini should open. Do a search for "Dynamic Extensions" in the file. In that section, add this line:

extension=oci8.so

Save the file, exit the editor, and restart servers. To be sure that oci8 was properly installed, you can click on the WebStart button in MAMP PRO. In the page that opens, click on phpinfo. There should be a section for the oci8 module (on top of the openssl module) if everything was done correctly.

Now, we are ready to continue with the rest of the process. Clone the repository to your desired location, set-up Composer and Laravel, set up the CV host in MAMP, etc.

Don't forget to re-enable SIP by following the same steps you took to disable csrutil, but now you want to use the csrutil enable command.