Codectionary / Developer documentation / PHP

Install a supported PHP command-line release from the official Windows binaries, set PATH, check php.ini and run a first script in PowerShell.

Choose PHP itself or a development bundle

For a first PHP script, the simplest path is an official PHP Windows ZIP and PowerShell. It gives you the PHP command-line interpreter without installing Apache or a database. Check the current supported-versions page and select a stable, patched release rather than a preview or an end-of-life branch.

XAMPP is an optional Apache Friends bundle containing Apache, MariaDB, PHP and other tools. It can be convenient for a local web stack, but it is not required to learn PHP or run php hello.php. Check the PHP version bundled with any installer against current support and patch releases before choosing it; a convenient bundle can lag behind PHP security updates. Do not expose a local learning server to the public internet.

Download the right official Windows build

Open the official PHP Windows downloads page, choose a current stable branch and download the ZIP archive rather than a source, debug-pack or development-package archive. For a typical 64-bit Windows machine, choose x64 Non Thread Safe (NTS) for command-line work or FastCGI. Thread Safe (TS) is for cases such as loading PHP as an Apache module. Match the archive to the architecture and server integration you actually intend to use; an editor alone does not determine TS versus NTS.

The official prebuilt Windows binaries are x86 or x64, with no native Windows-on-ARM build listed in PHP’s manual. Check Settings → System → About if you are unsure of your device architecture. Extract the ZIP to a stable folder, for example C:\php, rather than leaving it in Downloads. The archive contains php.exe; the ZIP is not a graphical installer and does not add itself to PATH.

PHP’s Windows builds require a matching Microsoft Visual C++ Redistributable. If it is missing, install the current supported redistributable from Microsoft, selecting x64 for an x64 PHP build or x86 for an x86 build. Avoid third-party DLL download sites.

  1. Check your Windows architecture and PHP’s live supported-versions table.
  2. Download a stable Windows ZIP from the official PHP downloads page; for ordinary x64 CLI use, select x64 NTS.
  3. Extract it to a permanent folder such as C:\php and install the matching Microsoft Visual C++ Redistributable if needed.

Test the executable before editing PATH

Open PowerShell and run the executable by its full path. The call operator (&) tells PowerShell to execute the quoted path. If you extracted PHP elsewhere, replace C:\php with your actual folder. A version line means the executable starts; this does not yet prove every optional extension is available.

PowerShell — check the extracted PHP executable

& 'C:\php\php.exe' -v

Add PHP to your user PATH

To type php from any project folder, open Windows Environment Variables, edit your user Path variable, and add the folder containing php.exe, for example C:\php. Add a new entry; do not replace the existing Path. The user Path works for your account without changing the system-wide Path; administrators can choose a system Path entry when all users need PHP. Close and reopen PowerShell so it reads the changed environment, then run the commands below.

php -v prints the command-line PHP version. Get-Command php -All reveals every php command PowerShell can find, useful if XAMPP or another installation takes precedence. If the result points to a different folder, adjust your user Path order or use the desired full executable path. php --ini shows the configuration file loaded by this CLI process.

PowerShell — find the PHP command

Get-Command php -All

PowerShell — verify the version

php -v

PowerShell — inspect the CLI configuration

php --ini

Understand php.ini without guessing its location

php.ini controls settings such as enabled extensions, error reporting and time zones. The official ZIP includes development and production example configuration files. PHP can run a basic CLI script even when no php.ini is loaded. If you need configuration, copy the development template to php.ini in the directory PHP checks, then edit only the settings you understand; keep the original template as a reference. php --ini tells you the actual loaded file and additional scanned files. Do not overwrite an existing php.ini without checking it.

CLI, IIS, Apache or other server integrations can use different configuration files. A php.ini edit for one execution environment may not affect another; restart a long-running web service when its configuration changes.

Run your first PHP file in PowerShell

Create a folder for a small project, save the example below as hello.php, and run it from that folder. The terminal prints “Hello, Codectionary!” on one line. The <?php tag begins PHP code; echo writes output and \n adds a newline. PowerShell does not execute the PHP source itself: it starts php.exe, which reads the file.

If you use an editor, save as plain text with the .php extension, not hello.php.txt. Opening the file directly in a browser will not run it. A web page needs a locally configured PHP-capable server; see How PHP Works before trying that workflow.

PowerShell — create and enter a project folder

New-Item -ItemType Directory -Path .\php-first -Force
Set-Location .\php-first

PowerShell — after saving hello.php

php .\hello.php

Fix common Windows setup problems

“php is not recognized” means PowerShell cannot find php.exe: test its full path, check the user Path entry, and open a new terminal. If the version is unexpected, use Get-Command php -All to find duplicate installations. A missing VCRUNTIME or MSVCP DLL usually points to a missing or mismatched Microsoft Visual C++ Redistributable; install the official package matching the PHP binary architecture.

If php --ini says no configuration file is loaded, PHP can still run simple scripts; create a php.ini from the supplied development template only when settings are needed. “Unable to load dynamic library” can mean an extension is unavailable, the extension path is wrong, or its dependencies are missing. Check php --ini and php -m before changing settings. If a downloaded bundle contains an old PHP branch or patch, update to a maintained build rather than working around version-related errors.

PowerShell — list loaded PHP extensions

php -m

Syntax

<?php
echo "Hello, Codectionary!\n";

Examples

First Windows command-line script

Save as hello.php and run php .\hello.php in PowerShell.

<?php
echo "Hello, Codectionary!\n";
  1. The opening tag marks the PHP code. The quoted text is a string, and \n adds the final line break.
  2. echo sends that string to standard output. PowerShell displays Hello, Codectionary! when php.exe executes the file.
  3. Change the message and run the same command again to confirm you are editing the file PHP is reading.

Best practices

  • Download PHP and required runtime libraries from the official PHP and Microsoft sites.
  • Use a supported, patched PHP release; inspect a development bundle’s actual bundled version before relying on it.
  • Add the PHP directory to your existing user Path instead of replacing Path or changing system-wide settings unnecessarily.

Runtime & versions

PHP runtime on a server or CLI. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

PHP Manual

Specifications & further reading