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.
- phpMyAdmin.
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. - phpMyAdmin
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 –
http://localhost/phpmyadmin/
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
htdocs
folder, 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
Inside the
htdocs
folder, create a new folder calledphp
.After that, go inside the
php
folder and create your first php calledindex.php
.Write the following PHP code in the
index.php
file. 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
Now open
http://localhost/php/index.php
on 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
The command
php -v
will 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
php file_name.php
.