Theory
Where your code runs matters
In BCA405-01 your JavaScript ran in the browser, on the student's phone. Then Node.js let JavaScript run on the SERVER instead. PHP is the language that made server-side web programming mainstream long before Node existed, and it still runs a huge share of the web.
This semester you will build a small event-registration portal with login in PHP. But PHP has one rule that trips up every beginner on day one: it runs on the SERVER, not in the browser, so you cannot just double-click a .php file and expect it to work. This lesson explains why, and gets you set up.
Theory
PHP, formally
PHP (PHP: Hypertext Preprocessor) is a widely used, open-source, server-side scripting language for web development.
The defining word is server-side: the web server runs your PHP code, which typically BUILDS HTML, and sends only the finished HTML to the browser. The browser never sees your PHP.
History in one line: created by Rasmus Lerdorf around 1994, it grew through PHP 5 and the much faster PHP 7 to today's PHP 8.x (with a JIT compiler, match expressions, named arguments and more). Its role: dynamic pages, form processing, and database-backed sites: exactly what an event portal needs.
Theory
The kitchen and the plate
Think of the browser as a diner and the server as a kitchen.
Client-side JavaScript is like garnishing the plate AT the table. Server-side PHP is the kitchen: the cooking happens out of sight, and only the finished dish (HTML) is carried out to the diner. The customer never sees the recipe, the raw ingredients, or the database the kitchen consulted. That hidden execution is why PHP can safely talk to databases and secrets: the browser only ever receives the plated result.
Practical
hello.php: PHP embedded in HTML
<!DOCTYPE html>
<html>
<body>
<h1>Event Portal</h1>
<?php
// Everything between <?php and ?> runs on the SERVER
echo "<p>Welcome! Server time is " . date("H:i") . "</p>";
?>
<p>This line is plain HTML.</p>
</body>
</html>
Follow along
Setting up with XAMPP
- Install XAMPP (or WAMP) It bundles the Apache web server, PHP, and MySQL/MariaDB together: everything a PHP site needs in one install.
- Put your file in htdocs Save hello.php inside XAMPP's htdocs folder. This is the folder Apache serves from.
- Start Apache Open the XAMPP control panel and start Apache (and MySQL when you need the database).
- Open it through localhost Visit http://localhost/hello.php in a browser. Apache runs the PHP and returns HTML. Do NOT double-click the file.
- Edit in VS Code Use VS Code (with a PHP extension) as your editor; save, then refresh the browser to see changes.
Quiz
A student double-clicks hello.php to open it directly in the browser, and sees the raw PHP code as text instead of the page. Why?
- The PHP file is corrupted
- PHP is server-side: it must be run by a web server (Apache via XAMPP) and accessed through http://localhost, not opened as a file
- The browser needs a PHP plugin installed
- PHP only works in Chrome
Show the answer
PHP is server-side: it must be run by a web server (Apache via XAMPP) and accessed through http://localhost, not opened as a file
PHP executes on the SERVER, so the file must be served by Apache and reached via http://localhost/hello.php; opened directly as a file (file://), no server runs the PHP, so the browser just shows the source text. This is the number one day-one confusion. Option A is wrong (the file is fine). Option C is a myth: browsers do not run PHP at all, with or without a plugin: the server does. Option D invents a browser restriction. The fix is always: start Apache, access through localhost. Server-side means a server must be in the loop.
Think first
PHP or Node: same side, different language
In BCA405-01 you wrote a server in Node.js. Now PHP is also server-side. So what actually differs between them, and why might a project pick PHP? Then tap.
Show the answer
Both run on the SERVER and build responses for the browser, so they occupy the same ROLE. The difference is the language and ecosystem: Node runs JavaScript (one language across client and server) with an event-loop model, while PHP is a language built specifically for the web, traditionally paired with Apache and MySQL, and it powers enormous platforms like WordPress. A project might pick PHP for its maturity, huge hosting availability, gentle setup (XAMPP), and vast existing codebase. Neither is 'better': they are 2 answers to the same server-side question. Knowing both makes you flexible about where code should run.
Watch out
Setup traps
Double-clicking .php files: the quiz bug; always go through http://localhost.
Wrong folder: files outside htdocs are not served; Apache only sees htdocs.
Apache not started: localhost will not respond until Apache is running in the XAMPP panel.
Port conflicts: another program on port 80 can block Apache; XAMPP will flag it, and you can change the port.
Editing but not refreshing: PHP runs fresh on each request; save, then reload the browser.
Theory
The portal starts here
With XAMPP running and hello.php served, your development loop is set: write PHP, save, refresh localhost. Every lesson this unit adds a piece of the event portal: next comes the language's basic grammar (tags, echo, variables, comments), then data types, control flow and arrays, and form handling with $_GET and $_POST to actually process a registration. Server-side web development, one page at a time.
Summary
Key takeaways
- PHP is a server-side scripting language: the server runs it and sends resulting HTML to the browser.
- The browser never sees your PHP, only the finished output: which is why PHP can safely handle databases and secrets.
- History: created by Rasmus Lerdorf (mid-1990s), evolved through PHP 5, 7, to today's PHP 8.x.
- XAMPP/WAMP bundles Apache + PHP + MySQL; put files in htdocs and access via http://localhost.
- You cannot double-click a .php file: it must be served by a running web server.
- Same server-side ROLE as Node.js (BCA405-01), different language and ecosystem.
- Memory hook: PHP is the kitchen; the browser only gets the plated dish.