89
1
0
Your First PHP Script Hello World in 3 Minutes

Your First PHP Script Hello World in 3 Minutes

Published on June 26, 2025 by OBSCountdown Editorial

Your First PHP Script: Hello World in 3 Minutes

A step-by-step beginner's guide to writing and running your first PHP script using tools like XAMPP, MAMP, Laragon, or Docker.

πŸš€ What You'll Learn

If you're brand new to PHP, this tutorial will walk you through creating your first "Hello, World!" script. You’ll learn how to:

  • Write a basic PHP file
  • Run it on a local server
  • Understand PHP syntax and output

πŸ›  Prerequisites: Set Up a PHP Environment

To run PHP scripts, you'll need a web server with PHP installed. The easiest ways to get started are:

  • XAMPP – Cross-platform, beginner-friendly stack.
  • Laragon – Lightweight Windows option.
  • MAMP – Great for macOS and Windows.
  • Docker – For containerized setups.

πŸ“„ Step 1: Create Your PHP File

Open your favorite code editor (e.g., VS Code, Sublime Text, Notepad++), and create a new file named index.php in your web root directory:

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

This simple script tells the PHP engine to print the text Hello, World! to your browser.

πŸ“‚ Step 2: Place the File in Your Web Directory

Depending on your setup, place index.php in one of the following folders:

  • XAMPP: C:\xampp\htdocs\hello
  • Laragon: C:\laragon\www\hello
  • MAMP: /Applications/MAMP/htdocs/hello
  • Docker: Bind your local folder using -v ${PWD}:/var/www/html

🌐 Step 3: Run the Script

Start your local web server and visit:

  • http://localhost/hello (XAMPP or Laragon)
  • http://localhost:8888/hello (MAMP)
  • http://localhost:8080 (Docker)

You should see the text Hello, World! displayed on the page. πŸŽ‰

🧠 Understanding the Code

Let’s break it down:

<?php           // Opening PHP tag
  echo "Hello, World!";  // Output to browser
?>           // Closing PHP tag

echo is a PHP command that outputs strings or variables to the browser.

πŸ” What's Next?

  • Try printing variables and using math operators.
  • Explore if-else conditions and loops.
  • Create a simple form that displays user input.

This is just the beginning of your PHP journey. Keep experimenting and building!


Tags: hello world PHP, PHP basics, first PHP script

πŸ“š Continue learning PHP with more beginner-friendly tutorials on file uploads, form handling, and connecting to MySQL.

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment
Replying to someone's comment. Cancel
89
1
0
Join Our OBS Community

Loading...

Join Now