Here you will learn how to install PHP and MySQL or MariaDB to set up your PHP development environment on your local Windows machine.
Table of Contents #
You have to install the following things on your Windows machine to setup a PHP dev environment –
- A Web Server (Apache or Nginx). (required)
- PHP itself. (required)
- MySQL or MariaDB.
You can install the above applications and software in two ways –
- Utilize all-in-one packages like XAMPP or WAMP. (recommended)
- Install MySQL, PHP, and Apache manually, and configure them.
Install XAMPP to setup your PHP Dev Env on Windows
- Download the XAMPP
Go to the https://www.apachefriends.org/download.html and download the latest version of XAMPP.
- Install the XAMPP
Now install the downloaded XAMPP, and it is quite easy to install. Just do next, next, …
- Open the XAMPP Control Panle & Start Apache and MySQL
After successfully installing the XAMPP in your local machine open the control panel and start Apache and MySQL.
Start Apache & MySQL –
- Open your localhost
After starting Apache, open
http://localhost/on your browser to access your localhost.
You don’t need to install phpMyAdmin separately, it comes with XAMPP.
So, after starting Apache as well as MySQL, you can access your phpMyAdmin here –
phpMyAdmin is a free and open-source web-based application that provides a graphical user interface (GUI) for managing and administering MySQL or MariaDB databases. It allows users to interact with their databases without needing to use command-line tools or write SQL queries directly.
Build your first PHP website
- Go inside the XAMPP htdocs folder
Open your XAMPP control panel and click on Explorer (make sure Apache and MySQL are running).
Now you can see the
htdocsfolder, This is the folder where you place your web files.
The htdocs folder serves as the default root directory for your local web server, which is Apache in the case of XAMPP. When you access http://localhost or http://127.0.0.1 in your web browser, Apache looks for web files within the htdocs folder and serves them to your browser.
- Create your first PHP file
htdocsfolder, create a new folder called
After that, go inside the
phpfolder and create your first php called
Write the following PHP code in the
index.phpfile. You can use Notepad to write the code.
The following PHP code will show the text between the quotes.
<?php echo "<h1>Hello, From PHP</h1>";
- Open index.php on your browser
http://localhost/php/index.phpon your browser to see the result.
Using PHP via Command-Line on Windows
Follow the steps given below to execute PHP code using command line –
- Open the XAMPP installation directory
After installing the XAMPP, open the XAMPP control panel and click on Explorer to open the XAMPP installation folder.
- Copy the path of the php folder
- Set the php folder path to the environment variables path
Open the Advanced system settings (Right click on This PC » Click Properties).
Then click on the Environment Variables.
Then select the Path and click on Edit.
Now click on the New and paste the path of the XAMPP php folder (
C:\xampp\php), and Save it.
- Now test it by checking the PHP version via command line
php -vwill give you the version of PHP installed on your computer.
- Execute PHP file using command line
Open command prompt or Powershell » navigate to the location of the PHP file » run