To run PHP scripts on your computer, you need the PHP command-line interpreter (php) and a local server tool. You do not need a heavy stack to start because PHP includes a built-in development server.
Pick the lightweight option that matches your operating system and workflow.
flowchart TD
A["Select Your OS"] --> B["Windows: Laragon, XAMPP, or WinGet"]
A --> C["macOS: Homebrew or Laravel Herd"]
A --> D["Linux: APT or DNF Package Manager"]
B --> E["Verify with php -v"]
C --> E
D --> E
E --> F["Start Server: php -S localhost:8000"]
On Windows, tools like Laravel Herd or Laragon configure PHP and Composer automatically. On macOS, Homebrew installs the latest PHP 8 release with one command. On Ubuntu or Debian Linux, install php-cli along with database and string extensions.
php -v
Run php -v in your terminal after installation. You should see PHP 8.2, 8.3, or 8.4 printed along with Zend Engine details.
Create a project folder with an index.php file, open your terminal inside that folder, and launch the local server on port 8000.
php -S localhost:8000
Now visit http://localhost:8000 in your browser. PHP executes index.php on every request and prints errors directly to your terminal window for fast debugging.
<?php
declare(strict_types=1);
echo "PHP Version: " . PHP_VERSION . PHP_EOL;
echo "Loaded php.ini: " . (php_ini_loaded_file() ?: 'None') . PHP_EOL;
echo "PDO MySQL Enabled: " . (extension_loaded('pdo_mysql') ? 'Yes' : 'No') . PHP_EOL;
php -S is single-threaded and built only for local development. Use Nginx with PHP-FPM or Apache in production.PATH: Windows and macOS terminals cache environment paths until you open a new shell session.mbstring or pdo_mysql extensions: Enable required extensions in php.ini before installing packages with Composer.No. PHP includes a built-in server via php -S localhost:8000 that handles local HTML and PHP files without extra web server configuration.
php.ini configuration file located?Run php --ini in your terminal to print the exact folder and filename of the active php.ini configuration file on your machine.
Always install PHP 8.2 or newer. PHP 7 reached end-of-life and no longer receives security updates or modern language features.
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.