How to Install PHP on Windows (Step-by-Step Guide) | PHP.Exalogics.com
Installing PHP on Windows
Before you can write and run PHP programs, you need a working PHP environment on your computer. Fortunately, installing PHP on Windows has become much easier over the years. Modern development packages allow you to install Apache, PHP, MySQL and other tools with just a few clicks.
This guide explains the different ways to install PHP and recommends the best option depending on your experience level.
Do You Need a Web Server?
Unlike HTML files, PHP programs cannot simply be opened by double-clicking them.
PHP is a server-side scripting language. This means your PHP code must be processed by a web server before the browser can display the final page.
The most common web servers are:
- Apache
- Nginx
- Microsoft IIS
For beginners, Apache is by far the easiest option.
Four Ways to Install PHP
| Method | Difficulty | Recommended |
|---|---|---|
| XAMPP | Easy | ★★★★★ |
| Laragon | Easy | ★★★★★ |
| WAMP | Medium | ★★★★☆ |
| Manual Installation | Advanced | ★★☆☆☆ |
Option 1 – Installing XAMPP
XAMPP is probably the easiest way to begin learning PHP. It includes everything required to build websites locally.
XAMPP includes:
- Apache Web Server
- PHP
- MariaDB/MySQL
- phpMyAdmin
- OpenSSL
- FileZilla FTP Server (optional)
Installation steps:
- Download XAMPP.
- Run the installer.
- Accept the default options.
- Install Apache and MySQL.
- Start the XAMPP Control Panel.
- Click Start beside Apache.
- Open your browser.
- Visit:
http://localhost
If you see the XAMPP welcome page, congratulations! Your web server is working correctly.
Where Should You Save PHP Files?
When using XAMPP, your website files are normally stored inside the following folder:
C:\xampp\htdocs\
Create a folder for your project.
Example:
C:\xampp\htdocs\mywebsite
Your first PHP file might be:
C:\xampp\htdocs\mywebsite\index.php
Your First Test
Create a file named index.php.
Add the following code:
<?php
echo "Welcome to PHP.Exalogics.com";
?>
Open your browser and visit:
http://localhost/mywebsite/
If everything is installed correctly, you should see:
Welcome to PHP.Exalogics.com
Tip:
Always save PHP files using the .php extension.
A file named index.html will not execute PHP code.
Checking Your PHP Version
Create another file named:
phpinfo.php
Add this code:
<?php
phpinfo();
?>
Visit:
http://localhost/mywebsite/phpinfo.php
You should now see a detailed page showing your PHP version, installed extensions, server configuration, and many other technical details.
This page is extremely useful when troubleshooting problems or verifying that PHP has been installed correctly.
Never leave phpinfo() accessible on a public website. It reveals server configuration details that attackers could potentially use.
Alternative: Laragon
Many professional PHP developers prefer Laragon because it is lightweight, extremely fast, and makes creating multiple local projects very easy.
Laragon includes:
- Apache or Nginx
- PHP
- MySQL/MariaDB
- Composer
- Node.js support
- Git integration
If you plan to work with Laravel or multiple websites, Laragon is an excellent choice.
Manual PHP Installation
Although packages such as XAMPP and Laragon are recommended for beginners, it is also possible to install PHP manually. This method gives you more control over your development environment and is commonly used by advanced developers.
Step 1 – Download PHP
Download the latest stable version of PHP for Windows from the official PHP website. Choose the version that matches your operating system (64-bit or 32-bit) and preferred web server.
Step 2 – Extract PHP
Extract the downloaded ZIP file to a folder such as:
C:\php
Step 3 – Configure PHP
Rename the file:
php.ini-development
to:
php.ini
Edit this file whenever you need to enable extensions such as MySQL, GD, ZIP, cURL or OpenSSL.
Installing Visual Studio Code
Visual Studio Code (VS Code) is one of the most popular editors for PHP development.
Useful extensions include:
- PHP Intelephense
- PHP Debug
- PHP Namespace Resolver
- Prettier
- GitLens
- Docker
These extensions provide intelligent code completion, syntax highlighting, debugging tools, formatting, and Git integration.
Installing Composer
Composer is PHP’s dependency manager. It allows you to install third-party libraries and frameworks with a single command.
Many modern PHP applications such as Laravel require Composer.
After installation, verify it by opening Command Prompt:
composer --version
If Composer is installed correctly, the version number will be displayed.
Recommended Folder Structure
Keeping your projects organized makes development much easier.
Projects
│
├── website1
│ ├── index.php
│ ├── css
│ ├── images
│ ├── js
│ └── includes
│
├── website2
│
└── test
Using a consistent folder structure helps when projects become larger.
Common Installation Problems
Apache Won’t Start
The most common reason is that another application is already using port 80.
Programs that commonly use port 80 include:
- Skype (older versions)
- IIS
- VMware
- Docker
- Other web servers
You can either stop the conflicting program or change Apache to use another port such as 8080.
Blank White Page
A blank page usually indicates a PHP error.
Enable error reporting while developing:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
?>
Never leave display_errors enabled on production websites.
PHP Code Appears in Browser
If your browser displays the PHP code instead of executing it, the web server is not processing PHP correctly.
Check:
- Apache is running.
- Your file has a .php extension.
- You opened the file using http://localhost rather than double-clicking it.
Database Connection Failed
Ensure that:
- MySQL or MariaDB is running.
- The username and password are correct.
- The database exists.
- The host is usually localhost.
Professional Tips
Tip #1
Create one folder for every project. Avoid placing dozens of unrelated PHP files directly inside your web root.
Tip #2
Use version control such as Git, even for personal projects. It allows you to track changes and recover older versions of your code.
Tip #3
Back up your work regularly. A simple ZIP archive or Git repository can save hours of work.
Tip #4
Learn to read PHP error messages. They usually tell you exactly where the problem is and can save a lot of debugging time.
Summary
Installing PHP on Windows is easier than ever. Beginners should start with XAMPP or Laragon, both of which include Apache, PHP, MySQL, and other useful development tools. As your skills grow, you may choose to install PHP manually for greater flexibility.
A proper local development environment allows you to build and test websites without uploading every change to a live server. It is faster, safer, and the standard approach used by professional developers.
Frequently Asked Questions
Which package is best for beginners?
XAMPP is an excellent choice because it is simple to install and includes everything needed to begin learning PHP.
Should I choose XAMPP or Laragon?
Both are excellent. XAMPP is easier for beginners, while Laragon is popular with professional developers due to its speed and flexibility.
Do I need an Internet connection to write PHP?
No. Once PHP is installed on your computer, you can develop websites entirely offline.
Can I use Notepad?
Yes, but Visual Studio Code provides a much better development experience with syntax highlighting, code completion, and debugging.
Is localhost visible to other people?
No. A localhost server runs only on your own computer unless you specifically configure it for network access.
Try It Yourself
Create a new folder named practice inside your web server directory.
Create an index.php file and display:
Hello from my first PHP website!
Then modify the message using your own name.
Next Tutorial
Now that PHP is installed, it’s time to write your first real PHP program and learn how PHP code is executed.
Next: Your First PHP Script