Lesson

PHP Install

10 min reading
Free Course

PHP Install: Setting Up Your Local PHP 8 Environment

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.

Choosing a Local PHP Setup

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.

Running the Built-In PHP Development Server

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;

Common Mistakes to Avoid

  • Using the built-in server in production: php -S is single-threaded and built only for local development. Use Nginx with PHP-FPM or Apache in production.
  • Forgetting to restart the terminal after editing PATH: Windows and macOS terminals cache environment paths until you open a new shell session.
  • Missing mbstring or pdo_mysql extensions: Enable required extensions in php.ini before installing packages with Composer.

Frequently Asked Questions

Do I need Apache or Nginx just to learn PHP?

No. PHP includes a built-in server via php -S localhost:8000 that handles local HTML and PHP files without extra web server configuration.

Where is the 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.

Should I install PHP 7 or PHP 8?

Always install PHP 8.2 or newer. PHP 7 reached end-of-life and no longer receives security updates or modern language features.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
PHP Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum