Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Send SMS From a Cloud Server Using Twilio

September 20, 2016

4 Min Read
Reading Time: 4 minutes

When you are running business applications like ecommerce stores, web applications, customer-specific applications, and banking apps, you need to reach out to your customers by any medium of communication like email, calls, and SMS messages.

We know that billions of people use cell phones, and it makes it much easier to reach out to them. Here’s a research developed by Statista on the evaluation of cell phone usage since 2013 and it is forecasted that there will be around 5.07 billion cellphone users by 2019.

Mobile Phone Users

We have SMS services like Twilio to reach out our customers and take advantage of the figures. Twilio is a cloud communication platform which provides APIs of messaging, voice calls, and video calls.

send sms with twilio

In this article, we are using Twilio Messaging API on Cloudways server to send SMS messages to customers. I am assuming that you’ve already setup the new server on Cloudways and launched a PHP stack application.

Now, we have to follow 5 easy steps to setup Twilio API on Cloudways.

Let’s get started.

Step 1: Register Account on Twilio

You need to register an account on Twilio first. After signing up you will get your API credentials that includes Account SID and Auth Token. After registration, go to Account settings where you can see the secret Twilio API information.

Twilio provides two sets of API credentials if you have a trial account.

Login and head over Account settings where you’ll see these.

Register Account on Twilio

You can use TEST credentials for testing purpose in your apps but when you are upgrade to a premium account you will need the LIVE credentials. Since we have trial account, we will use the test credentials.

Step 2: Enable Geographic Permissions

Twilio provides its services worldwide but you can enable and disable it by configuring geographic permissions. Go to Account settings, scroll down, and you will see the settings for SMS and Voice geographic permissions.

Enable Geographic Permissions

We are setting up SMS API so click on SMS geographic permissions then filter your country to enable checkbox in it.

SMS API settings

Step 3: Verify Numbers to Send Message

Twilio will ask you to verify your phone number on trial account. To verify the number move to Verification Page and enter your digits.

Verify Numbers to Send Message

Click on the “Text Me” button and you will get a verification code. Enter the code in the next verification window and click on Submit button. You have successfully verified your number.

Step 4: Download Twilio Libraries

To send messages from Twilio on Cloudways, you need to create a cloud server.

php server stack

After creating a server, launch PHP stack application and download Twilio API files in your projects. Let’s download the library from the SSH terminal inside Cloudways. You can find it in the Server Tab. Move it to your public_html folder by using this command:

$ cd application/{your app folder name}/public_html/

Now, run the following command to install Twilio library:

$ composer require twilio/sdk:4.11.0

Step 5: Create index.php File in Cloudways Server

It’s time to move to Cloudways server and create an index.php file to add some code. Move to server area and find your Master Credentials and connect to you server with FileZilla.

Create index.php File in Cloudways Server

After connecting it to FileZilla, move to application/{your app folder}/public.html and edit index.php file by adding the following code:


require 'vendor/twilio/sdk/Services/Twilio.php';

use Twilio\Rest\Client;

// Your Account SID and Auth Token from

$sid = 'Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

$token = 'your Auth token';

$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages!
   // the number you'd like to send the message to
       // A Twilio phone number you purchased at

       'from' => '+12406086952',

       // the body of the text message you'd like to send

       'body' => 'Hey shahroz! Good luck for the exam!'

You might be interested at: How To Get Server And App SMS Alerts Using Twilio And CloudwaysBot

We have finally setup Twilio API on Cloudways server to send messages in a simple way. You can also customize it and use forms with validation strategies. Extend the functionality of this service as per your requirements.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Launch PHP websites without the worry of Server Management.

Pre-Installed Optimized Stack with Git, Composer & SSH

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. Besides his work life, he loves movies and travelling. You can email him at

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

BFCM 2019