> For the complete documentation index, see [llms.txt](https://dika-maulidal.gitbook.io/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dika-maulidal.gitbook.io/home/cloud-computing/microsoft-azure.md).

# Microsoft Azure

Pada tahap ini dilakukan pembuatan Virtual Machine (VM) pada Microsoft Azure menggunakan program Azure for Students. VM ini akan digunakan sebagai server cloud untuk deployment aplikasi web berbasis PHP dan MySQL.

#### Tujuan

* Membuat Virtual Machine berbasis Ubuntu Linux.
* Memperoleh akses server cloud melalui internet.
* Menyiapkan lingkungan untuk deployment aplikasi web.

## Setup Cloud

### Langkah 1 - Membuka Azure Portal

1. Buka Azure Portal.

   [Azure Portal](https://portal.azure.com?utm_source=chatgpt.com)
2. Login menggunakan akun Microsoft yang telah terhubung dengan Azure for Students.

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2Faztqcee4A0WttCZbUbrv%2Fimage.png?alt=media&amp;token=a465f274-cce0-4f26-bf07-c565040d7c5c" alt=""><figcaption></figcaption></figure>

### Langkah 2 - Membuat Virtual Machine

1. Pada kolom pencarian Azure Portal, ketik:

   ```
   Virtual Machines
   ```

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FHHcUFN6MDSgb9Nzfgsjg%2Fimage.png?alt=media&amp;token=5d5425f4-ec1d-4e2d-adb5-252c04bf7d7c" alt=""><figcaption></figcaption></figure>

2. Pilih menu **Virtual Machines**.
3. Klik tombol: **Create**

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FncwFtf99NDzrDpa4gNFA%2Fimage.png?alt=media&amp;token=124df06d-38f0-4b51-88b2-40ea5e5d666d" alt=""><figcaption></figcaption></figure>

### Langkah 3 - Konfigurasi Dasar Virtual Machine

| Parameter            | Nilai                                       |
| -------------------- | ------------------------------------------- |
| Subscription         | Azure for Students                          |
| Resource Group       | cth. (cloud-tubes)                          |
| Virtual Machine Name | cth. (php-crud-server)                      |
| Region               | Central India                               |
| Availability options | No infrastructure redundancy required       |
| Image                | Ubuntu Server 24.04 LTS                     |
| Size                 | B2as\_v2                                    |
| Authentication Type  | Password                                    |
| Public inbound ports | Allow selected ports                        |
| Select inbound ports | <p>HTTP (80)<br>HTTPS (443)<br>SSH (22)</p> |

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FjOHLzbcz1logx2E5N0wa%2Fimage.png?alt=media&amp;token=798f7d46-68da-4526-91ad-a8b05aa57142" alt=""><figcaption></figcaption></figure>

Kemudian Klik **Next: Disk**

### Langkah 4 - Membuka Tab Disks

Gunakan konfigurasi berikut:

| Parameter      | Nilai                  |
| -------------- | ---------------------- |
| OS Disk Size   | Image Default (30 GiB) |
| OS Disk Type   | Standard SSD (LRS)     |
| Delete with VM | Enabled                |

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2Fn75lvyzkXczTIl5gziFG%2Fimage.png?alt=media&amp;token=9f20c3a6-072e-4a5a-930b-6dd2526e5ff2" alt=""><figcaption></figcaption></figure>

Klik: **Next : Networking >**

### Langkah 5 - Membuka Tab Disks

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FA2f6WU8QL5nbw1Du0v9N%2Fimage.png?alt=media&amp;token=c08072e8-3a52-4c97-9759-941072cb3f15" alt=""><figcaption></figcaption></figure>

### Langkah 6 - Create VM

Setelah seluruh konfigurasi selesai, klik:

```
Review + Create
```

Azure akan melakukan validasi terhadap konfigurasi VM yang telah dibuat.

## Verifikasi Virtual Machine

### Langkah 1 - Membuka Resource Virtual Machine

**Klik:**

```
Go to Resource
```

**atau pilih resource:**

```
php-crud-server
```

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FLPL5qxwwp6eZ5SdSSwkb%2Fimage.png?alt=media&amp;token=87e5a055-3821-4238-bab7-ef81ef6bda1a" alt=""><figcaption></figcaption></figure>

### Langkah 2 - Memeriksa Status VM

Pastikan status VM menunjukkan:

```
Running
```

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2Fh5seAoIszib4lIZTIw5b%2Fimage.png?alt=media&amp;token=29f5f6d1-24cb-427e-9d6d-d2df16f2a7cb" alt=""><figcaption></figcaption></figure>

### Langkah 3 - Mendapatkan Public IP Address

Pada halaman Overview, catat alamat IP publik yang diberikan Azure.

Contoh:

```bash
20.219.38.255
```

#### Fungsi Public IP

Public IP digunakan untuk:

* Mengakses website melalui browser.
* Melakukan koneksi SSH ke server.
* Mengelola layanan yang berjalan pada VM.

## Koneksi SSH ke Virtual Machine

### Langkah 1 - Membuka Terminal

Pada sistem operasi Windows, buka:

* Windows Terminal
* PowerShell

### Langkah 2 - Melakukan Koneksi SSH

Jalankan perintah berikut:

```bash
ssh dika@20.219.38.255
```

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FCB5lQw7cWj58NM3MSisw%2Fimage.png?alt=media&amp;token=ad9e9c2e-1d4c-484b-a6b1-176cf0764eff" alt=""><figcaption></figcaption></figure>

## Instalasi Apache Web Server

### Langkah 1 - Update Repository Sistem

Setelah berhasil login ke Virtual Machine melalui SSH, lakukan pembaruan repository package Ubuntu.

Jalankan perintah berikut:

```bash
sudo apt update
```

### Langkah 2 - Install Apache2

Install Apache Web Server menggunakan package manager APT.

Jalankan perintah berikut:

```bash
sudo apt install apache2 -y
```

### Langkah 3 - Memeriksa Status Apache

Setelah proses instalasi selesai, lakukan pengecekan status layanan Apache.

Jalankan perintah berikut:

```bash
sudo systemctl status apache2
```

Apabila instalasi berhasil, akan muncul status:

```
active (running)
```

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FRgyf3a9WhNsdcLr5wh10%2Fapache%20status.png?alt=media&amp;token=55f10f37-4a13-4aa2-bd0c-6f02fe13c9c2" alt=""><figcaption></figcaption></figure>

### Langkah 4 - Membuka Browser

Buka browser dan akses alamat IP publik Virtual Machine.

Contoh:

```bash
http://20.219.38.255
```

## Instalasi PHP

### Langkah 1 - Install PHP dan Modul MySQL

Jalankan perintah berikut untuk menginstal PHP beserta modul yang diperlukan untuk koneksi database MySQL.

```bash
sudo apt install php libapache2-mod-php php-mysql -y
```

### Langkah 2 - Memeriksa Versi PHP

Setelah instalasi selesai, lakukan pengecekan versi PHP.

Jalankan perintah berikut:

```shellscript
php -v
```

Contoh output:

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FjUJNC9Z9ZXsdVEYqVU3M%2Fphp%20-v.png?alt=media&amp;token=2e8dc2b7-efba-452e-9cd4-5f40807e556e" alt=""><figcaption></figcaption></figure>

### Langkah 3 - Membuat File test.php

Masuk ke direktori website:

```shellscript
cd /var/www/html
```

Buat file pengujian PHP:

```shellscript
sudo nano test.php
```

Isi file dengan kode berikut:

```php
<?php
phpinfo();
?>
```

### Langkah 4 - Membuka Halaman PHP

Akses alamat berikut melalui browser:

```shellscript
http://20.219.38.255/test.php
```

<figure><img src="https://3379135436-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pfT5vR8uE4ISAa7XuPV%2Fuploads%2FgDz7oILJY7TAe7bZObuK%2Ftest.php.png?alt=media&amp;token=96089877-fe36-4c91-b040-eaa8e64fef0f" alt=""><figcaption></figcaption></figure>

## Instalasi MySQL Server

### Langkah 1 - Install MySQL Server

Jalankan perintah berikut:

```bash
sudo apt install mysql-server -y
```

### Langkah 2 - Memeriksa Status MySQL

Setelah instalasi selesai, lakukan pengecekan status layanan MySQL.

```bash
sudo systemctl status mysql
```

Apabila berhasil, status yang ditampilkan adalah:

```
active (running)
```

## Membuat Database Inventory

### Langkah 1 - Login ke MySQL

Masuk ke MySQL menggunakan akun root.

```sql
sudo mysql
```

### Langkah 2 - Membuat Database

Buat database baru untuk aplikasi inventory.

```sql
CREATE DATABASE inventory_db;
```

Verifikasi database:

```sql
SHOW DATABASES;
```

## Membuat User Database

Untuk alasan keamanan, dibuat user khusus yang hanya digunakan oleh aplikasi inventory.

#### Langkah 1 - Membuat User

```sql
CREATE USER 'inventory_user'@'localhost'IDENTIFIED BY 'Inventory123!';
```

#### Langkah 2 - Memberikan Hak Akses

```sql
GRANT ALL PRIVILEGESON inventory_db.*TO 'inventory_user'@'localhost';
```

Kemudian jalankan:

```sql
FLUSH PRIVILEGES;
```

### Membuat Tabel Barang

Masuk ke database:

```sql
USE inventory_db;
```

Buat tabel penyimpanan data inventory:

```sql
CREATE TABLE barang (
    id INT AUTO_INCREMENT PRIMARY KEY,
    nama_barang VARCHAR(100),
    kategori VARCHAR(100),
    jumlah INT
);
```

### Menambahkan Data Awal

Tambahkan satu data untuk pengujian.

```sql
INSERT INTO barang
(nama_barang, kategori, jumlah)
VALUES
('Mouse Logitech', 'Elektronik', 10);
```

#### Verifikasi Data

```sql
SELECT * FROM barang;
```

## Deployment Aplikasi CRUD Inventory Barang

### Struktur Aplikasi

File aplikasi ditempatkan pada direktori:

```bash
/var/www/html
```

Struktur file:

```bash
/var/www/html
├── config.php
├── index.php
├── tambah.php
├── edit.php
└── hapus.php
```

### Konfigurasi Koneksi Database

File `koneksi.php` digunakan untuk menghubungkan aplikasi PHP dengan database MySQL.

#### Membuat File Koneksi

```bash
nano /var/www/html/koneksi.php
```

Isi file:

```php
<?php

$host = "localhost";
$user = "inventory_user";
$password = "Inventory123!";
$database = "inventory_db";

$conn = mysqli_connect(
    $host,
    $user,
    $password,
    $database
);

if (!$conn) {
    die("Koneksi database gagal: " . mysqli_connect_error());
}

?>
```

### Deployment Aplikasi CRUD

File aplikasi CRUD kemudian ditempatkan pada direktori:

```bash
/var/www/html
```

Repository source code aplikasi:

```bash
https://github.com/username/inventory-crud
```
