Configure the PHP SDK (video tutorial)
Last updated: Mar-07-2025
On this page:
Overview
Learn how to install and configure the Cloudinary PHP SDK in your PHP environment. This enables you to utilize Cloudinary for uploading, managing, and displaying assets in your applications.
Video tutorial
View the code
You can find the code from this tutorial in GitHub.Tutorial contents
This tutorial presents the following topics. Click a timestamp to jump to that part of the video.
Introduction
Cloudinary has powerful tools for transforming and managing your images and videos to improve your media workflow. In this video, you'll learn how to install and set up the Cloudinary PHP SDK so you can start using these features. |
Install the PHP SDK
To install the Cloudinary PHP SDK, use Composer to manage dependencies. In your composer.json file, add "cloudinary/cloudinary_php": "^2" , then run composer install to install the Cloudinary PHP package and its dependencies. |
|
Retrieving and configuring Cloudinary credentials
Next, retrieve your Cloudinary credentials and add them to your .env file:
|
|
.env
Important
- When writing your own applications, follow your organization's policy on storing secrets and don't expose your API secret.
- Don't store your
.env
under version control for maximum security.
Loading environment variables in PHP
To import the credentials from your .env file into your project, use the phpdotenv library:
|
|
Creating a Cloudinary instance
Use a configuration object to create a Cloudinary instance:
To confirm you set everything up correctly, print the instance to your HTML page and run the code. You should see your configuration details, including your Cloud Name, API Key, and API Secret. |
|
Generating an HTML image tag with Cloudinary
Use the Cloudinary instance to generate a basic HTML <img> tag:
Run the code to display your image. |
Applying image transformations
The image may be too large, but one of the great features of Cloudinary is on-the-fly transformations. Instead of using HTML resizing, Cloudinary optimizes the image itself. To resize an image:
|
Keep learning
Related topics
- Learn more about the PHP SDK.
- Watch more Dev Hints videos on the Cloudinary YouTube channel.
If you like this, you might also like...
Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.
✖️