Lesson 2 — Getting Started

Setting Up a PHP Environment

To run PHP locally, you need a web server with PHP installed. Pre-packaged tools bundle everything you need in one installer.

Using XAMPP

XAMPP bundles Apache (a web server), MySQL/MariaDB (a database), and PHP into one installer for Windows, macOS, and Linux — a popular all-in-one choice for beginners. Once installed, PHP files placed in its htdocs folder are accessible through a browser at http://localhost/.

PHP's Built-In Server

For quick testing without installing a full server stack, PHP includes a lightweight built-in development server, launched from the terminal inside your project folder.

TERMINAL — Built-in PHP server
php -S localhost:8000

Common Mistakes

  • Trying to open a .php file directly in a browser without a running server — it will either download the raw file or show nothing meaningful.
  • Forgetting to start Apache/MySQL from the XAMPP control panel before testing a page.
  • Placing project files outside the configured document root (like htdocs), so the server can't find them.
  • Using PHP's built-in server for a live production site — it's intended for local development only.

Professional Tip

PHP's built-in server (php -S localhost:8000) is the fastest way to test a small script without installing a full server stack, and is perfect while working through this course.

Your Turn

Install XAMPP or confirm the PHP CLI is available, then run a simple script using the built-in server and view it in your browser at localhost:8000.

Mini Quiz

What command starts PHP's lightweight built-in development server?