Learn the basic steps to set up the Square SDK for a PHP project.
If you're new to developing Square integrations using the Square PHP SDK, try the Quickstart. It provides step-by-step instructions to explore your first project.
With the Square PHP SDK, you can use Composer for dependency management or configure and manage your project manually. The following are general guidelines for creating a new PHP project.
You can use Composer to configure and install the Square PHP SDK, as follows:
This command does the following:
- Searches the Packagist repository for the
square/squarepackage. PHP package names consist of a vendor name and a project name, separated by a slash.
- Downloads the package to the vendor subdirectory.
- Updates the composer.json file, which describes the packages and version numbers that your code uses at runtime. If composer.json doesn't exist, Composer creates it automatically.
After you've installed the Square PHP SDK, you can begin writing your application code.
If you prefer not to use Composer, you can manually install and configure the Square PHP SDK. To do this, you must first clone these PHP source code packages from GitHub:
- square-php-sdk - The Square PHP SDK.
- core-lib-php - Core logic and utilities for the SDK.
- core-interfaces-php - Interface definitions for the SDK.
- jsonmapper - A library that converts JSON responses into PHP classes.
- unirest-php - A RESTful HTTP client.
Next, you need to provide an autoload script (autoload.php) so that your application can easily access the PHP source code packages at runtime. The Square PHP SDK provides the following example autoload script:
You can download this file, rename it to autoload.php, and use it as is. You can also customize the script to suit your needs.
In your application code, add a
require statement to run the autoload script. After that, you're able to
use any of the Square PHP SDK classes. For example: