Use Contentstack to power content for your PHP projects

Create PHP-based applications and use the PHP SDK to fetch and deliver content from Contentstack. The PHP SDK uses the Content Delivery APIs.

Getting Started

This guide will help you get started with our PHP SDK to build apps powered by Contentstack.


To get started with PHP, you will need the latest version of PHP (version 7.0.23 or above).

SDK Installation and Setup

To use the PHP SDK, you need to perform the following steps:

  1. Download/clone the PHP SDK from here.
  2. Paste the downloaded ZIP file of the PHP SDK to a folder of your choice.

Let's get started with the implementation.

Initialize SDK

You will need to specify the API Key, Delivery Token, and Environment Name of your stack to initialize the SDK.

use Contentstack\Contentstack;
include_once "contentstack/index.php";
$stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME);

Once you have initialized the SDK, you can start getting content in your app.

Basic Queries

Get a Single Entry

To get a single entry, you need to specify the content type as well as the uid of the entry:

$result = $stack->ContentType(CONTENT_TYPE_UID)->Entry(ENTRY_UID)->toJSON()->fetch()
$result - entry object

Get Multiple Entries

To retrieve multiple entries of a content type, you need to specify the content type uid. You can also specify search parameters to filter results:

$result = $stack->ContentType(CONTENT_TYPE_UID)->Query()->toJSON()->includeCount()->includeContentType()->find()
$result[0] - array of entries
$result[1] - content type
$result[2] - count of the entries

These were example of some of the basic queries of the SDK. For advanced queries, refer to our API reference documentation by visiting the link given below.

API Reference

Go through our SDK API Reference guide to know about the methods that can be used to query your content in Contentstack.

Read PHP API Reference Guide

Download SDK

The PHP SDK interacts with and uses our Content Delivery APIs to fetch content from Contentstack. Download the SDK to deliver content to your PHP projects.

Download the PHP SDK

Example Apps

To help you get started, we have created a sample application that is powered by Contentstack PHP SDK. Click on the link below to read the tutorial of the app, view app demo, or download the code from GitHub. 

PHP Demo App

Was this article helpful?