start here

Start Here

php -v

If the command prints a PHP version, continue. If the terminal says that php is missing, install PHP for your operating system before moving on. The official PHP installation guide covers the supported installation paths. Track 06 returns to setup in depth and explains extensions, configuration files, the local web server, and runtime differences.

Create a new folder for your course scripts and open a terminal in that folder. Add a file named first.php:

PHP example
<?php

echo "My first PHP script\n";

// Prints:
// My first PHP script

Run the file:

php first.php

PHP reads the file and executes the instruction. When you change the quoted text and run the command again, the output should change too.

When The Wrong Output Appears

If your change does not appear:

  1. Check that the terminal is in the folder containing the file.
  2. Check the filename in the command.
  3. Save the file before rerunning it.
  4. Read any error message from the top.

This edit-run-check loop is the basis of the early course. Keep the first scripts small enough that you can understand every line.

What To Keep Nearby

Use an editor that shows plain text files and a terminal where you can run commands. Keep each early exercise in its own file so you can rerun an older example when a new concept is confusing.

For now, the only command you need is:

php filename.php

The next lessons explain the language one step at a time. The runtime track later explains why the same PHP project can behave differently in a terminal, a browser, and production.

Practice

Run Your First Script

Create first.php, print PHP is ready, and run the file from the terminal.

Show solution
PHP example
<?php

echo "PHP is ready\n";

// Prints:
// PHP is ready

Run it with php first.php.

Diagnose The Wrong Output

You edited first.php, but running php test.php still prints an old message. Explain the mistake and the fix.

Show solution
php first.php
Change And Rerun

Change the first-script message to I changed the file, save it, and rerun the script.

Show solution
PHP example
<?php

echo "I changed the file\n";

// Prints:
// I changed the file

Run php first.php again. The changed output proves you are editing and running the same file.