Set Up a PHP Dev Environment for PHLO
Using this guide, you can set up a development environment in five minutes to trigger a PHLO.
Install PHP, Composer, Laravel, and the Plivo PHP SDK
To get started, install PHP, the Composer dependency manager, the Laravel web framework, and Plivo’s PHP SDK.
Install PHP
Operating System | Instructions |
---|---|
macOS | Install PHP using the official macOS installer or by downloading and installing it. |
Linux | Download and install PHP using your favorite package installer. |
Windows | Use the official Windows installer. |
Install Composer
All modern PHP frameworks use the Composer dependency manager; we highly recommend using it as the package manager for your web project. Follow the instructions to download and install Composer for macOS and Linux and for Windows, or follow the steps below.
-
Download the latest version of Composer.
-
Run this command in Terminal:
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line.
-
Copy the file to /usr/local/bin and make it executable:
-
If your PATH doesn’t include /usr/local/bin directory, we recommend adding it so that you can access it globally. To check if the path has /usr/local/bin, enter
If necessary, run these commands to update the $PATH:
-
You can also check the version of Composer by running this command:
-
Download the latest version of Composer.
-
Run this command in Terminal:
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line.
-
Copy the file to /usr/local/bin and make it executable:
-
If your PATH doesn’t include /usr/local/bin directory, we recommend adding it so that you can access it globally. To check if the path has /usr/local/bin, enter
If necessary, run these commands to update the $PATH:
-
You can also check the version of Composer by running this command:
-
Run the command
-
Make the composer.phar file executable:
Note: PHAR (PHP archive) is an archive format for PHP that can be run on the command line.
-
Run this command to make Composer globally available for all system users:
-
Download and run the Windows Installer for Composer.
Note: Allow Windows Installer for Composer to make changes to your php.ini file.
-
If you have any terminal windows open, close all instances and open a fresh terminal instance.
-
Run the Composer command.
Install Laravel and create a Laravel project
Install the Laravel web framework by running the command
Once you have Laravel installed, create a project directory using the command mkdir mylaravelapp
, then change to that directory and create a new Laravel project.
This command creates a directory named quickstart with the necessary folders and files for development.
Install the PHP Plivo SDK
To install the stable release of the Plivo SDK, run this command in the project directory:
To install a specific release, run this command in the project directory:
Alternatively, you can download source code from GitHub and run
The composer
command generates the autoload files, which you can include in your PHP source code by using the line
Trigger the PHLO
Create and configure a PHLO, then integrate the PHLO into your application workflow by making an API request to trigger the PHLO with the required payload.
You can run a PHLO with static payload values by entering specific values in fields like from
and to
on the PHLO console.
To deliver a dynamic payload instead of a static one, define the payload keys as Liquid templates on the PHLO console and pass the values at runtime.
Create a Laravel Controller
Change the directory to the project directory and run this command to create a Laravel controller named PhloController in the app/http/controllers/ directory.
Edit app/http/controllers/phloController.php and paste into it the code below for either a static or dynamic payload.
Static payload
Dynamic payload
- Replace the placeholders
<auth_id>
and<auth_token>
with your authentication credentials, which you can find on the overview page of the Plivo console. - We recommend that you store your credentials in the
auth_id
andauth_token
environment variables to avoid the possibility of accidentally committing them to source control. If you do this, you can initialize the client with no arguments and it will automatically fetch the values from the environment variables. - Replace the placeholder
<phlo_id>
with the PHLO_ID from the PHLO list screen of the Plivo console. - Replace the placeholder
<Caller_ID>
with a phone number you’ve purchased, and<Destination_Number>
with the phone number you’ll be calling. Both phone numbers should be in E.164 format.
Add a route
To add a route for the outbound function in the PhloController class, edit routes/web.php and add this line at the end of the file:
Note: If you’re using Laravel 8 you need to use the fully qualified Class name for your controllers. For example:
Route::match(['get', 'post'], '/triggerphlo', 'App\Http\Controllers\PhloController@triggerPhlo')
Save the file and run it.
Your local development server will be started and you can test the Laravel application via the URL http://localhost:8000/triggerphlo/.
Note: If you’re using a free trial account you must verify (sandbox) your destination number, unless you use the phone number you used for signup verification as your destination number. We require this as a security measure to avoid abuse. To sandbox a number in a Plivo trial account, visit Phone Numbers > Sandbox Numbers and click on Add Sandbox Number.