Installing PHP in Windows Using XAMPP
XAMPP is a free and open-source software package that includes Apache, MySQL, PHP, and Perl, making it easy to set up a local development environment on Windows. It eliminates the need for manual installation and configuration of each component separately.
1. Why Use XAMPP for PHP Installation?
✅ Easy to Install – One-click installation without configuring Apache or PHP manually.
✅ Pre-Configured PHP – Comes with PHP pre-installed and ready to use.
✅ MySQL & phpMyAdmin – Allows database management through a graphical interface.
✅ Cross-Platform – Available for Windows, Linux, and macOS.
2. Downloading XAMPP
- Visit the Official Website
- Open your browser and go to Apache Friends.
- Download the latest version of XAMPP for Windows.
- Choosing the Right Version
- The latest versions of XAMPP come with PHP 8.x by default.
- If your project requires an older PHP version (PHP 7.x), select the appropriate XAMPP version from the official website.
3. Installing XAMPP on Windows
Step 1: Run the Installer
- Double-click the downloaded XAMPP installer (.exe file).
- Click “Yes” if Windows asks for permission to run the installer.
Step 2: Select Components
- The installer will ask which components to install.
- By default, all components are selected, but you only need:
✅ Apache (Web Server)
✅ MySQL (Database Server)
✅ PHP (Scripting Language)
✅ phpMyAdmin (Database Management Tool) - Click Next to proceed.
Step 3: Choose Installation Directory
- The default installation directory is C:\xampp\.
- It’s recommended to install XAMPP in C:\xampp rather than C:\Program Files to avoid permission issues.
Step 4: Start Installation
- Click Next and then Install.
- The installation process will begin. Wait until it’s complete.
Step 5: Launch XAMPP Control Panel
- Once installed, check the box “Do you want to start the Control Panel?” and click Finish.
- The XAMPP Control Panel will open.
4. Running PHP Using XAMPP
Step 1: Start Apache and MySQL
- In the XAMPP Control Panel, click Start next to Apache and MySQL.
- If both services start successfully, their status will turn green.
Step 2: Verify XAMPP Installation
- Open a browser and go to:
http://localhost
- If XAMPP is installed correctly, you will see the XAMPP Dashboard.
Step 3: Test PHP Installation
- Open the XAMPP installation folder (C:\xampp\htdocs\).
- Create a new file named test.php inside htdocs and open it in a text editor like Notepad++ or VS Code.
- Add the following PHP code:
php
CopyEdit
<?php
phpinfo();
?>
- Save the file and open a browser. Go to:
http://localhost/test.php
- If PHP is working correctly, you will see the PHP configuration page with details about your installation.
5. Configuring PHP in XAMPP
Editing php.ini File
The php.ini file controls PHP settings. You may need to modify it for various reasons (e.g., enabling extensions, increasing memory limits).
- Open the XAMPP Control Panel.
- Click on Config next to Apache, then select PHP (php.ini).
- The php.ini file will open in Notepad.
- To enable extensions (e.g., curl or openssl), remove the ; (semicolon) before the corresponding line:
extension=curl
extension=openssl
- Save the file and restart Apache.
6. Managing MySQL with phpMyAdmin
phpMyAdmin is a web-based tool for managing MySQL databases.
- Open a browser and visit:
http://localhost/phpmyadmin
- You will see the phpMyAdmin interface where you can create, modify, and delete databases.
7. Running PHP Scripts in the Command Line (Optional)
If you want to run PHP scripts via the command prompt, you need to set up the PHP environment variable:
Step 1: Add PHP to System Path
- Open Control Panel > System > Advanced system settings.
- Click Environment Variables.
- Under System Variables, find Path, select it, and click Edit.
- Click New and add the path to PHP (e.g., C:\xampp\php).
- Click OK to save changes.
Step 2: Test PHP CLI
- Open Command Prompt (cmd) and type:
php -v
- You should see the installed PHP version.
8. Troubleshooting Common Issues
Issue | Solution |
Apache/MySQL fails to start | Check if another application (e.g., Skype, IIS) is using port 80/443. Change Apache’s port in httpd.conf. |
PHP file downloads instead of executing | Ensure Apache is running and test.php is inside htdocs. |
phpinfo() does not display PHP info | Restart Apache and ensure PHP is correctly installed. |
MySQL service stops automatically | Check MySQL error logs in C:\xampp\mysql\data\. Try running MySQL manually from the command line. |
9. Conclusion
Installing PHP using XAMPP on Windows is the easiest way to set up a local development environment. With Apache, MySQL, and PHP pre-configured, you can start developing web applications immediately.