Set up your Square SDK for a PHP Project

Learn the basic steps to set up the Square SDK for a PHP project.

Link to section

Start a new 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.

Link to section

Composer

You can use Composer to configure and install the Square PHP SDK, as follows:

composer require square/square

This command does the following:

  • Searches the Packagist repository for the square/square package. 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.

Link to section

Manual configuration

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:

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:

https://github.com/square/square-php-sdk/blob/master/example-autoload.php

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:

require 'autoload.php'; use Square\SquareClient;
Link to section

See also