Install the Twilio PHP Helper Library Without Composer
Time to read: 3 minutes
PHP is a venerable language. As I go to press, it’s in major version 7 and has maintained it’s well-deserved popularity for nearly 25 years.
With two and a half decades of evolution, we PHP developers have quite a few ways to do things. To wit: many of you ask us how to use Twilio’s PHP Helper Library directly, without a package manager.
Today, I’ll show you how to install Twilio’s PHP Helper Library on *NIX or Mac OSX without using the package manager Composer.
Let’s compose some magic.
Prerequisites to Install The Twilio PHP Helper Library (Without Composer)
Before we get started with the install, you’ll need to set a few things up, confirm a few others, and find a phone:
- (If you haven’t yet) Sign up for a free Twilio account here
- Log into the Twilio console
- Visit the Twilio PHP Helper Library page
- A cell phone that can receive SMS
Once we’re on the same page (pun intended!), move onto the next step.
Install The Twilio PHP Helper Library without Composer
If you’ve done the above steps and logged into Twilio, you’re ready to start installing the Helper Library.
Download and Decompress the Twilio PHP Helper Library
In your favorite console, create a new directory for your project and change into it:
Download the PHP Helper Library from the Helper Library page, and unzip it inside. You can also grab the latest library from Github and unzip it from the command line:
Test the Helper Library
Now that you have the PHP Helper library downloaded and unzipped, we’re going to test your install by sending an SMS.
You’re going to need a phone number before we can test sending an SMS. If you already have a Twilio-purchased phone number to use to test, skip the next section.
Purchase a Twilio phone number (if you don’t have one)
Navigate to the Buy a Number page in the Twilio Phone Numbers console.
Check the ‘SMS’ box, then search for your choice of phone number.
Finally, ‘Buy’ your favorite.
Write PHP to Send an SMS
Create a new file – name it whatever you’d like with the extension .php
– then open it in your favorite text editor:
Now, open the Twilio console. You need to prepare to make some substitutions to the code I provide.
Make a note of your Account SID and Auth Token (Click ‘View’ to see the token.)
Now, in your text editor, paste the following code:
Insert your Account SID and Auth Token (from the previous step) into the code where $account_sid
and $auth_token
appear, respectively.
Substitute the value of $twilio_number
with a Twilio number you own (or the number you just purchased). Use E.164 format here – you can find it in an easy, copy/paste-able format in the Phone Number console.
Finally, substitute your cell phone’s number into the line below $client->messages->create(
, where I currently have +18005551212
. Again, use E.164 format.
Test the SMS PHP Script
Save your file and go back to the command line. We’re almost ready for some magic... make sure your phone is on and by your side.
In your console, run the file:
Boom! Did you get the text?
Installing the PHP Helper Library Without Using Composer
And there you have it – the humble beginnings of your next project, all without the use of Composer.
Now – I certainly recommend you use a package manager of some sort for your complex communications applications. In fact, I wrote our PHP SMS Quickstart with Composer in mind – read it if you’d like to try it out.
But if you just don’t want to take this particular plunge, at least you’ve got the scaffolding of a Composer-less app. And whether you use a package manager or not, we can’t wait to see what you build.
Additional Resources:
Paul Kamp is Editor-in-Chief of the Twilio Blog. When not using Composer, he usually can be found writing Python. He can be reached at pkamp [at] twilio.com.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.