PHP Training Lesson 01

Lesson 01

Introduction to PHP

What PHP is, how it works with a web server, and how to write and run your very first script.

Syntax echo phpinfo() Beginners

What you'll learn

  • What PHP is and where it runs
  • How PHP fits into the client-server model
  • How to open and close a PHP block
  • Using echo to output text
  • Using phpinfo() to inspect your environment

Code examples

Here's the code written in the video. You can copy and paste these directly into a .php file on your server.

hello.php
<?php

// Your first PHP script
echo "Hello, world!";

// You can also use print
print "<p>This is a paragraph.</p>";

?>
phpinfo.php
<?php

// This outputs a full page of info about your PHP installation.
// Delete this file from your server once you're done with it!
phpinfo();

?>
mixed.php
<!DOCTYPE html>
<html>
<head>
  <title>My First PHP Page</title>
</head>
<body>

  <h1>Welcome</h1>

  <?php
    $name = "World";
    echo "<p>Hello, " . $name . "!</p>";
  ?>

</body>
</html>

Notes & tips

PHP files need a server. Unlike HTML, PHP won't run if you just open the file in a browser. You need a web server (Apache, Nginx) or a local environment like XAMPP or Laragon.

Delete phpinfo.php when you're done. It exposes details about your server configuration that you don't want public.

← Previous Next →