Loading...

How to insatall PHP on Windows machine?

How to insatall PHP on Windows machine?
  • study365days.in

```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:

  • A Windows computer.
  • Administrator access when system settings need to be changed.
  • An internet connection to download PHP and required components.
  • A web browser.
  • A text editor or development environment such as Visual Studio Code.

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.

  1. Press Windows + I to open Settings.
  2. Open System.
  3. Select About.
  4. Look for System type.

On most modern computers, you will see something similar to:

64-bit operating system, x64-based processor

Choose 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.

BuildDescriptionTypical 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.zip

The exact filename changes as new PHP releases and toolchains become available.

Step 4: Extract PHP

After downloading the ZIP archive:

  1. Open File Explorer.
  2. Locate the downloaded PHP ZIP file.
  3. Right-click it.
  4. Select Extract All.
  5. Extract the files to a permanent folder.

A simple location is:

C:\php

After 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.ini

After extracting PHP, you will typically find template configuration files such as:

php.ini-development
php.ini-production

For a local development computer, you can start by making a copy of:

php.ini-development

Rename the copied file to:

php.ini

Your PHP directory should then contain:

C:\php\php.ini

The 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:

  • curl
  • mbstring
  • mysqli
  • openssl
  • pdo_mysql

Other applications may require extensions such as:

  • fileinfo
  • gd
  • intl
  • zip

In php.ini, an extension configuration may appear similar to:

;extension=curl
;extension=mbstring
;extension=mysqli
;extension=openssl
;extension=pdo_mysql

To 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_mysql

Do 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 -v

You can simply use:

php -v

To add PHP to PATH:

  1. Open the Windows search box.
  2. Search for Environment Variables.
  3. Open Edit the system environment variables.
  4. Click Environment Variables.
  5. Select the appropriate Path variable.
  6. Click Edit.
  7. Click New.
  8. Add your PHP directory.

For example:

C:\php

Click 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 -v

If 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 --ini

This 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 php

This 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 -m

The 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-projects

Create a new file named:

hello.php

Add 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-projects

Then run:

php hello.php

You 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-projects

Start the development server:

php -S localhost:8000

Then open the following address in your web browser:

http://localhost:8000/hello.php

You 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.php

Add:

<?php
phpinfo();
?>

With the local development server running, open:

http://localhost:8000/info.php

The page can display information about:

  • PHP version.
  • Loaded configuration.
  • Enabled extensions.
  • Environment information.
  • PHP configuration values.

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:

  • Apache.
  • PHP.
  • MariaDB.
  • phpMyAdmin.

The basic process is:

  1. Download XAMPP from the official Apache Friends website.
  2. Run the installer.
  3. Select the required components.
  4. Complete the installation.
  5. Open the XAMPP Control Panel.
  6. Start Apache.
  7. Start the database service when your project requires it.

XAMPP can be convenient for beginners because it provides several web-development components in one package.

Manual PHP Installation vs. XAMPP

FeatureManual PHP InstallationXAMPP
PHPYesYes
ApacheInstall separately if requiredIncluded
Database ServerInstall separatelyIncluded
phpMyAdminInstall separatelyIncluded
Initial SetupMore configurationGenerally easier
Configuration ControlHighPreconfigured development stack
Learning PHP InternalsVery usefulMore 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 command

Possible causes include:

  • The PHP directory has not been added to PATH.
  • The terminal was opened before PATH was updated.
  • The PATH entry points to the wrong directory.

Verify that your PHP directory, such as:

C:\php

is included in PATH, then reopen your terminal.

Problem: Missing DLL Error

If PHP reports that a required DLL cannot be found, verify that:

  • The correct PHP build was downloaded.
  • The required Microsoft Visual C++ runtime is installed.
  • Required extension dependencies are available.
  • Your PHP installation files are complete.

Problem: Extension Not Loading

If an extension doesn't appear when running:

php -m

Check:

  • The extension is enabled in the correct php.ini.
  • The extension file exists in the extension directory.
  • The extension_dir setting is correct.
  • Any DLL dependencies required by the extension are available.

Use:

php --ini

to verify which configuration file PHP is loading.

Problem: Wrong PHP Version Appears

If:

php -v

shows a different version from the one you installed, run:

where php

You may have multiple PHP installations configured in PATH. Reorder or remove outdated PATH entries as appropriate.

Useful PHP Commands

CommandPurpose
php -vDisplay the installed PHP version.
php -mList loaded PHP modules.
php --iniDisplay PHP configuration file information.
php -iDisplay detailed PHP configuration information.
php -r "echo 'Hello';"Execute PHP code directly from the command line.
php filename.phpExecute a PHP script.
php -S localhost:8000Start PHP's built-in development web server.
where phpShow 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.php

Keeping 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:

  1. PHP syntax.
  2. Variables and constants.
  3. Data types.
  4. Operators.
  5. Conditional statements.
  6. Loops.
  7. Arrays.
  8. Functions.
  9. HTML forms.
  10. GET and POST requests.
  11. Sessions and cookies.
  12. File handling.
  13. MySQL database integration.
  14. PDO and prepared statements.
  15. Object-oriented PHP.
  16. Composer and third-party packages.
  17. MVC architecture.
  18. PHP frameworks.

Best Practices

  • Download PHP from trusted official sources.
  • Use a currently supported PHP release that meets your project's compatibility requirements.
  • Keep development and production configurations separate.
  • Enable only the PHP extensions your applications require.
  • Add the correct PHP directory to Windows PATH.
  • Use php -v, php --ini, and php -m to verify your configuration.
  • Keep PHP and its dependencies updated.
  • Never expose development diagnostic pages such as phpinfo() on a public production website.
  • Use PHP's built-in server only for development and testing.

Quick Installation Checklist

  • Check whether Windows is 64-bit or 32-bit.
  • Download the appropriate PHP build.
  • Extract PHP to a permanent directory such as C:\php.
  • Install the required Microsoft runtime if necessary.
  • Create and configure php.ini.
  • Enable the PHP extensions required for your projects.
  • Add the PHP directory to Windows PATH.
  • Open a new terminal.
  • Run php -v.
  • Check the configuration with php --ini.
  • Check extensions with php -m.
  • Create and run your first PHP script.
  • Test the script using PHP's built-in development server.

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.