How to Install PHP on Windows

If you’re looking to develop with PHP on a Windows system, knowing how to install PHP on Windows is essential for setting up your development environment. Installing PHP on Windows can seem a bit tricky at first, but with the right steps, it’s a straightforward process. In this guide, we’ll walk you through how to install PHP on Windows, including configuration and verification, so you can start coding in PHP smoothly and efficiently. Whether you’re a beginner or an experienced developer, these steps will help you get up and running with PHP in no time.

Prerequisites

  • A Windows machine with administrative access.
  • An internet connection to download PHP and related files.

1: Download PHP

  1. Visit the PHP Website
    Go to the official PHP download page to get the latest stable version of PHP for Windows.
  2. Choose the Thread-Safe Version
    Under the Windows downloads section, select the “Thread Safe” version, as it is recommended for web server usage. Download the ZIP file (e.g., php-8.x.x-Win32-vs16-x64.zip).

2: Extract the PHP Files

  1. Locate the Downloaded File
    Navigate to your downloads folder and locate the ZIP file you downloaded.
  2. Extract PHP to a Folder
    Right-click the ZIP file, select “Extract All,” and choose C:\php as the destination folder. This is the recommended location for easy configuration, but you can use a different path if needed.

3: Configure PHP Environment Variables

To use PHP from the command line, you’ll need to set it in your system’s PATH environment variable.

  1. Open Environment Variables
    • Go to Start, type “Environment Variables,” and select Edit the system environment variables.
    • In the System Properties window, click on Environment Variables.
  2. Add PHP to the Path
    • Under System Variables, find the Path variable and click Edit.
    • Click New and add the path to your PHP folder (e.g., C:\php).
    • Click OK to save and close all windows.

4: Configure php.ini

The php.ini file allows you to configure PHP’s behavior.

  1. Locate the php.ini File
    In the C:\php directory, you’ll see two files: php.ini-development and php.ini-production. Choose one based on your environment:
    • For development, rename php.ini-development to php.ini.
    • For a live server, rename php.ini-production to php.ini.
  2. Edit Key Settings
    Open the php.ini file in a text editor (like Notepad) and set the following parameters:
    • Enable Extensions: Uncomment lines for any extensions you need by removing the semicolon (;) in front of them, e.g., extension=mysqli.
    • Set Timezone: Search for date.timezone and set it to your timezone (e.g., date.timezone = "America/New_York").
  3. Save and Close
    Save the changes and close the file.

5: Verify PHP Installation

  1. Open Command Prompt
    Press Win + R, type cmd, and press Enter to open the command prompt.
  2. Check PHP Version
    Type php -v and press Enter. If PHP is installed correctly, it will display the version and other details.

6: Run a Test PHP Script

Now, let’s ensure PHP is working by creating a simple script.

  1. Create a PHP File
    Open a text editor and type the following PHP code:phpCopy code<?php echo "Hello, PHP is working!"; Save the file as test.php in your C:\php directory or any directory of your choice.
  2. Run the PHP Script from Command Line
    In the command prompt, navigate to the directory where you saved test.php and run:Copy codephp test.php You should see the output: Hello, PHP is working!.

7: Integrate PHP with a Web Server (Optional)

If you want to run PHP scripts via a web server, you can install a local server like Apache or Nginx.

Option A: Install XAMPP or WAMP (Recommended for Beginners)

  • XAMPP and WAMP are all-in-one packages that include Apache, PHP, and MySQL.
  • Download and install one of these packages, and it will automatically configure PHP with Apache.

Option B: Manual Apache Configuration (Advanced Users)

Restart Apache, and PHP should be configured to work with your server.

Download and install Apache.

Open Apache’s httpd.conf file and add the following lines to configure PHP:apacheCopy code# Add to the end of httpd.conf LoadModule php_module "C:/php/php8apache2_4.dll" AddHandler application/x-httpd-php .php PHPIniDir "C:/php"

Conclusion

And there you have it! You’re now ready to start learning PHP and build interactive web pages on your Windows machine. For more in-depth tutorials, don’t hesitate to visit Newtum. Dive deeper, experiment, and happy coding!

Edited and Compiled by

This blog was compiled and edited by Rasika Deshpande, who has over 4 years of experience in content creation. She’s passionate about helping beginners understand technical topics in a more interactive way.

About The Author