Requirements
- PHP 7.4+ (8.0+ recommended)
- Composer
Installation
Installing the Auth0 PHP SDK requires Composer, the standard dependency management utility for PHP. Composer allows you to declare the dependent libraries your project needs and installs them for you. Please ensure Composer is installed and accessible from your shell before continuing. Next, run the following shell command within your project directory to install the SDK:vendor
subfolder within your project and download all the dependencies needed to use the PHP SDK. This will also create a vendor/autoload.php
file necessary for the SDK to work with your application, which we’ll import later.
Getting Started
To use the Auth0 Authentication and Management APIs, you’ll need a free Auth0 account and an Application:- Go to auth0.com/signup and create your account.
- Once you are in the dashboard, go to Applications, then Create Application.
- Give your Application a name, select Regular Web Application, then Create
- Click the Settings tab for the required credentials used below. To learn more, see Application Settings.
Configure the SDK
You should use environment variables to store and load sensitive Auth0 credentials. This eliminates the need for hard-coding them into your application. Let’s create an.env
file within the root of our project directory to store our application’s credentials:
The easiest way to use environment variables in your project is to use a library like PHP Dotenv along with a local .env
file. Create a .env
file (make sure this is not accessible publicly and is excluded from version control) and add the following values:
.env
file natively, you’ll need to install a PHP library to do so. For the purposes of this documentation we’ll be using vlucas/phpdotenv
, but any “dotenv” library you prefer will work. From our project directory, run the following shell command to install the library:
Initialize the SDK
We’re ready to configure and initialize an instance of the SDK within our new PHP application. Let’s start by creating the PHP source file we’ll be working with for this demonstration,index.php
, and use the following snippet to get started: