Deploying a PHP application to Cloud Foundry (OpenCart)

Ram Iyengar
Cloud Foundry Foundation
4 min readAug 20, 2020
Cover Photo

The aim of Cloud Foundry is to provide a great developer experience. Cloud Foundry tools achieve this by allowing programmers to deploy their apps with a single command. This deployment workflow can be enabled independent of language, framework, cloud provider, or local environment.

Several independent pieces of technology come together to make this great experience possible. Let’s take a look at each of them in the context of a specific example.

What is OpenCart?

OpenCart is written in PHP. It is an open-source ecommerce platform that can enable an online web store for merchants. It employs a database (MySQL) backend in

OpenCart allows extensive customizations to your ecommerce vendor experience and provides extensibility with over 13,000 widgets installable from their Marketplace.

OpenCart powers in excess of 340,000 merchants all over the globe.

Deploying OpenCart using Cloud Foundry.

Here are the steps that you need to take to deploy OpenCart using Cloud Foundry. Don’t forget the prerequisites.

Step 1: Clone the OpenCart repo to your dev machine.

git clone https://github.com/opencart/opencart.git

Step 2: Change directories into the repo you just cloned.

cd opencart

Step 3: Deploy the ecommerce store to the cloud.

cf push opencart-test

Now wait for the steps to complete. Once the installation is complete and the application has been started successfully, you will see this message on the terminal:

name: opencart-testrequested state: startedroutes: opencart-test.de.a9sapp.eulast uploaded: Tue 11 Aug 19:47:22 IST 2020stack: cflinuxfs3buildpacks: php 4.4.16type: webinstances: 1/1memory usage: 256Mstart command: $HOME/.bp/bin/startstate since cpu memory disk details#0 running 2020–08–11T14:17:43Z 0.0% 25.9M of 256M 350.5M of 512M

This means that the application is ready. Make use of the “routes” parameter in the output to access the application.

Deployed app, displayed on browser

There are a couple of steps to make the application fully functional, namely configuring a database and setting up the right DNS.

How to update the app?

If you make modifications to the code, you can update the app using the same cf push command. Cloud Foundry will pick up the changes and redeploy your application to the same instance.

Prerequisites:

  1. Make sure you have a Cloud Foundry account. You can sign for a trial using one of our providers.
  2. Ensure that you’ve setup Cloud Foundry CLItools on your local machine.
  3. Make sure that you’ve logged in to your Cloud Foundry instance. If not, use cf login -a <provider-url-here>.

Beneath the hood

Cloud Foundry is a PaaS that aims to abstract the details of the language, framework, infrastructure, and cloud provider for the developer. Using a single cf push command initiates the following flow:

1. An app with default attributes is created in the cloud.

2. A random route is mapped to the application.

3. The codebase is packaged and uploaded to the cloud.

4. The buildpacks are downloaded to the cloud and the right one is chosen based on the codebase.

5. The app is containerized and prepared for staging.

6. Additional resources are downloaded for building the app is needed. In the case of this app, HTTPD and PHP are downloaded and installed.

7. A droplet (which is an archive format that contains 3 distinct pieces — the stack, a buildpack, and the app source code) is built and uploaded along with any build artifacts.

8. The app is started using the default start command ($HOME/.bp/bin/start).

Advanced options

You can configure several parameters to fine tune the deployment of an application.

  • Specify the name of the app.
  • Configure any number of instances.
  • Alter the memory limits of your application.
  • Customize the domain, hostname, and routes.
  • You can read the cf push documentation page for further details.

Trial Cloud Foundry Account Providers

The simplest way to experience Cloud Foundry is to create a trial on any one of our Certified Providers:

  • Atos Cloud Foundry
  • IBM Cloud Foundry (formerly Bluemix)
  • SAP Cloud Platform
  • SUSE Cloud Application Platform
  • Swisscom Application Cloud
  • VMware Tanzu

Other distributions of Cloud Foundry include:

  • anynines Public PaaS
  • Pivotal Web Services

We also strongly recommend enabling CF on your own infrastructure. You can make use of the tools available or deploy our open source version.

Conclusion

Cloud Foundry aims to make deployment a trivial and simple task. And it doesn’t get simpler than cf push. What are your thoughts? Do you have any questions about the whole process? Please leave a comment below to let us know.

Cloud Foundry Summit Europe 2020 is built by and for the Cloud Foundry community. Whether you’re new to Cloud Foundry, you’re a long-time contributor building the platform, or you’re using Cloud Foundry to attain your business goals, Cloud Foundry Summit is the place to collaborate with other developers, operators, CIOs and IT professionals to shape the future of the project, share best practices and innovate together.

Dates: Oct 21st & 22nd 2020

The best way to connect with the Cloud Foundry community is to join our Slack Workspace at https://slack.cloudfoundry.org/. Those in the Slack community help you get quickly connected with other members or someone from the Cloud Foundry Foundation.

--

--

Ram Iyengar
Cloud Foundry Foundation

culture vulture. (d)evangelist. help tech find people, and vice versa.