Deployment

Deployment API Server


Deployment API Server

Kebutuhan Umum

untuk dapat melakukan deployment API Server ini, developer sudah mempunyai lingkungan kerja (working environment) di Laptop maupun Server sebagai berikut:

  • telah terpasang Apache 2.4 atau NGINX,
  • telah terpasang PHP versi 7.3,
  • telah terpasang Git dengan konfigurasi dan user yang sudah mendapat akses ke repository project,
  • telah memiliki database MySQL versi 5.6/5.7,
  • telah terpasang composer (dependency manager),

Clone Repository

Silakan login ke laman Bitbucket.org dan clone repository Git. Contoh:

git clone https://xxxnamauserxxx@bitbucket.org/dsiunnes/unnes_api.git

Deploy Container

Untuk mempermudah proses deployment baik di Laptop atau Server, kita bisa menggunakan docker container. Pastikan docker sudah terinstall jika ingin menggunakan cara deployment ini.

Masuk ke aplikasi console/terminal pada folder aplikasi /, Gunakan docker-compose untuk membangun container-container yang dibutuhkan:

docker-compose up -d

untuk menyesuaikan port dan password database server pada container tersebut, silakan edit file docker-compose.yml

version: '2'
services:
  client:
    image: panahbiru/php73
    links:
      - clientdb
    ports:
      - "8002:80"
    volumes:
      - ./public:/var/www
      - ./:/opt/api-server

  clientdb:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: "xxxxxxxx"
      MYSQL_USER: "xxxxxx"
      MYSQL_PASSWORD: "xxxxxxx"
      MYSQL_DATABASE: "xxxxxxx"
    ports:
      - "33062:3306"
    volumes:
      - ./mysqldb:/var/lib/mysql

Konfigurasi API Server

Silakan buat file konfigurasi dan file tambahan untuk API Server ini.

1. Buat file .env untuk Lumen di di direktori / sesuaikan isinya:

APP_NAME=Lumen
APP_ENV=local
APP_KEY=nZSwO3Mhlbw3Iw9kxTafxyZYzcfkROvK
APP_DEBUG=true
APP_URL=http://localhost
APP_TIMEZONE=UTC

API_USERNAME=api
API_PASSWORD=labalababel4ng
API_PREFIX=api

LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=unnes_db
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
QUEUE_CONNECTION=sync

2. buat file /config/cnf.php dengan isi:

<?php
return [
    'basepath_file_upload' => '/opt/api-server/file_uploads/', # Absolute path ke folder uploads
];

3. buat file /public/index.php dengan isi:

<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/

$app = require __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$app->run();

Update dependency Lumen Framework dengan composer:

composer install

Persiapan Database

Silakan dump database contoh dari repository Bitbucket pada menu Download. Struktur database dan relasinya ada pada buku Dokumentasi Database.

Silakan sesuaikan kembali dan pastikan koneksi database di file .env.

Uji Coba

Untuk menguji coba dengan menggunakan aplikasi testing API seperti Insomnia ataupun Postman.