Aral Code

Getting Started Lesson 2 of 17

Getting Started with PHP — XAMPP and Your First Page

Install XAMPP, start Apache and MySQL, put PHP files in htdocs, open them through localhost, and use the built-in PHP server.

PHP pages must be run by a server; double-clicking a .php file just shows the code. The easiest way to get a server on your own computer is XAMPP.

Step 1: Install XAMPP

  1. Download XAMPP from apachefriends.org for your operating system.
  2. Install it (on Windows, the default folder C:\xampp is best).
  3. Open the XAMPP Control Panel and click Start next to Apache (the web server) and MySQL (the database).

When both turn green, open your browser and go to http://localhost. You should see the XAMPP welcome page.

Step 2: Create a page in htdocs

XAMPP serves files from the htdocs folder (C:\xampp\htdocs). Make a folder for your work, like htdocs\aralphp, and create hello.php inside it with any text editor (VS Code is recommended):

<?php
$name = "Juan";
echo "<h1>Hello, $name!</h1>";
echo "<p>PHP version: " . phpversion() . "</p>";

Step 3: Open it through localhost

Visit http://localhost/aralphp/hello.php. The page shows:

In the browser

Hello, Juan!
PHP version: 8.2.12

Always open PHP pages through http://localhost/..., never by double-clicking the file (file:///C:/...). Only the server runs PHP.

A file with only PHP

If a file contains only PHP, start it with <?php and leave out the closing ?>. This avoids accidental blank space being sent after the code, a common cause of "headers already sent" errors later.

Alternative: PHP's built-in server

If PHP is installed on its own (for example with Homebrew on a Mac), you can start a quick development server in any folder:

cd my-project
php -S localhost:8000

Then open http://localhost:8000/hello.php. It's perfect for practice, but not for real public websites.

Running PHP in the terminal

PHP can also run scripts without a browser, which is handy for quick tests:

php hello.php

Output

<h1>Hello, Juan!</h1><p>PHP version: 8.2.12</p>

In the terminal you see the raw HTML, because there's no browser to display it. Many examples in this course show the output this way.

Seeing errors

While learning, make sure PHP shows errors. Put this at the top of your file during development:

<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);

Turn this off on a real public website, so visitors never see details about your code.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Where do you put PHP files in XAMPP?
2. How should you open hello.php?
3. Which XAMPP module is the web server?
4. What does php -S localhost:8000 do?

By Sir Reyel · Last updated 2026-12-04