Setup PHP Development Environment on Windows

How to Setup PHP Development Environment on Windows?

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.

    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, …

    first step of xampp installation
    select xampp components
    xampp installation folder location
    installing xampp
  • 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.

    search the xampp control panel on windows

    Start Apache & MySQL –

    start apache and mysql on xampp
  • Open your localhost

    After starting Apache, open http://localhost/ on your browser to access your localhost.

    XAMPP localhost dashboard
  • 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.

    XAMPP phpMyAdmin dashboard

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).

    XAMPP explorer button to open xampp installation directory

    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.

    xampp htodcs folder location
  • Create your first PHP file

    Inside the htdocs folder, create a new folder called php.

    create php folder inside the htdocs folder

    After that, go inside the php folder and create your first php called index.php.

    create the index.php file

    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.

    open index.php on your browser

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.

    XAMPP explorer button to open xampp installation directory
  • Copy the path of the php folder
    XAMPP php folder location
    Copy the XAMPP php folder path
  • Set the php folder path to the environment variables path

    Open the Advanced system settings (Right click on This PC » Click Properties).

    windows advanced system settings

    Then click on the Environment Variables.

    windows environment variables

    Then select the Path and click on Edit.

    windows path environment variables

    Now click on the New and paste the path of the XAMPP php folder (C:\xampp\php), and Save it.

    add new path to the windows environment variables
  • 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.

    check php version via command line or powershell
  • Execute PHP file using command line

    Open command prompt or Powershell » navigate to the location of the PHP file » run php file_name.php.