
```html
How to Install PHP on a Windows Machine?
PHP is a popular server-side scripting language used to create dynamic websites, web applications, APIs, content management systems, and database-driven applications. If you want to learn PHP development on a Windows computer, one of the first steps is installing PHP and configuring your system so that PHP programs can be executed locally.
There are several ways to install PHP on Windows. You can install PHP manually, use a complete development package such as XAMPP, or use another local development environment. For beginners who want to understand how PHP itself works, manually installing PHP is a useful approach because it introduces important concepts such as the PHP executable, configuration file, extensions, and Windows PATH environment variable.
This guide explains how to install PHP manually on Windows, configure it, verify the installation, and run your first PHP program from the command line.
What You Need Before Installing PHP
Before starting the installation, make sure you have:
You should also determine whether your Windows installation is 64-bit or 32-bit so that you can choose an appropriate PHP build when applicable.
Step 1: Check Your Windows System Type
Before downloading PHP, check your Windows system information.
On most modern computers, you will see something similar to:
64-bit operating system, x64-based processorChoose a PHP build that is compatible with your operating system and development requirements.
Step 2: Download PHP for Windows
Download PHP from the official PHP for Windows distribution website.
Official PHP for Windows downloads:
https://windows.php.net/download/
You will normally see multiple PHP versions and build options. For a new development environment, select a currently supported PHP release that is compatible with the software, libraries, and frameworks you plan to use.
Understanding Thread Safe and Non Thread Safe
Windows PHP downloads may include Thread Safe (TS) and Non Thread Safe (NTS) builds.
| Build | Description | Typical Use |
|---|---|---|
| Thread Safe (TS) | Includes thread-safety support. | Commonly used when PHP is loaded as an Apache module. |
| Non Thread Safe (NTS) | Does not include thread-safety support. | Commonly used with FastCGI-based environments such as IIS. |
If you are installing PHP primarily to learn the language and run PHP from the command line, either build may work for CLI use, but your eventual web-server configuration should determine the appropriate choice.
Step 3: Download the ZIP Package
PHP for Windows is commonly distributed as a ZIP archive.
Download the appropriate ZIP package for your system. The downloaded filename will vary according to the PHP version, architecture, and build type.
For example, it may resemble:
php-x.x.x-Win32-vsXX-x64.zipThe exact filename changes as new PHP releases and toolchains become available.
Step 4: Extract PHP
After downloading the ZIP archive:
A simple location is:
C:\phpAfter extraction, the directory should contain files and folders similar to:
C:\php\
php.exe
php-cgi.exe
php.ini-development
php.ini-production
ext\
...The exact files may vary between PHP releases.
Step 5: Install the Required Microsoft Visual C++ Runtime
PHP builds for Windows may depend on the Microsoft Visual C++ Redistributable runtime used to build that PHP release. Check the requirements listed on the PHP for Windows download page for the version you downloaded.
If the required runtime is missing, PHP may fail to start or display an error about a missing DLL.
Download required Microsoft runtime components only from official Microsoft sources.
Step 6: Create the php.ini Configuration File
PHP uses a configuration file named:
php.iniAfter extracting PHP, you will typically find template configuration files such as:
php.ini-development
php.ini-productionFor a local development computer, you can start by making a copy of:
php.ini-developmentRename the copied file to:
php.iniYour PHP directory should then contain:
C:\php\php.iniThe development configuration is intended to provide settings that are more convenient during development. Production servers should use appropriately hardened production configuration instead.
Step 7: Configure the PHP Extension Directory
Open php.ini in a text editor and locate the extension directory configuration.
Depending on the supplied configuration template, you may find a line similar to:
;extension_dir = "ext"Remove the semicolon if necessary so the setting becomes active:
extension_dir = "ext"The semicolon at the beginning of a PHP configuration line generally indicates that the line is commented out.
Step 8: Enable Required PHP Extensions
PHP extensions add additional functionality to the language. The extensions you need depend on the applications you plan to develop.
Common extensions may include:
Other applications may require extensions such as:
In php.ini, an extension configuration may appear similar to:
;extension=curl
;extension=mbstring
;extension=mysqli
;extension=openssl
;extension=pdo_mysqlTo enable an extension, remove the leading semicolon when the extension and required dependencies are available:
extension=curl
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysqlDo not enable every extension simply because it exists. Enable the extensions required by your application and verify their configuration.
Step 9: Add PHP to the Windows PATH
Adding PHP to the Windows PATH environment variable allows you to run the php command from Command Prompt or PowerShell without entering the complete path to php.exe.
For example, instead of:
C:\php\php.exe -vYou can simply use:
php -vTo add PHP to PATH:
For example:
C:\phpClick OK to save the changes.
Close any existing Command Prompt or PowerShell windows and open a new one so the updated environment variable can be loaded.
Step 10: Verify the PHP Installation
Open Command Prompt or PowerShell and enter:
php -vIf PHP is installed correctly, information about the installed PHP version and build will appear.
The exact output depends on the version installed.
Step 11: Check Which php.ini File PHP is Using
When multiple PHP installations exist on the same computer, it is important to confirm which configuration file is being loaded.
Run:
php --iniThis command displays information including the loaded configuration file.
You should see your configured php.ini path if everything is set up correctly.
Step 12: Check the PHP Executable Location
If you have installed PHP previously, Windows may find a different PHP executable first.
In Command Prompt, run:
where phpThis shows the PHP executable paths found through your current PATH configuration.
If multiple results appear, verify that the correct PHP installation appears first in PATH.
Step 13: Check Enabled PHP Extensions
To display the extensions currently loaded by PHP, run:
php -mThe output lists active PHP modules.
You can use this command to verify whether extensions such as mysqli, curl, or mbstring loaded successfully.
Step 14: Create Your First PHP Program
Create a folder for your PHP projects.
For example:
C:\php-projectsCreate a new file named:
hello.phpAdd the following code:
<?php
echo "Hello from PHP!";
?>Save the file.
Step 15: Run Your PHP Program from the Command Line
Open Command Prompt and navigate to the project directory:
cd C:\php-projectsThen run:
php hello.phpYou should see:
Hello from PHP!Congratulations! PHP is now running successfully from the Windows command line.
Step 16: Run PHP Using the Built-in Development Server
PHP includes a built-in web server intended for development and testing.
Navigate to your project folder:
cd C:\php-projectsStart the development server:
php -S localhost:8000Then open the following address in your web browser:
http://localhost:8000/hello.phpYou should see:
Hello from PHP!The PHP built-in server is convenient for local development and testing. It is not intended to replace a properly configured production web server.
Create a PHP Information Page
PHP provides the phpinfo() function for displaying detailed information about the current PHP environment.
Create a file named:
info.phpAdd:
<?php
phpinfo();
?>With the local development server running, open:
http://localhost:8000/info.phpThe page can display information about:
Security Note: A phpinfo page can reveal detailed server configuration. Do not leave such a page publicly accessible on a production website.
Installing PHP Using XAMPP
If you don't want to configure PHP manually, XAMPP provides a convenient development package that includes several components commonly used for local PHP development.
A typical XAMPP installation includes:
The basic process is:
XAMPP can be convenient for beginners because it provides several web-development components in one package.
Manual PHP Installation vs. XAMPP
| Feature | Manual PHP Installation | XAMPP |
|---|---|---|
| PHP | Yes | Yes |
| Apache | Install separately if required | Included |
| Database Server | Install separately | Included |
| phpMyAdmin | Install separately | Included |
| Initial Setup | More configuration | Generally easier |
| Configuration Control | High | Preconfigured development stack |
| Learning PHP Internals | Very useful | More automated |
Which Installation Method Should Beginners Use?
If your primary goal is to start creating PHP and MySQL websites quickly, a local development package such as XAMPP can simplify the initial setup.
If you want to understand PHP configuration more deeply, manually installing PHP is an excellent learning exercise.
Both approaches can be useful depending on your goal.
Common Installation Problems
You may encounter a few common issues while installing PHP on Windows.
Problem: 'php' is not recognized
You may see an error similar to:
'php' is not recognized as an internal or external commandPossible causes include:
Verify that your PHP directory, such as:
C:\phpis included in PATH, then reopen your terminal.
Problem: Missing DLL Error
If PHP reports that a required DLL cannot be found, verify that:
Problem: Extension Not Loading
If an extension doesn't appear when running:
php -mCheck:
Use:
php --inito verify which configuration file PHP is loading.
Problem: Wrong PHP Version Appears
If:
php -vshows a different version from the one you installed, run:
where phpYou may have multiple PHP installations configured in PATH. Reorder or remove outdated PATH entries as appropriate.
Useful PHP Commands
| Command | Purpose |
|---|---|
php -v | Display the installed PHP version. |
php -m | List loaded PHP modules. |
php --ini | Display PHP configuration file information. |
php -i | Display detailed PHP configuration information. |
php -r "echo 'Hello';" | Execute PHP code directly from the command line. |
php filename.php | Execute a PHP script. |
php -S localhost:8000 | Start PHP's built-in development web server. |
where php | Show PHP executables found through Windows PATH. |
Recommended Folder Structure for Learning PHP
You can organize your practice projects in a dedicated folder:
C:\php-projects\
hello-world\
index.php
variables\
index.php
forms\
index.php
process.php
database\
index.php
practice-project\
index.phpKeeping projects organized makes it easier to progress from basic PHP syntax to complete applications.
What Should You Learn After Installing PHP?
Once PHP is running successfully, you can begin learning the language in a structured order:
Best Practices
php -v, php --ini, and php -m to verify your configuration.phpinfo() on a public production website.Quick Installation Checklist
C:\php.php.ini.php -v.php --ini.php -m.Conclusion
Installing PHP on Windows is the first practical step toward creating dynamic websites and web applications with PHP. A manual installation gives you greater insight into how PHP itself is configured, including the PHP executable, php.ini, extensions, and Windows PATH. Alternatively, development packages such as XAMPP provide a convenient way to install a complete local web-development environment.
Once PHP is installed, verify the setup using commands such as php -v, php --ini, and php -m, then create a simple PHP file and run it from both the command line and a local development server. With your development environment working correctly, you can move on to PHP syntax, forms, databases, sessions, object-oriented programming, security, Composer, MVC, and eventually complete web applications.