In this guide we'll cover how to set up your PHP development environment. We’ll also talk about a couple helpful tools that we recommend for all PHP applications that use Twilio: ngrok and the Twilio PHP SDK. Show Let’s get started! How you install PHP varies depending on your operating system. Operating SystemInstructionsOS XThe easiest way to install PHP on OS X is to use the official installer from php.net. You can also use Homebrew if you prefer. Before we can start our PHP project we’ll need something to write it with. If you already have a code writing tool of choice, you can stick with it for developing your PHP application. If you're looking for something new, we recommend trying out a few options:
If you’re new to programming, we recommend giving Atom and Sublime Text a try before you settle on your favorite. Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage them for you. Create a new empty directory in your development environment and run
We’re almost ready to start writing our PHP application, but first we need to install the Twilio PHP SDK.
We can test that our development environment is configured correctly by creating a simple PHP application.
We can then try running our new PHP web application with the command Once you see your sample PHP web application's “<Response><Say>Hello World!</Say></Response>” message, your development environment is ready to go. But for most Twilio projects you’ll want to install one more helpful tool: ngrok. Most Twilio services use webhooks to communicate with your application. When Twilio receives an incoming phone call, for example, it reaches out to a URL in your application for instructions on how to handle the call. When you’re working on your PHP web application in your development environment, your app is only reachable by other programs on the same computer, so Twilio won’t be able to talk to it. Ngrok is our favorite tool for solving this problem. Once started, it provides a unique URL on the ngrok.io domain which will forward incoming requests to your local development environment. To start, head over to the Ngrok download page and grab the binary for your operating system: https://ngrok.com/download Once downloaded, make sure your PHP web application is running and then start Ngrok using this command: Look at the “Forwarding” line to see your unique Ngrok domain name (ours is 0) and then point your browser at that domain name.If everything’s working correctly, you should see your PHP web application’s Anytime you’re working on your Twilio application and need a URL for a webhook you should use Ngrok to get a publicly accessible URL like this one. You’re now ready to build out your PHP web application. Here are a few other resources we like:
Contributors: Rate this page: 1 2 3 4 5 Need some help?We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow. |