# Set up your development environment

Get familiar with the Stripe CLI and our server-side SDKs.

Check out our [no-code docs](https://docs.stripe.com/no-code.md), use a [prebuilt solution](https://stripe.com/partners/directory) from our partner directory, or hire a [Stripe-certified expert](https://stripe.com/partners/directory?t=Consulting).

Stripe’s server-side SDKs and command-line interface (CLI) allow you to interact with Stripe’s REST APIs. Start with the Stripe CLI to streamline your development environment and make API calls.

Use the SDKs to avoid writing boilerplate code. To start sending requests from your environment, choose a language to follow a quickstart guide.

> #### Chrome extensions
> 
> We recommend you build your payment integration with Stripe (such as [Elements](https://docs.stripe.com/payments/elements.md) or [Checkout](https://docs.stripe.com/payments/checkout.md)) on your own website. Then, set up your Chrome extension to send users to this payment page when they’re ready to complete a purchase.
> 
> This method is more secure and easier to maintain than trying to handle payments directly within the extension.

# PHP


In this quickstart, you install the [Stripe CLI](https://docs.stripe.com/stripe-cli.md)—an essential tool that gets you command line access to your Stripe integration. You also install the [Stripe PHP server-side SDK](https://github.com/stripe/stripe-php) to get access to Stripe APIs from applications written in PHP.

## What you learn

In this quickstart, you’ll learn:

- How to call Stripe APIs without writing a line of code
- How to manage third-party dependencies using Composer
- How to install the latest Stripe PHP SDK v21.1.0
- How to send your first SDK request

## Initial setup

First, [create a Stripe account](https://dashboard.stripe.com/register) or [sign in](https://dashboard.stripe.com/login).

## Set up the Stripe CLI

### Install

From the command-line, use an install script or download and extract a versioned archive file for your operating system to install the CLI.

#### homebrew

To install the Stripe CLI with [homebrew](https://brew.sh/), run:

```bash
brew install stripe/stripe-cli/stripe
```

This command fails if you run it on the Linux version of homebrew, but you can use this alternative or follow the instructions on the Linux tab.

```bash
brew install stripe-cli
```

#### apt

> The Debian build for the CLI is available on JFrog at https://packages.stripe.dev, which isn’t a domain owned by Stripe. When you visit this URL, it redirects you to the Jfrog artifactory list.

To install the Stripe CLI on Debian and Ubuntu-based distributions:

1. Add Stripe CLI’s GPG key to the apt sources keyring:

```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg > /dev/null
```

1. Add CLI’s apt repository to the apt sources list:

```bash
echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list
```

1. Update the package list:

```bash
sudo apt update
```

1. Install the CLI:

```bash
sudo apt install stripe
```

#### yum

> The RPM build for the CLI is available on JFrog at https://packages.stripe.dev, which isn’t a domain owned by Stripe. When you visit this URL, it redirects you to the Jfrog artifactory list.

To install the Stripe CLI on RPM-based distributions:

1. Add CLI’s yum repository to the yum sources list:

```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```

1. Install the CLI:

```bash
sudo yum install stripe
```

#### Scoop

To install the Stripe CLI with [Scoop](https://scoop.sh/), run:

```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```

```bash
scoop install stripe
```

#### winget

To install the Stripe CLI with [winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), run:

```bash
winget install Stripe.StripeCLI
```

#### macOS

To install the Stripe CLI on macOS without homebrew:

1. Download the latest `mac-os` tar.gz file of your cpu architecture type from [GitHub](https://github.com/stripe/stripe-cli/releases/latest).
2. Unzip the file: `tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`.

Optionally, install the binary in a location where you can execute it globally (for example, `/usr/local/bin`).

#### Linux

To install the Stripe CLI on Linux without a package manager:

1. Download the latest `linux` tar.gz file from [GitHub](https://github.com/stripe/stripe-cli/releases/latest).
2. Unzip the file: `tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
3. Move `./stripe` to your execution path.

#### Windows

To install the Stripe CLI on Windows without Scoop:

1. Download the latest `windows` zip file from [GitHub](https://github.com/stripe/stripe-cli/releases/latest).
2. Unzip the `stripe_X.X.X_windows_x86_64.zip` file.
3. Add the path to the unzipped `stripe.exe` file to your `Path` environment variable. To learn how to update environment variables, see the [Microsoft PowerShell documentation](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables).

> Windows anti-virus scanners occasionally flag the Stripe CLI as unsafe. This is likely a false positive. For more information, see [issue #692](https://github.com/stripe/stripe-cli/issues/692) in the GitHub repository.

1. Run the unzipped `.exe` file.

#### Docker

The Stripe CLI is also available as a [Docker image](https://hub.docker.com/r/stripe/stripe-cli). To install the latest version, run:

```bash
docker run --rm -it stripe/stripe-cli:latest
```

### Authenticate

Log in and authenticate your Stripe user [account](https://docs.stripe.com/get-started/account/set-up.md) to generate a set of restricted keys. To learn more, see [Stripe CLI keys and permissions](https://docs.stripe.com/stripe-cli/keys.md).

```bash
  stripe login
```

Press **Enter** on your keyboard to complete the authentication process in your browser.

```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```

### Confirm setup

Now that you’ve installed the CLI, you can make a single API request to [Create a product](https://docs.stripe.com/api/products/create.md).

#### bash

```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```

Look for the product identifier (in `id`) in the response object. Save it for the next step.

If everything worked, the command-line displays the following response.

#### bash

```json
{
  "id": "prod_LTenIrmp8Q67sa", // The identifier looks like this.
  "object": "product",
  "active": true,
  "attributes": [],
  "created": 1668198126,
  "default_price": null,
  "description": "Created with the Stripe CLI",
  "identifiers": {},
  "images": [],
  "livemode": false,
  "metadata": {},
  "name": "My First Product",
  "package_dimensions": null,
  "price": null,
  "product_class": null,
  "shippable": null,
  "sku": "my-first-product-10",
  "statement_descriptor": null,
  "tax_code": null,
  "type": "service",
  "unit_label": null,
  "updated": 1668198126,
  "url": null
}
```

Next, call [Create a price](https://docs.stripe.com/api/prices/create.md) to attach a price of 30 USD. Swap the placeholder in `product` with your product identifier (for example, `prod_LTenIrmp8Q67sa`).

#### bash

```bash
stripe prices create \
  --unit-amount=3000 \
  --currency=usd \
  --product="{{PRODUCT_ID}}"
```

If everything worked, the command-line displays the following response.

#### bash

```json
{
  "id": "price_1KzlAMJJDeE9fu01WMJJr79o", // The identifier looks like this.
  "object": "price",
  "active": true,
  "billing_scheme": "per_unit",
  "created": 1652636348,
  "currency": "usd",
  "livemode": false,
  "lookup_key": null,
  "metadata": {},
  "nickname": null,
  "product": "prod_Lh9iTGZhb2mcBy",
  "recurring": null,
  "tax_behavior": "unspecified",
  "tiers_mode": null,
  "transform_quantity": null,
  "type": "one_time",
  "unit_amount": 3000,
  "unit_amount_decimal": "3000"
}
```

## Manage third-party dependencies

We recommend managing third-party dependencies from [Packagist](https://packagist.org/) using [Composer](https://getcomposer.org/download/), which allows you to add new libraries and include them in your PHP projects.

### Install Composer

From the command line, [download Composer](https://getcomposer.org/download/) using the instructions.

## Install the PHP server-side SDK

The latest version of the Stripe PHP server-side SDK is v21.1.0. It supports PHP versions 5.6.0+.

Check your PHP version:

```bash
php --version
```

### Install the library

Install the library with [Composer](http://getcomposer.org/), a package manager for PHP:

```bash
composer require stripe/stripe-php
```

After you install the library with Composer, it’s automatically added as a dependency in your project’s composer.json file. For example:

```json
{
    "require": {
        "stripe/stripe-php": "^21.1.0"
    }
}
```

To use the bindings, use Composer’s [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading). For example:

```php
require_once('vendor/autoload.php');
```

### Installation alternatives

**Manual installation**

You can [download the latest release](https://github.com/stripe/stripe-php/releases) to use the bindings, then include the init.php file:

```php
require_once('/path/to/stripe-php/init.php');
```

Then, add the following extensions: [cURL](https://secure.php.net/manual/en/book.curl.php) (or optionally, use your own non-curl client) [json](https://secure.php.net/manual/en/book.json.php) [mbstring](https://secure.php.net/manual/en/book.mbstring.php)

## Run your first SDK request

Now that you have the PHP SDK installed, you can create a subscription [Product](https://docs.stripe.com/api/products/create.md) and attach a [Price](https://docs.stripe.com/api/prices/create.md) with a couple API requests. We’re using the product identifier returned in the response to create the price in this example.

> #### Use best practices for API keys
> 
> This sample uses the default keys of your Stripe user [account](https://docs.stripe.com/get-started/account/set-up.md) for your *sandbox* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes) environment. Only you can see these values. Follow [best practices](https://docs.stripe.com/keys-best-practices.md) to manage your keys safely.

#### Create a product and price

```php
<?php
require_once('vendor/autoload.php');

# Don't embed any keys in production code. This is an example.
# See https://docs.stripe.com/keys-best-practices.
$stripe = new \Stripe\StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

$product = $stripe->products->create([
  'name' => 'Starter Subscription',
  'description' => '$12/Month subscription',
]);
echo "Success! Here is your starter subscription product id: " . $product->id . "\n";

$price = $stripe->prices->create([
  'unit_amount' => 1200,
  'currency' => 'usd',
  'recurring' => ['interval' => 'month'],
  'product' => $product['id'],
]);
echo "Success! Here is your starter subscription price id: " . $price->id . "\n";

?>
```

Save the file as `create_price.php`. From the command line, `cd` to the directory containing the file you just saved and run:

#### create_price.php

```bash
php create_price.php

```

If everything worked, the command line shows the following response. Save these identifiers so you can use them while building your integration.

#### bash

```bash
Success! Here is your starter subscription product id: price_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```

## See also

This wraps up the quickstart. See the links below for a few different ways to process a payment for the product you just created.

- [Create a payment link](https://docs.stripe.com/payment-links.md)
- [Stripe-hosted page](https://docs.stripe.com/checkout/quickstart.md)
- [Advanced integration](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)

