BAB 1: KENAPA PHP?

1-3: Ekosistem PHP

Objectives

  • Mengenal ecosystem PHP secara keseluruhan
  • Memahami tools dan framework yang tersedia
  • Mengetahui kemana harus mencari resource

Overview Ekosistem PHP

📊 Memuat diagram…

1. PHP Frameworks

Laravel — The King

┌─────────────────────────────────────────────────────────┐
│   LARAVEL — The PHP Framework for Web Artisans           │
├─────────────────────────────────────────────────────────┤
│  🎯 Fokus: Rapid development, elegant syntax            │
│  📦 Ecosystem: Laravel Forge, Vapor, Envoyer, Nova      │
│  👥 Community: Huge, tutorial melimpah                  │
│  📚 Learning: laracasts.com (premium, worth it)         │
│  ⚡ Speed: Cukup cepat untuk most use cases             │
│  ✅ Best for: Startup, MVP, medium-large apps           │
├─────────────────────────────────────────────────────────┤
│  Fitur Unggulan:                                        │
│  • Eloquent ORM (database abstraction)                  │
│  • Blade templating                                      │
│  • Artisan CLI                                           │
│  • Laravel Mix / Vite                                     │
│  • Built-in auth, validation, queue                      │
│  • Huge package ecosystem                               │
└─────────────────────────────────────────────────────────┘

Contoh Syntax Laravel:

php
// Routes
Route::get('/users', [UserController::class, 'index']);

// Controller
public function index() {
    $users = User::where('active', true)->paginate(10);
    return view('users.index', compact('users'));
}

// Model (Eloquent)
class User extends Model {
    protected $fillable = ['name', 'email'];
}

Symfony — The Enterprise Choice

┌─────────────────────────────────────────────────────────┐
│   SYMFONY — The PHP Framework for Professionals        │
├─────────────────────────────────────────────────────────┤
│  🎯 Fokus: Enterprise, reusable components              │
│  📦 Components: Banyak framework lain pakai ini         │
│  👥 Community: Strong, European-dominated               │
│  📚 Learning:Lebih steep dari Laravel                   │
│  ⚡ Speed: Sangat flexible, bisa dioptimize             │
│  ✅ Best for: Large enterprise, complex systems        │
├─────────────────────────────────────────────────────────┤
│  Digunakan oleh:                                        │
│  • Drupal (CMS)                                         │
│  • Laravel (components)                                │
│  • eZ Platform (CMS)                                   │
│  • PHPUnit (testing)                                   │
└─────────────────────────────────────────────────────────┘

CodeIgniter — Lightweight Champion

┌─────────────────────────────────────────────────────────┐
│   CODEIGNITER — Simple and Powerful                    │
├─────────────────────────────────────────────────────────┤
│  🎯 Fokus: Simple, lightweight, fast                   │
│  📦 Size: Very small footprint                         │
│  👥 Community: Smaller but dedicated                    │
│  📚 Learning: Easy untuk pemula                         │
│  ⚡ Speed: Sangat cepat, low resource                   │
│  ✅ Best for: Shared hosting, small-medium apps        │
├─────────────────────────────────────────────────────────┤
│  Kenapa pilih CodeIgniter?                              │
│  • Install mudah di shared hosting                     │
│  • Documentation clear                                  │
│  • Tidak over-engineered                               │
│  • Good untuk belajar fundamentals                    │
└─────────────────────────────────────────────────────────┘

Perbandingan Framework

AspekLaravelSymfonyCodeIgniterSlim
Learning curveMediumSteepEasyEasy
SizeLargeLargeSmallTiny
PerformanceGoodExcellentExcellentExcellent
FlexibilityOpinionatedVery flexibleFlexibleMinimal
Enterprise-readyYesYesModerateNo
Community sizeHugeLargeMediumMedium
Package ecosystemHugeLargeMediumMedium
Best forGeneralEnterpriseSimple appsAPIs

2. Content Management Systems (CMS)

WordPress — The Giant

┌─────────────────────────────────────────────────────────┐
│   WORDPRESS — 43% of the Web                           │
├─────────────────────────────────────────────────────────┤
│  📊 Market share: ~43% semua website                    │
│  🎨 Themes: Ribuan themes gratis & premium             │
│  📱 Plugins: 60,000+ plugins di repository              │
│  👤 Users: Non-technical sampai enterprise              │
│  💰 CMS market: ~65%                                   │
├─────────────────────────────────────────────────────────┤
│  Technology Stack:                                      │
│  • PHP 7.4+ (PHP 8.x recommended)                      │
│  • MySQL/MariaDB database                              │
│  • Vanilla JavaScript ( Gutenberg = React)             │
│  • Template: PHP files dengan Loop                    │
└─────────────────────────────────────────────────────────┘

Contoh WordPress Loop:

php
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <div><?php the_content(); ?></div>
<?php endwhile; endif; ?>

3. Package Manager: Composer

┌─────────────────────────────────────────────────────────┐
│   COMPOSER — Dependency Manager for PHP                 │
├─────────────────────────────────────────────────────────┤
│  📦 Packagist: 350,000+ packages                       │
│  🔗 Concept: Mirip npm untuk Node.js                   │
│  📋 command: composer require vendor/package           │
│  🔄 Updates: composer update                           │
│  🎯 Autoload: PSR-4 autoloading                        │
└─────────────────────────────────────────────────────────┘

Install Composer:

bash
# Linux/macOS
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

# Windows
# Download composer-setup.exe dari getcomposer.org

Contoh Penggunaan:

bash
# Install package
composer require ramsey/uuid

# Install development package
composer require --dev phpunit/phpunit

# Install semua dependencies dari composer.json
composer install

# Update semua packages
composer update

4. Tools & Utilities

Development Tools

🔍 Debugging:

  • Xdebug — PHP debugger dengan step-by-step
  • var_dump, dd() — Laravel debug

📊 Static Analysis:

  • PHPStan — static analysis, catches bugs
  • Psalm — type checking, mirip TypeScript

✨ Code Quality:

  • PHP-CS-Fixer — auto-format code
  • PHP_CodeSniffer — linting & formatting
  • Pint — opinionated formatter (Laravel)

🧪 Testing:

  • PHPUnit — unit testing framework
  • Pest — elegant PHP testing
  • Behat — BDD testing framework

📚 Documentation:

  • phpDocumentor — generate API docs
  • Swagger/PHPDoc — API documentation

VS Code Extensions untuk PHP

#ExtensionFungsi
1PHP IntelephenseIntellisense, autocomplete
2PHP DebugXdebug integration
3PHP Namespace ResolverAuto-import namespace
4PHP Getters & SettersGenerate getters/setters
5Laravel Blade SnippetsBlade syntax support
6DotENV.env file support

5. Database Drivers

MySQL/MariaDB:

  • mysqli_* (native PHP driver)
  • PDO_MySQL (unified interface)
  • Eloquent (Laravel ORM)

PostgreSQL:

  • pdo_pgsql
  • Eloquent (via package)

SQLite:

  • pdo_sqlite
  • Cocok untuk: dev, small apps, testing

MongoDB:

  • mongodb/mongodb (official driver)

6. Learning Resources

📖 Official:

  • php.net/manual — Dokumentasi resmi
  • phptherightway.com — Best practices

🎥 Video:

  • Laracasts — Laravel & PHP (premium, worth it)
  • Traversy Media — YouTube (gratis)
  • Programmer Zaman Now — YouTube (Indonesian)

📝 Written:

  • Medium — banyak PHP articles
  • Dev.to — PHP community
  • Reddit r/PHP

🇮🇩 Indonesian:

  • Codepolitan — Courses & tutorials
  • Petani Kode — Blog tutorial
  • Warung Belajar — Laravel tutorials

PHP Framework Popularity (2024)

Framework⭐ GitHub StarsPopularitas
Laravel75K+████████████████████████████
Symfony30K+████████████████████
CodeIgniter20K+█████████████
Slim12K+████████
CakePHP9K+███████
Yii214K+███████

Exercise

  1. Install Composer di komputer kamu
  2. Browse packagist.org dan lihat package PHP yang popular
  3. Install VS Code extension "PHP Intelephense"
  4. Baca phptherightway.com dan highlight 3 hal baru yang kamu pelajari

Summary

KategoriTools
FrameworkLaravel, Symfony, CodeIgniter
CMSWordPress, Drupal, Magento
Package ManagerComposer + Packagist
DebuggingXdebug, var_dump
Static AnalysisPHPStan, Psalm
Code QualityPHP-CS-Fixer, Pint
TestingPHPUnit, Pest
DatabaseMySQL, PostgreSQL, SQLite, MongoDB

💡Tip

Mulai dengan PHP vanilla untuk memahami fundamental. Setelah paham dasar-dasarnya, pilih Laravel untuk project nyata karena ecosystem-nya paling lengkap dan dokumentasinya melimpah.

Klik tombol ini setelah menyelesaikan materi

📝

Quiz Bab 1

Uji pemahamanmu tentang Kenapa PHP?