StreetGeek Academy · PHP Foundations

🧠 Module 1: Introduction to PHP & Setup

Objective: Understand what PHP is, where it runs, and how to set up your local development environment.

🔹 1. What PHP Is and How It Works

PHP (short for Hypertext Preprocessor) is a server-side scripting language designed
primarily for web development, but it’s also used as a general-purpose programming language.

  • PHP code runs on the server, not in your browser.
  • When a visitor requests a PHP page, the server processes the PHP code, generates HTML, and sends that HTML to the browser.
  • The browser never sees your PHP code—only the rendered result.

🧩 Example

<?php
echo "Hello, StreetGeek!";
?>

The server interprets this, sends only the text Hello, StreetGeek! to the browser, and hides the PHP logic from view.

🔹 2. PHP vs. HTML vs. JavaScript

Language Runs On Purpose Example
HTML Browser Structure Defines page layout (<h1>Title</h1>)
CSS Browser Style Controls colors, fonts, spacing
JavaScript Browser Interactivity Responds to user actions, fetches data dynamically
PHP Server Logic & Data Fetches data, processes forms, connects to databases

💡 Think of it like this:
HTML is your skeleton, CSS is your clothes, JavaScript is your movements,
and PHP is your brain.

🔹 3. Server-side vs. Client-side

Type Runs On Example Use Case
Client-side User’s browser JavaScript Animations, instant form validation
Server-side Web server PHP Database interaction, authentication, dynamic content

PHP runs before the page reaches the browser. JavaScript runs after the browser receives the page.

🔹 4. The LAMP Stack

The LAMP stack is a classic environment for running PHP websites:

  • L – Linux (Operating System)
  • A – Apache (Web Server)
  • M – MySQL (Database)
  • P – PHP (Scripting Language)

You can also run PHP on Windows (WAMP) or Mac (MAMP).

🔹 5. Installing LocalWP / XAMPP / MAMP

Option 1: 🧱 LocalWP (Recommended)

  • Easy setup for WordPress & PHP projects.
  • Download from localwp.com.
  • Create a new site → it automatically installs PHP, MySQL, and a local web server.

Option 2: ⚙️ XAMPP

  • Download from apachefriends.org.
  • Install and open the Control Panel.
  • Start Apache (web server) and MySQL (database).
  • Web root (default): C:\xampp\htdocs\
  • Example project path: C:\xampp\htdocs\php-basics\

Option 3: 🍎 MAMP (Mac)

  • Download from mamp.info.
  • Web directory: /Applications/MAMP/htdocs/

🔹 6. Writing Your First PHP Script

Create a folder called php-basics inside your web root directory:

  • LocalWP: use your site’s app/public folder.
  • XAMPP: htdocs/php-basics
  • MAMP: htdocs/php-basics

Inside it, create a file called index.php and add:

<?php
echo "Hello, StreetGeek!";
?>

Open your browser and visit:

http://localhost/php-basics/

✅ You should see: Hello, StreetGeek!

🔹 7. How the Server Interprets .php Files

When you request a PHP file like:

http://localhost/php-basics/index.php
  • Apache passes the file to the PHP interpreter.
  • PHP executes the code between <?php ... ?> tags.
  • The interpreter outputs HTML, which the server sends to your browser.

🧠 Example

<?php
$greeting = "StreetGeek Academy";
echo "<h1>Welcome to $greeting!</h1>";
?>

→ Browser output:

Welcome to StreetGeek Academy!

✅ Module 1 Deliverable & Assignment

Deliverable
Run your first PHP script that outputs:

<?php
echo "Hello, StreetGeek!";
?>

Assignment

  • Create a folder named php-basics.
  • Save your script as index.php.
  • Open it in the browser via http://localhost/php-basics/.
  • Take a screenshot of the output “Hello, StreetGeek!” for your course submission.

🧩 Module 1 Lab Sheet: Introduction to PHP

Objective: Get hands-on experience with PHP by setting up your environment,
writing your first script, and understanding how PHP interacts with HTML and the web server.

🧰 Lab Setup

Requirements:

  • Installed LocalWP / XAMPP / or MAMP
  • Code editor (Visual Studio Code recommended)
  • Web browser (Chrome, Edge, Firefox, etc.)

Folder Structure:

htdocs/
└── php-basics/
    └── index.php

🧪 Exercise 1: Hello, StreetGeek!

Goal: Write your first PHP program.

  1. Open your php-basics folder.
  2. Create a file named index.php.
  3. Add this code:
<?php
echo "Hello, StreetGeek!";
?>

Open in your browser:

http://localhost/php-basics/

✅ Verify the page displays Hello, StreetGeek!

🧩 Exercise 2: Mixing PHP and HTML

Goal: Learn how PHP and HTML can work together.

<!DOCTYPE html>
<html>
<head>
    <title>StreetGeek Academy</title>
</head>
<body>
    <h1>Welcome to PHP Basics</h1>
    <p>
        <?php
            echo "This line is generated by PHP on " . date("l, F jS Y") . ".";
        ?>
    </p>
</body>
</html>

✅ The date changes dynamically each time you refresh.

🧩 Exercise 3: Embedding PHP Logic

Goal: Use PHP to generate different content dynamically.

<?php
$hour = date("H");
if ($hour < 12) {
    $greeting = "Good morning, StreetGeek!";
} elseif ($hour < 18) {
    $greeting = "Good afternoon, StreetGeek!";
} else {
    $greeting = "Good evening, StreetGeek!";
}
?>
<!DOCTYPE html>
<html>
<body>
    <h1><?php echo $greeting; ?></h1>
</body>
</html>

🧩 Exercise 4: Understanding PHP File Processing

Goal: Verify that PHP code is executed on the server.

  • Open your PHP page in the browser and right-click → View Page Source.
  • Notice that the PHP code (<?php ... ?>) does not appear—only the resulting HTML is shown.

🧩 Exercise 5: PHP Info

Goal: Learn about your server configuration.

  1. Create a new file in php-basics called info.php.
  2. Add this code:
<?php
phpinfo();
?>

Open in the browser:

http://localhost/php-basics/info.php

✅ You’ll see a detailed list of PHP settings, modules, and versions.

📝 Module 1 Quiz

# Question Options Correct
1 What does PHP stand for? a) Personal Home Page · b) PHP: Hypertext Preprocessor · c) Private Home Program b
2 Where does PHP code execute? a) In the browser · b) On the web server · c) On both b
3 Which tag is used to start PHP code? a) <php> · b) <?php · c) {php} b
4 What is the file extension for PHP files? a) .ph · b) .html · c) .php c
5 What happens when you “View Page Source” of a PHP file? a) You see all PHP code · b) You see only HTML output · c) You see server configuration b

💪 Challenge Task – “Dynamic Greeting Page”

Objective: Build a simple PHP web page that changes its message based on the time of day.

  1. Create a file greeting.php inside your php-basics folder.
  2. Write code that:
    • Displays a different greeting based on the current hour (date("H"))
    • Shows today’s date and time using date()
    • Includes some styled HTML (<h1>, <p>, <em>, etc.)

Target format:

Good afternoon, StreetGeek!
Today is Tuesday, October 27, 2025 — The perfect day to learn PHP.

Add CSS styling inline or via <style> tags and run it at:

http://localhost/php-basics/greeting.php

🧾 Submission Checklist

  • ✅ Folder named php-basics
  • index.php displays “Hello, StreetGeek!”
  • info.php shows PHP configuration
  • greeting.php outputs a time-based greeting
  • ✅ Completed quiz answers

🏁 Completion Message: Once you finish, you’ve completed your first step toward PHP mastery.
In Module 2, you’ll learn the syntax and building blocks of PHP — variables, data types, and debugging with var_dump().