How to Install PHP on Windows and Set Up a Local Development Server
Last update: 12-19-2024
If you're a developer looking to set up PHP on Windows without the overhead of tools like XAMPP, you're in the right place. This guide will walk you through downloading PHP directly and creating a local development server using the php -S
command.
Step 1: Download and Set Up PHP
- Visit the official PHP for Windows download page.
- Under the "Downloads" section, choose the latest stable version of PHP. For most users, the "Thread Safe" version is recommended.
- Download the zip file appropriate for your system (e.g., x64 if you're using a 64-bit version of Windows).
-
After downloading, right-click on the zip file and select "Extract All." Once extracted, move the folder to your
C:\
drive and rename it to something likePHP8.4
to indicate the version.
Step 2: Add PHP to Your System Path
- Open the Start Menu and search for "Environment Variables."
- Click "Edit the system environment variables."
- In the System Properties window, click "Environment Variables."
- Under "System Variables," find the
Path
variable and click "Edit." - Click "New" and add the path to your PHP folder (e.g.,
C:\PHP8.4
). - Click "OK" to save the changes.
Step 3: Verify Your Installation
Open Command Prompt and type:
php -v
If PHP is installed correctly, you'll see the PHP version and additional information. If you receive no response or encounter issues, it might be due to:
- Microsoft Defender SmartScreen blocking PHP: To check, open the PHP executable file (
php.exe
) directly from File Explorer. If it's blocked, you'll see a blue warning message. Click "More Info," then "Run Anyway" to allow PHP to run. - Missing C++ Redistributables: If you see the error message
The code execution cannot proceed because VCRUNTIME140.dll was not found
, you need to install the Microsoft C++ Redistributables:- Download vc_redist.x64.exe (for 64-bit systems)
Running php.exe
directly from File Explorer can help you pinpoint whether the issue is related to SmartScreen blocking it or the missing redistributables. You might need to address both issues to proceed.
Step 4: Create and Test Your PHP Application
- Create a new empty folder for your PHP project.
- Install Visual Studio Code if you haven’t already by downloading it from code.visualstudio.com/download.
- Open VS Code and use it to open the empty folder you just created.
- Create a new file named
index.php
and add the following code:<?php phpinfo(); ?>
- Open the built-in terminal in VS Code by pressing
Ctrl + `
(backtick). - Run the following command to start the built-in PHP server:
php -S localhost:8000
- Open your browser and go to http://localhost:8000 to view the output of your PHP application.
Conclusion
With PHP installed and your local development server running, you're ready to start building PHP applications. This lightweight setup is ideal for small projects and quick testing. Happy coding!