How to Install PHP on Windows: Step-by-Step Guide
To install
PHP on Windows, download the latest PHP zip package from the official website, extract it to a folder, and add its path to the system PATH environment variable. Then, verify the installation by running php -v in the Command Prompt.Syntax
Installing PHP on Windows involves these main steps:
- Download: Get the PHP zip package from the official site.
- Extract: Unzip the files to a folder like
C:\php. - Configure PATH: Add the PHP folder path to the system environment variable
PATHso Windows can find PHP. - Verify: Run
php -vin Command Prompt to check the version and confirm installation.
bash
php -v
Output
PHP 8.2.6 (cli) (built: May 4 2024 12:00:00) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
Example
This example shows how to check if PHP is installed correctly by running the version command in Command Prompt.
bash
php -v
Output
PHP 8.2.6 (cli) (built: May 4 2024 12:00:00) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
Common Pitfalls
Common mistakes when installing PHP on Windows include:
- Not adding the PHP folder to the
PATHenvironment variable, causingphpcommands to fail. - Downloading the wrong PHP version (thread safe vs non-thread safe) for your setup.
- Forgetting to restart Command Prompt after changing environment variables.
- Not configuring
php.iniif needed for extensions or settings.
batch
REM Wrong way: Trying to run php without PATH set
php -v
REM Right way: Add PHP folder to PATH and restart terminal
setx PATH "%PATH%;C:\php"Output
php is not recognized as an internal or external command, operable program or batch file.
Environment variable updated. Please restart your terminal.
Quick Reference
| Step | Description |
|---|---|
| Download PHP | Get the latest zip from https://windows.php.net/download/ |
| Extract Files | Unzip to a folder like C:\php |
| Set PATH | Add C:\php to system PATH environment variable |
| Verify Installation | Run php -v in Command Prompt |
| Configure php.ini | Copy php.ini-development to php.ini and edit if needed |
Key Takeaways
Download the official PHP zip package for Windows from the PHP website.
Extract PHP files to a folder and add that folder to your system PATH.
Restart Command Prompt after updating PATH to recognize PHP commands.
Verify installation by running php -v to see the PHP version.
Configure php.ini for custom settings if your projects require it.