Automating PHP-based Microservices Deployment in the Oracle Cloud Platform


Options



Before you Begin

Purpose

In this tutorial you learn how to deploy a simple PHP based REST microservice project to Oracle Application Container Cloud Service using Oracle Developer Cloud Service.

Time to Complete

Approximately 45 minutes

Background

Oracle Application Container Cloud Service provides a lightweight infrastructure so that you can run Java, PHP, and Node.js applications in Oracle Cloud. This cloud service can be integrated with other Oracle services to complement the development process, for example, Oracle Developer Cloud Service.

Oracle Developer Cloud Service is a cloud-based software development Platform as a Service (PaaS) and a hosted environment for your application development infrastructure. It provides an open source standards-based solution to develop, collaborate, build, and deploy applications within Oracle Cloud.

Scenario

This tutorial provides you the source code of an application project ready to be deployed in Oracle Developer Cloud Service.

The EmployeeApp.zip file provided in the section "What do you need?" contains the following structure:

  • The manifest.json file contains the metadata about the application such as the PHP version and the command to execute the application. The manifest.json is required to deploy the application on Oracle Application Container Cloud Service.

  • The start.sh script file contains the instructions to start the application when it's deployed to Oracle Application Container Cloud Service.

  • The timer.sh script file contains the instructions to simulate an application log.

  • The Employee.php file is the employee entity that contains the employee properties.

  • The service.php file contains the class with the functionality of the employee service.

  • The employee-api.php file is the REST service controller that process the REST calls.

  • The Gruntfile.js file defines the build task to create project archive for deployment.

  • The package.json file defines the dependencies required for the Grunt tool to execute the build.

What Do You Need?

Creating a Project and a Git Repository in Oracle Developer Cloud Service

  1. Start your Oracle Developer Cloud Service by following the instructions in Accessing Oracle Developer Cloud Service Using the Web Interface.

  2. On the Welcome page, click New Project.

  3. On the first page of the New Project dialog box, enter a name for the project, such as Employee Application. In the Description field, enter a description, such as Employee REST service using PHP. Select Private for the Security setting, then click Next.

  4. On the Template page, select Initial Repository, and then click Next.

  5. From the Wiki Markup drop-down menu, select TEXTILE. In the Initial Repository area, select Empty Repository, and then click Finish.

  6. Wait for provisioning to complete.

    After provisioning completes, the project is fully provisioned. You're on the project's Home page, which displays the URLs of the Git and Maven repositories.

    Home page with newly created project
    Description of the image

Setting Up Oracle Cloud on Eclipse

Installing the Oracle Cloud Tools Plugin on Eclipse

  1. Open the Eclipse program.

  2. Click Help and then click Eclipse Market.

  3. In the Search tab, find Oracle Cloud Tools, and click Install.

    Search tab of the Eclipse Market window
    Description of the image
  4. Keep all the elements selected and click Confirm.

    Confirm selected features
    Description of the image
  5. Select I accept the terms of the license agreements, and click Finish.

  6. In the Security Warning confirmation message, click OK.

  7. Click Yes to restart the Eclipse program.

Creating an Oracle Cloud connection from Eclipse

  1. Click the Window menu, then click Show View, and then click Other.

  2. Select Oracle Cloud and then click OK.

    Show view window
    Description of the image
  3. Click Connect.

    Oracle Cloud window
    Description of the image
  4. Enter the Identity domain, User name, Password, Connection Name, and click Finish.

Creating a PHP Project

  1. Click the File menu, select New and click PHP Project from the list, and click Next.

  2. Enter the Project name and click Finish.

    Note: If you want to test your application locally you should create the project in the file directory of your server where all the applications are installed.

    New PHP Project window
    Description of the image
  3. Extracts the contents of the employee-service.zip file into the project directory.

    Project Explorer window
    Description of the image

Synchronizing the Project with Developer Cloud Service

  1. Take the EmployeeApp project and drag it into the Employee Application.

    Project Explorer and  Oracle Cloud windows
    Description of the image
  2. Keep the default values and click Finish.

    Sinchronize window
    Description of the image
  3. In the Success confirmation message click OK.

Building Your Application on Oracle Developer Cloud Service

Create a build job to generate the artifacts needed to deploy the application to Oracle Application Container Cloud Service.

  1. Return to your Oracle Developer Cloud Service account and go to your project.

  2. Click Build and then click New Job.

  3. In the New Job dialog box, enter employee-app-build for the Job Name, select Create a free-style job to create a blank job that must be configured to run a build, then click Save.

  4. Click the Source Control tab and select the following values:

    • Git
    • URL: employee-application.git.
  5. Click the Triggers tab and select Based on SCM polling schedule.

    Note: If the Based on SCM polling schedule option is enabled, polling is always triggered when commits are pushed to an internal Git repository.

  6. Click the Build Steps tab, enter and select the following values:

    • Click Add Build Step and select Execute shell.
    • Command:
      cd EmployeeApp
      npm install
      grunt
  7. Click the Post Build tab, enter and select the following values:

    • Archive the artifacts
    • Files To Archive: EmployeeApp\employeeservice.zip
    • Compression Type: NONE
  8. Click Save and then click Build Now.

    If the build was successful, you'll see the employeeservice.zip file in the Artifacts of Last Successful Build section. You can download them by clicking the file name. If the build failed, then go back to check the build job configuration or click Git Logs to see more information about the error.

    Build tab - Package build Job
    Description of the image

Deploying Your Application to Oracle Application Container Cloud Service

  1. Click the Deploy tab and then click New Configuration.

  2. In the New Deployment Configuration page, enter and select the following values, then click Save:

    • Configuration Name: deploy-employee-app
    • Application Name: EmployeeService
    • In the Deployment Target field click New and select Application Container Cloud.
    • In the Deploy to Application Container Cloud window, enter the following values and click Test connection.

      • Data center: Data center of your Oracle Cloud account
      • Identity Domain: Your identity domain
      • Username: Your user name
      • Password: Your password
    • When you see the Successful message click Use Connection.

    • Runtime: PHP
    • Subscription: Hourly
    • Type: Automatic (Select Deploy stable build only)
    • Job: employee-app-build
    • Artifact: employeeservice.zip
  3. Click Action menu and then select Start to deploy the application to Oracle Application Container Cloud Service.

    Note: It could take a few minutes to complete the deployment process.

  4. Click EmployeeService to execute the application.

    Deployments page
    Description of the image

    Now, you can see that the Apache Server is running properly.

    Apache Server home page
    Description of the image
  5. Add to the end of the URL the service endpoint of your application employees-rest-api.php/employees

    Firefox window with the employees response
    Description of the image

Committing and Pushing Changes into the Git Repository

In this section, you learn how the commits to the git repository in Oracle Developer Cloud Service automatically creates the build and the deployment to Oracle Application Container Cloud Service.

  1. Open the Employee.php file and change the fisrtName and lastName properties of the emp1.

    An extract of the Employee.php class file
    Description of the image
  2. Right-click the Employee.php file, select Team, and then click Commit.

    File menu of the Eclise project
    Description of the image
  3. Select the Employee.php file from the Unstaged Changes and drop it on the Staged Changes section, then enter a commit message, and click Commit and Push. You can also enter the Author and Committer.

    Commit window
    Description of the image
  4. Click OK.

    Push results: employee-application.git-ef12
    Description of the image
  5. Go to the Oracle Developer Cloud Service console to the Build section and select employee-app-build.

    Build tab of the Employee application
    Description of the image
  6. After you execute the commit the build is executed. Wait until the build is finished.

    Build History
    Description of the image
  7. Click Deploy and wait until the deployment is finished.

    Deployments tab of the Employee application
    Description of the image
  8. Go to the URL of your service and see the changes.

    Firefox window with the employee service response
    Description of the image

Want to Learn More?