Setting Up PHP
Installing PHP locally and running the built-in development server.
2 min read
Unlike HTML or CSS, PHP code can't just be opened as a file in a browser — it needs a PHP runtime to actually execute it first.
Installing PHP
PHP is available for every major operating system:
- macOS — usually easiest via Homebrew:
brew install php. - Windows — download from windows.php.net or install via a bundle like XAMPP/Laragon, which also includes a local database.
- Linux — available through your distribution's package manager, e.g.
apt install php.
Confirm it installed correctly:
php --versionThe built-in development server
PHP ships with a simple server built in, meant for local development only (never for production):
php -S localhost:8000Run this inside a folder containing your .php files, then visit http://localhost:8000 in a browser. Any .php file in that directory is executed on request — no separate web server (like Apache or Nginx) needed just to get started.
A first project structure
my-project/
index.php
about.php
<!-- index.php -->
<?php
echo "<h1>Home Page</h1>";Visiting http://localhost:8000/index.php (or just http://localhost:8000/, since index.php is the default file most servers look for) runs that script and displays its output.
Composer: PHP's package manager
Modern PHP development relies heavily on Composer, which manages third-party libraries (and is required by every major framework, including Laravel and Symfony):
composer --versionInstall it from getcomposer.org if the command isn't found. You won't need it for pure syntax practice early in this course, but every framework covered later assumes it's available.
Checking your setup works
<?php
phpinfo();Running a file containing just phpinfo() prints a detailed page showing your installed PHP version, loaded extensions, and configuration — the standard way to confirm PHP is working and see exactly what's available in your environment. Remove or protect this file before ever deploying anywhere public: it reveals configuration details you don't want exposed to visitors.
Test what you just learned
4 quick questions. Get all of them right to unlock the next lesson.
You can take the quiz without an account — logging in just lets your result count toward your progress.