To execute PHP code on your local computer, you need the PHP CLI executable and optionally a local web server environment (such as XAMPP, Herd, Docker, or native PHP CLI development server).
Developers choose local PHP runtime environments based on OS and workflow complexity:
flowchart TD
A["Choose Local Environment"] --> B["PHP CLI Native (Lightweight)"]
A --> C["Laravel Herd / Valet (macOS / Windows)"]
A --> D["XAMPP / MAMP (All-in-One GUI)"]
A --> E["Docker Container (Production Parity)"]
B --> F["Run 'php -S localhost:8000'"]
C --> F
D --> F
E --> F
# Using Chocolatey Package Manager
choco install php
# Or verify existing PHP version in terminal
php -v
sudo apt update
sudo apt install php-cli php-mbstring php-xml php-curl php-mysql
brew install php
You can run a local development web server instantly without configuring Apache or Nginx:
# Navigate to project directory containing index.php
cd /path/to/project
# Start local server on port 8000
php -S localhost:8000
index.php)<?php
// Verify PHP installation & display environment runtime configuration
echo "PHP Version: " . phpversion() . "
";
echo "Loaded Configuration File: " . php_ini_loaded_file() . "
";
?>
pdo_mysql, mbstring, openssl, and curl are enabled in php.ini.php -S for Quick Local Testing: The built-in dev server is ideal for testing static & dynamic PHP scripts before staging deployments.display_errors = On in Development: Enable error reporting in development php.ini to catch syntax and runtime bugs immediately.Open your terminal or command prompt, type php -v, and write a script info.php that prints out the current PHP version using phpversion()!
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.