THU.JUN.18
2026
23:36:17
← back to modules MODULE · 01 · PHP
0 / 10 chapters complete · 0%

First PHP File

Make Apache and PHP run YOUR code, served over the network. The "I built this" moment.
Connect VS Code to Lubuntu over SSH → drop a PHP file in your project folder → hit it in a browser → celebrate.

The setup you'll use forever

Picture the cast:

  • Windows = your cockpit (where your hands are)
  • VS Code on Windows = the editor
  • VS Code Remote-SSH = the bridge to Lubuntu
  • Files actually live on Lubuntu's disk
  • Apache reads those files when a browser asks

Like Google Docs but for code — you edit "in" VS Code, file lives on the server. Exact pattern the pros use with AWS, just with a laptop instead of a datacenter.

Connect VS Code to Lubuntu

  1. In VS Code: open Extensions, search "Remote - SSH", install
  2. Hit F1 → "Remote-SSH: Connect to Host..."
  3. Add new host: ssh erictey@192.168.0.19
  4. Pick where to save SSH config (default is fine)
  5. VS Code reopens connected to Lubuntu — check bottom-left, should say "SSH: 192.168.0.19"
  6. File → Open Folder → /home/erictey/server

The disk-to-URL map

Apache is configured to serve from /home/erictey/server/. The mapping:

  • File /home/erictey/server/index.php → URL http://192.168.0.19/
  • File /home/erictey/server/hello.php → URL http://192.168.0.19/hello.php

Path on the left, URL on the right. They mirror each other.

Write your first PHP file

  1. In VS Code (connected to Lubuntu), create new file: hello.php
  2. Type this:
    <?php
    echo "Hello, network.";
    ?>
  3. Save (Ctrl+S)
  4. From Windows browser: hit http://192.168.0.19/hello.php
Browser shows "Hello, network." — that's PHP running on Lubuntu, output sent over your WiFi, displayed on Windows. That round-trip is exactly what every website does. You just built one.

If something went wrong

  • Browser shows the raw PHP code: Apache's PHP module not loaded. sudo a2enmod php8.3 && sudo systemctl restart apache2
  • 404 Not Found: wrong path/filename. Linux is case-sensitive: Hello.php ≠ hello.php. Stick to lowercase.
  • 403 Forbidden: chmod 644 /home/erictey/server/hello.php
  • Blank page: PHP error with display off (we fix this in the PHP tab). Check sudo tail /var/log/apache2/error.log
  • Connection refused: Apache stopped. sudo systemctl start apache2

Folder convention

One folder per project — even if there's only one project right now.

/home/erictey/server/
├── medtrack/
│   ├── index.php
│   └── assets/
├── another-project/
│   └── index.php
└── tools/
    └── db-backup.php

Then http://192.168.0.19/medtrack/ serves MedTrack, the other URL serves the other project. A single Apache can host like a dozen apps without breaking a sweat.

Build: Greeter Page

Goal: take a name from the URL and greet that specific person. First taste of dynamic web pages.

  1. Create /home/erictey/server/greet.php
  2. Drop this in:
    <?php
    $name = $_GET['name'] ?? 'stranger';
    echo "<h1>Hey there, " . htmlspecialchars($name) . "!</h1>";
    echo "<p>Welcome to my server. The time here is " . date('H:i') . ".</p>";
    ?>
  3. Hit http://192.168.0.19/greet.php — should say "Hey there, stranger!"
  4. Now hit http://192.168.0.19/greet.php?name=Eric
  5. Should say "Hey there, Eric!" with the current time

Stretch: add another query param like ?name=Eric&age=25 and have the page say "you're 25 years old."

What you just learned: reading URL params ($_GET), null coalescing (??), output escaping (htmlspecialchars), date formatting. We'll go deep on all of these.

Curious how /home/erictey/server/ ends up served by Apache? Peek at the APACHE tab — it's a one-line Alias in /etc/apache2/sites-available/000-default.conf.