> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP quick start


[readme-version-support-link]:https://github.com/cloudinary/cloudinary_php#version-support
This quick start lets you get an end-to-end implementation up and running using the PHP SDK in 5 minutes or less.

#### Prerequisites **To perform this quick start, you'll need:**

* A Cloudinary account. If you don't have one yet, you can quickly [register for free](https://cloudinary.com/users/register_free).
* Your product environment credentials. You can find your [credentials](product_environment_settings#api_keys) on the [API Keys](https://console.cloudinary.com/app/settings/api-keys) page of the Cloudinary Console Settings. 
  * To use your **API environment variable**, copy the provided format and replace the `<your_api_key>` and `<your_api_secret>` placeholders with the actual values found on the page. Your cloud name will already be correctly included in the format.
* A working PHP development environment with a [supported version][readme-version-support-link] of PHP.

> **NOTES**:
>
> * This quick start is designed for quick onboarding.  It doesn't necessarily employ coding best practices and the code you create here isn't intended for production.  

> * If you aren't familiar with Cloudinary, you may want to first take a look at the [Developer Kickstart](dev_kickstart) for a hands-on, step-by-step introduction to Cloudinary features. You may also find our [Glossary](cloudinary_glossary) helpful to understand Cloudinary-specific terminology.
## 1. Set up and configure the SDK

### Install the SDK

Use `Composer` to manage your PHP library dependency, and install Cloudinary's PHP library.

1. Run the following command in the root folder of your project to add the SDK and update your `composer.json`: 

    ```
    composer require cloudinary/cloudinary_php
    ```

    
composer.json

You've automatically added Cloudinary to your `composer.json` file, like this:

    ```composer.json
    {
      "require": {
        "cloudinary/cloudinary_php": "^3"
      }
    }
    ```

  
2. Install dependencies, including Cloudinary's PHP package, by running the following command:
  
    ```php
    composer install
    ```

    > **NOTE**: If you don't have the necessary permissions you can run the file itself: `php composer.phar install`.

### Configure Cloudinary

> **INFO**: When writing your own applications, follow your organization's policy on storing secrets and don't expose your API secret.

In a new PHP file, `php_quickstart.php`, use your API environment variable to configure your Cloudinary credentials. Replace `cloudinary://my_key:my_secret@my_cloud_name` with your actual environment variable value:

php_quickstart.php

```php
<html lang="HTML5">
<head>    <title>PHP Quick Start</title>  </head>
<body>
<?php
	
require __DIR__ . '/vendor/autoload.php';

// Use the Configuration class 
use Cloudinary\Configuration\Configuration;

// Configure an instance of your Cloudinary cloud
Configuration::instance('cloudinary://my_key:my_secret@my_cloud_name?secure=true');
```

More info about configuration...

* Using your **environment variable URL** is one of a few options to [configure credentials](php_integration#configuration). 
* The `secure=true` option will ensure the SDK generates HTTPS URLs, and is one of the available [optional configuration parameters](cloudinary_sdks#configuration_parameters).

## 2. Upload an image

Use the `upload` method of the `UploadApi` class to upload assets to Cloudinary. The code is encased in HTML to format and display the response:

php_quickstart.php  (continued)

```php
// Use the UploadApi class for uploading assets
use Cloudinary\Api\Upload\UploadApi;

// Upload the image
$upload = new UploadApi();

echo '******Upload response******';
echo '<br>';
echo '<pre>';
echo json_encode(
    $upload->upload('https://res.cloudinary.com/demo/image/upload/flower.jpg', [
        'public_id' => 'flower_sample',
        'use_filename' => true,
        'overwrite' => true]),
    JSON_PRETTY_PRINT
);
echo '</pre>';
```

More info about upload...

* You can upload from [various sources](upload_parameters#required_file_parameter), not only remote files as in this example code.
* We've set the [public ID](cloudinary_glossary#public_id) and other parameters so that if you run this code more than once, you'll still only have one file uploaded that overwrites the previous one. Without these parameters set, the default option of using a random public ID would be applied, and a new asset would be created each time.

## 3. Get info about the image

Use the `asset` method of the `AdminApi` class to return the details of our uploaded asset. The code is encased in HTML to format and display the response:

php_quickstart.php  (continued)

```php
// Use the AdminApi class for managing assets
use Cloudinary\Api\Admin\AdminApi;

// Get the asset details
$admin = new AdminApi();
echo '******Asset details******';
echo '<br>';
echo '<pre>';
echo json_encode($admin->asset('flower_sample', [
    'colors' => true]), JSON_PRETTY_PRINT
);
echo '</pre>';
```

More info about getting details of an asset...

* This step uses a method of the [Admin API](admin_api#get_details_of_a_single_resource_by_public_id) to return specific details about the image. In addition to the default response details, this example specifically requests to return the color histogram of predominant colors in the image.
* Learn more about [managing assets](asset_management).

## 4. Transform and deliver the image

Use the `imageTag` method to generate the full image URL based on the specified transformation parameters and add the image tag to your HTML code:

php_quickstart.php  (continued)

```php
// Use the Resize transformation group and the ImageTag class
use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\Background;
use Cloudinary\Tag\ImageTag;

// Create the image tag with the transformed image
$imgtag = (new ImageTag('flower_sample'))
    ->resize(Resize::pad()
        ->width(400)
        ->height(400)
        ->background(Background::predominant())
    );

echo '******Your transformed image******';
echo '<br>';
echo $imgtag;
// The code above generates an HTML image tag similar to the following:
//  <img src="https://res.cloudinary.com/demo/image/upload/b_auto:predominant,c_pad,h_400,w_400/flower_sample">

```

More info about transformations...

* Cloudinary supports powerful and extensive [transformations](transformation_reference). You can even combine multiple transformation actions together as part of a single transformation request. Our example delivers an image padded to a width and height of 400 pixels, and uses the images predominant color to for the extra padding needed.
* You need to include classes for the transformation actions that you use (e.g. Resize in the example above).
* You can generate the URL directly, without an encasing IMG tag, using the [image](php_image_manipulation#direct_url_building) method.

## 5. Run your code

Run your file by entering the following command in your terminal: 

```
php php_quickstart.php
```

You’ll see console output for each step of the quick start. Click the generated URLs to view your uploaded image in the browser.

## View the completed code

You can fork the sample code for this quick start from [GitHub](https://github.com/cloudinary-devs/php-sdk-quickstart).

## Next steps
* Learn more about the PHP SDK by visiting the other pages in this SDK guide.
* Get comprehensive details about Cloudinary features and capabilities:
    * [Upload guide](upload_images): Provides details and examples of the upload options.
    * [Image transformations guide](image_transformations): Provides details and examples of the transformations you can apply to image assets.
    * [Video transformations guide](video_manipulation_and_delivery): Provides details and examples of the transformations you can apply to video assets.
    * [Transformation URL API Reference](transformation_reference): Provides details and examples of all available transformation parameters. 
    * [Admin API guide](admin_api): Provides details and examples of the methods available for managing and organizing your media assets.