Learning outcome: By the end of this lesson, you will be able to check your PHP installation, create a .php file, and run it in both a terminal and a browser.
You need a code editor, PHP installed on your computer, and a terminal such as PowerShell on Windows. A web hosting account or database is not needed for this lesson.
PHP’s official download page provides installation options for different operating systems. On Windows, follow the Windows download and installation instructions; if you install PHP manually, its folder must be available on your system PATH to run php from any terminal. php.net
Already have PHP installed? Open a terminal and run the check below before installing another copy.
Open PowerShell on Windows, or Terminal on macOS or Linux, and type:
php -v
If PHP is ready, you will see a version number and other information. If your terminal says that php is not recognized or cannot be found, finish the installation, check that PHP is on your PATH, and open a new terminal window before trying again. On macOS, the PHP manual documents installation through Homebrew; on Linux, PHP is commonly installed through the distribution’s package manager. Manual
Create a folder named php-practice. Inside it, create a file named hello.php. Open that file in your code editor and add:
<?php
echo "Hello, PHP!";
Save the file. The <?php tag tells PHP where its code begins. echo outputs text, and the semicolon ends the statement.
Open a terminal inside the php-practice folder and run:
php hello.php
Expected output:
Hello, PHP!
If you see that message, you have successfully run your first PHP script.
From the same folder, start PHP’s built-in development server:
php -S localhost:8000
Keep that terminal window open. In your browser, visit:
http://localhost:8000/hello.php
You should see Hello, PHP! on the page. Press Ctrl+C in the terminal when you want to stop the server. PHP provides this server for local development; it is not intended for hosting a public production website. Manual
Change hello.php so it displays two lines:
Welcome to my PHP practice site!I am learning to build real-world projects.Hint: Use a second echo statement and HTML <p> tags so each message appears as a paragraph. Save the file and refresh your browser.
<details> <summary>Example solution — open after trying the task</summary>
<?php
echo "<p>Welcome to my PHP practice site!</p>";
echo "<p>I am learning to build real-world projects.</p>";
</details>
php is not recognized: Check the installation and PATH, then reopen your terminal.php -S localhost:8000 is still open.hello.php and check the filename in the URL.Checkpoint: You are ready for the next lesson when php -v works and you can see your edited message at localhost:8000/hello.php.