The Auth0 PHP SDK provides you with methods for accessing Auth0's Authentication and Management API endpoints.
- PHP 5.5 or later
Auth0-PHP can be installed one of two ways:
- With Composer
Install With Composer
Otherwise, download Composer locally and run:
This will create
composer.lock files in the directory where the command was run, along with a vendor folder containing this SDK and its dependencies.
Finally, include the Composer autoload file in your project to use the SDK:
If your project does not use Composer or you want to maintain a connection to the Git repo, Auth0-PHP can be installed manually. This process still requires Composer to download dependencies, but the process does not use Composer to manage the package.
First, navigate to the directory that contains the Auth0-PHP library and clone the Github repo:
Download Composer and install the dependencies:
Finally, require the Auth0-PHP autoloader and you're ready to use the SDK:
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. More information about these settings is here.
The examples in this documentation use environment variables to store and load sensitive Auth0 credentials, eliminating the need for you to hardcode them into your application.
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:
AUTH0_REDIRECT_URI value above is a URL for your application that will handle the callback from Auth0. This is used for both successful logins as well as errors. The processing that happens at this URL is covered later in this documentation.
In your application (below the Composer autoload
You can now use the environment variables to instantiate the necessary Auth0-PHP classes:
You are now ready to use Auth0-PHP. Use one of the articles below to add authentication to your existing app or one of our quickstarts to build a test application from scratch: