1-4: Setup Lingkungan Development
Objectives
- Install dan configure PHP development environment
- Memahami perbedaan XAMPP, Laragon, dan cara manual
- Bisa run PHP script pertama kamu
Pilihan Development Environment
| Environment | Platform | Stack | Karakteristik |
|---|---|---|---|
| XAMPP | Cross-platform | Apache + MySQL | Mudah, cocok pemula |
| Laragon | Windows only | Apache/Nginx | Auto DNS, modern |
| Manual | Linux-centric | Custom | Full control, complex |
| Docker | Cross-platform | Containerized | Reproducible, learning curve |
Opsi 1: XAMPP (Recommended untuk Pemula)
Apa itu XAMPP?
XAMPP adalah singkatan dari:
- X = Cross-platform (Windows, Linux, macOS)
- A = Apache (web server)
- M = MySQL/MariaDB (database)
- P = PHP
- P = Perl
Download & Install XAMPP
Langkah 1: Download
- Buka https://www.apachefriends.org/download.html
- Pilih versi PHP 8.x (terbaru)
- Download sesuai OS kamu (Windows/macOS/Linux)
- Jalankan installer
Langkah 2: Install
Windows:
- Run installer (.exe)
- Pilih lokasi (default:
C:\xampp) - Uncheck "Learn more about Bitnami" (optional)
- Next, Next, Finish
macOS:
- Open downloaded .dmg
- Drag XAMPP ke Applications
- Open XAMPP Control Panel
Langkah 3: Start Services
XAMPP Control Panel:
- Apache → Start (klik Start)
- MySQL → Start (klik Start)
- Ports → Default: Apache=80, MySQL=3306
Langkah 4: Verify
- Buka browser
- Ketik:
http://localhost - Kalau muncul halaman XAMPP → Success! 🎉
Struktur Folder XAMPP
C:\xampp\ # Folder install XAMPP ├── htdocs\ # Document root (letakkan file PHP di sini!) │ ├── index.php │ ├── project-saya.php │ └── folder-saya\ │ └── file.php ├── apache\ # Apache web server ├── mysql\ # MySQL database ├── php\ # PHP installation │ └── php.ini # PHP configuration ├── FileZilla\ # FTP server └── Mercury\ # Mail server
Testing PHP dengan XAMPP
Langkah 1: Buat file PHP
<?php
// File: C:\xampp\htdocs\hello.php
echo "Hello dari XAMPP!";
phpinfo();
?>
Langkah 2: Buka di Browser
Buka http://localhost/hello.php di browser.
Langkah 3: Kalau bisa lihat info PHP → All good! ✅
Opsi 2: Laragon (Windows Only, More Powerful)
Kenapa Laragon?
- ✅ Auto Virtual Host — setiap project dapat URL sendiri (misal:
myproject.test) - ✅ Auto SSL — HTTPS ready
- ✅ Git integration — built-in
- ✅ Node.js, Python, Ruby — multi-language
- ✅ Database management — phpMyAdmin included
- ✅ Terminal integrated — Git Bash, PowerShell
- ✅ Portable — bisa jalan dari USB
Install Laragon
Langkah 1: Download
- Buka https://laragon.org/download
- Download "Laragon Full" (includes everything)
- Install dengan default settings
Langkah 2: Start Laragon
Tray Icon Laragon:
- Klik Start All
- Apache: Running
- MySQL: Running
- Web: Klik → Browser → Buka browser
Langkah 3: Auto Virtual Host
- Buat folder:
C:\laragon\www\belajar-php - Buat file
index.phpdi dalam folder tersebut - Browser otomatis buka:
http://belajar-php.test - Laravel auto-detect & pretty URL!
Struktur Folder Laragon
C:\laragon\ ├── www\ # Document root │ ├── belajar-php\ # Project 1 │ │ └── index.php │ └── myapp\ # Project 2 │ └── public\ │ └── index.php ├── bin\ # Tools (PHP, Apache, MySQL) ├── data\ │ └── mysql\ # Database files └── etc\ # Configuration
Opsi 3: Install PHP Manual
Windows (Manual)
Langkah 1: Download PHP
- Buka https://windows.php.net/download
- Pilih PHP 8.x VS16 x64 Thread Safe
- Extract ke:
C:\php
Langkah 2: Add ke PATH
- Windows Search → "Environment Variables"
- Edit System Environment Variables
- Klik "Environment Variables"
- Edit "Path" → Add
C:\php - OK, OK, OK
Langkah 3: Verifikasi
# Buka CMD baru (tutup CMD yang lama)
php -v
# Output:
PHP 8.3.x (cli) ...
Langkah 4: PHP Built-in Server
# Navigate ke folder project
cd C:\xampp\htdocs\belajar
# Start server
php -S localhost:8000
# Buka browser: http://localhost:8000
macOS
Langkah 1: Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Langkah 2: Install PHP
brew install php
# Verify
php -v
Langkah 3: Start Server
php -S localhost:8000 -t ~/Sites/myproject
Linux (Ubuntu/Debian)
Langkah 1: Install
sudo apt update
sudo apt install php php-mysql php-cli
# Verify
php -v
Langkah 2: Install Apache/MySQL
sudo apt install apache2 mysql-server
sudo service apache2 start
sudo service mysql start
Opsi 4: Docker (Recommended untuk Production-like)
Apa itu Docker?
Docker lets you run services (PHP, MySQL, Redis) dalam container yang isolated dan bisa di-share antar tim.
docker-compose.yml untuk PHP
# docker-compose.yml
version: '3.8'
services:
php:
image: php:8.3-apache
ports:
- "80:80"
volumes:
- ./src:/var/www/html
depends_on:
- db
db:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: myapp
volumes:
- db_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin
ports:
- "8080:80"
depends_on:
- db
volumes:
db_data:
Run dengan Docker
# Start semua services
docker-compose up -d
# Buka browser
# http://localhost → PHP app
# http://localhost:8080 → phpMyAdmin
Troubleshooting Umum
🚫 Apache tidak mau start?
- Port 80 sudah dipakai → cek IIS, Skype
- Skype Options → Connection → uncheck port 80
- XAMPP → Config → Service and Port Settings
🚫 "Connection refused" atau blank page?
- Pastikan Apache running
- Cek file
.phpada dihtdocs - Enable error display:
php
<?php phpinfo(); ini_set('display_errors', 1); ?>
🚫 MySQL tidak mau start?
- Port 3306 sudah dipakai → ganti port
C:\xampp\mysql\data\→ check error log- Backup data → delete
ibdata1→ restart
🚫 Permission denied di Linux?
sudo chmod 755 /var/www/htmlsudo chown -R www-data:www-data /var/www/htmlsudo service apache2 restart
Recommended: VS Code Setup
Extensions yang Perlu Diinstall
| # | Extension | Fungsi |
|---|---|---|
| 1 | PHP Intelephense | Code completion, refactoring |
| 2 | PHP Debug | Xdebug integration |
| 3 | PHP Namespace Resolver | Auto-import |
| 4 | Prettier - Code formatter | Auto format |
| 5 | Live Server | Auto refresh browser (HTML/CSS/JS) |
| 6 | Dracula Official | Dark theme (optional) |
VS Code Settings untuk PHP
// .vscode/settings.json
{
"php.validate.enable": true,
"php.validate.run": "onSave",
"php.suggest.basic": false,
"editor.formatOnSave": true,
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
}
}
Exercise
- ✅ Install XAMPP atau Laragon
- ✅ Start Apache dan MySQL
- ✅ Buat file
perkenalan.phpdi htdocs dengan konten:- Nama kamu
- Tanggal hari ini
- Pesan "Website pertama saya!"
- ✅ Buka di browser:
http://localhost/perkenalan.php - ✅ Bonus: Install VS Code + PHP Intelephense extension
Summary
| Environment | Pros | Cons | Best For |
|---|---|---|---|
| XAMPP | Easy, cross-platform | Basic features | Pemula |
| Laragon | Auto vhost, powerful | Windows only | Windows dev |
| Manual | Full control | Complex setup | Production-like |
| Docker | Reproducible, clean | Learning curve | Team projects |
Recommendation: Mulai dengan XAMPP untuk simplicity. Kalau pakai Windows, upgrade ke Laragon untuk fitur lebih (auto vhost, terminal integrated). Docker bisa dipelajari kemudian saat kamu mulai kerja di tim.
Biasakan buka project dengan URL spesifik (misal: http://localhost/myproject) daripada langsung file (file:///C:/xampp/htdocs/project/). Ini lebih mendekati production environment dan menghindari path issues.
Klik tombol ini setelah menyelesaikan materi
Quiz Bab 1
Uji pemahamanmu tentang Kenapa PHP?