PHP executes on a server or in a terminal. Opening a PHP file directly in a browser does not execute its PHP code. Use the built-in server for local practice.
What you need
- A supported PHP command-line installation
- A code editor and terminal
- A browser
Set up your environment
- Follow the PHP installation instructions for your operating system and ensure the PHP executable is available in your terminal.
- Run
php --version. Create a folder namedphp-practiceand save the example asindex.php. - Open a terminal in that folder and start the local server with the command below.
- Visit
http://127.0.0.1:8000/. Keep the terminal open while using the server and stop it with Ctrl+C.
Your first check
Save as index.php
<?php
$message = 'Hello from w1coding.com';
echo '<h1>' . htmlspecialchars($message, ENT_QUOTES, 'UTF-8') . '</h1>';Run or verify
php -S 127.0.0.1:8000Expected result: The browser displays Hello from w1coding.com as a heading.
Common setup problems
- If the port is occupied, use another local port, such as 8001, in both the command and browser address.
- The built-in server is for development. Do not expose it as a public production server.
Official documentation
Guide reviewed 17 November 2026. Check the linked vendor documentation for current supported versions and operating systems.