PHPARI is a class library and development framework, designed to make the development of Asterisk ARI applications a breeze. Technically speaking, PHP isn’t the natural choice for developing ARI applications and the reason for that is simple: ARI is Asynchronous, most PHP developers aren’t familiar with Asynchronous programming. In order to overcome this issue, the PHP React library is used, in order to provide a means of developing Asynchronous applications with PHP.
The following tutorial will teach you how to get ARI and PHPARI off the ground and up and running.
Step 1: Get ARI Working on Asterisk
As ARI is a WebSocket technology, so naturally, we’ll need to enable the Asterisk HTTP server. So, let’s do that first, open the /etc/asterisk/http.conf file for editing:
** Pay attention to the prefix setting above, it is currently disabled. When enabled, a prefix will be assigned to the Asterisk http server URL, so accessing WebSockets and other Asterisk http resources, will be via the prefix routing.
If you would like to support TLS (encrypted web sockets), add the following:
Following the above configuration, the web server should be fully configured. Now, we need to configure the ARI connector, done via editing the /etc/asterisk/ari.conf file:
Step 2: PHPARI Installation
The preferred method of installation is via composer. You may find additional information about the actual composer.json file for this at https://www.packagist.org.
The recommended file is as follows:
We recommend working with the dev-master package, as the code is being maintained on a daily basis.
Step 3: The basic Stasis Application Template
Before you can continue working with PHPARI, you need to setup the phpari.ini file. Here is a sample of what your file should look like:
** Pay attention, if your /etc/asterisk/http.conf file indicated a prefix, your endpoint value should include the prefix. For example, if you’ve set the prefix to ‘asterisk’, your endpoint URL shall be /asterisk/ari.