Using OCI Object Storage in Laravel

This article describes how you can use OCI Object Storage in your Laravel 11

Patrick Riemer

This article describes how you can use OCI Object Storage in your Laravel 11 application using the following package: patrickriemer/oci-adapter

First you have to create a new bucket. For a "normal S3-like" usage you have to select the Standard tier.

Create new bucket in OCI

After the bucket is created, copy the "namespace" from the detail page. Copy the value into the environment variable "OCI_NAMESPACE" and the bucket name into "OCI_BUCKET".

Next in the right upper corner, click on your profile picture and then on "Tenancy: {your tenancy name}". Under Tenancy Information you will find a "OCID". You can copy this value into the environment variable "OCI_TENANCY_ID".

Tenancy ID

Add your region to OCI_REGION. You can find a full list here. Use the value in the column "Region Identifier" (e.g. ap-singapore-1).

Browser to your user profile and copy the OCID into "OCI_USER_ID".

Tenancy ID

Next you have to create an API key. You can find the link in your user profile on the left side "API keys". Oracle uses private and public keys for this. Generate a new key pair and download the private and public key.

After generating the key, store the fingerprint in "OCI_KEY_FINGERPRINT". Then store the private key file in the root folder in your Laravel project. I will use the filename "oci.pem". Update the environment variable "OCI_KEY_PATH" to the location of your key (in my case "./oci.pem".

Next add the filename (or a wildcard for *.pem) to your .gitignore file.

Your .env file should have now entries that look similar to the following:

                    
OCI_REGION=ap-singapore-1
OCI_BUCKET=my-bucket-name
OCI_TENANCY_ID=ocid1.tenancy.oc1..{longstring}
OCI_USER_ID=ocid1.user.oc1..{longstring}
OCI_KEY_FINGERPRINT=11:12:aa:ab:ac:1d:dd:aa:11:99:22:21:f3:79:12:1b
OCI_KEY_PATH=./oci.pem
OCI_STORAGE_TIER=Standard
                    
                

If you are using config caching, don't forget to run "php artisan config:cache".

The package uses the disk name "oci". You can specify that as your default disk with

                    
FILESYSTEM_DISK=oci
                    
                

Or you can directly address this disk from your Storage facade

                    
Storage::disk('oci')->exists('uploaded_file.txt');
                    
                

Work in progress

The package caters for the most common use cases, but is still a work in progress. The exception handling has to be improved, tests have to be written, etc. Every collaborator is welcome. I am new to Oracle Cloud Infrastructure and don't know if there is a proper way of the move problematic described in the package. If you have a viable solution for this, please contact me.