devnotes.

Installing PHP and Your First Script

To run PHP locally you need the PHP interpreter installed. Options include:

  • XAMPP / MAMP / WAMP — bundle PHP, Apache, and MySQL together; beginner-friendly, one installer.
  • Native install — on macOS: brew install php; on Ubuntu/Debian: sudo apt install php; on Windows, download binaries from windows.php.net.
  • Docker — docker run -p 8000:80 -v $(pwd):/var/www/html php:8.5-apache for a clean, disposable environment.

Check your installed version:

php -v

PHP code is embedded inside <?php ... ?> tags, usually saved in a .php file. A minimal script:

<?php
echo "Hello, World!";

Run it with PHP's built-in development server, no Apache/Nginx required:

php -S localhost:8000

Then visit http://localhost:8000/yourfile.php in a browser. You can also run a script directly from the command line with php yourfile.php, which is handy for scripts, cron jobs, and CLI tools.

Comments in PHP: // single line, # also single line, and /* multi line */.

Install PHP and Write Your First Script | DevNotes