Contentful CMS Integration with Cloudways

Contentful CMS Integration with Cloudways

Let’s start the installation process by launching a server on the Cloudways hosting platform.

Launch a Server

Sign-in to your Cloudways account, and if you don’t have an account then sign-up here. After selecting the server size, bandwidth, and server location, click the Launch button.

image1-292-1024x491.png

Cloudways Launch Server screen

For this guide, I am using Custom PHP Application but you can follow the following process for any other application as well.

Launch SSH Terminal

On the server settings page, click the Launch SSH Terminal button and use the credential (available on the same screen) to access the server.

image2-292-768x361.png

Install Contentful CMS

Navigate to your desired folder and use the following command to install Content;

composer require contentful/contentful

image6-180-768x542.png

The installation process will take less than 30sec to complete.

Integration Process

Once the installation is successfully done on the server. Let’s test the integration between the Cloudways hosting platform and Contentful CMS.

For this purpose, I’ve written a very basic function that will pull the title of the content. The idea is to share the basics of integration between your application on Cloudways and Contentful CMS.

Function //Homepage (index.php file)

<?php
require 'vendor/autoload.php'; // initiate and established the connection
$client = new \Contentful\Delivery\Client('ruaopLJdbDWPg6FkiY16J8QIeZoiDjdlPwR_PfLnGx8', 'okrx0bt8on5x', 'master'); // API token declaration
try{
$entries = $client->getEntries();
$entry = $client->getEntry('6RHNiZLQwLghtcNCZ616RP'); //a specific entry
echo $entry->getTitle(); //displays the title of the entry
}
}
catch(Exception $e){
echo "Error";
echo $e;
}
?>

Targeted Entry

Following is the screenshot of the content available on my Contentful dashboard.

image4-233-1024x226.png

Function’s Output

Similarly, you can pull and present the content and its attributes the way required by your application.

Conclusion

Contentful is one of the top headless CMS, and one of the reasons for its increasing user-base is its API-first nature which allows the developers, and content developers a major advantage by allowing integration on a wide range of devices (PC, Smartphone, Wearables, etc).

Read my full article on Cloudways - Integrate Contentful with Your Web Application Using Cloudways