Results 1 to 1 of 1

Thread: PHP For Windows Development Guide

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    PHP For Windows Development Guide

    What This Is
    This is a step-by-step guide on how to setup a development environment for PHP hosted on Windows.

    What This Is Not
    This is not a step-by-step guide on serving a PHP application on Windows nor is this a guide on best practices for serving PHP applications.

    The Steps
    The following are the steps to get a development environment stood up for PHP applications on Windows from scratch.
    1. Download and extract the PHP files
    2. Configure php.ini
    3. Add PHP to the PATH environment variable
    4. Setting up the Apache module
    5. Setting up a Live Reloader


    Download and Extract the PHP Files
    First you will need to download the latest x64 Thread Safe ZIP package from https://windows.php.net/download/. After downloading the ZIP package, extract it to a file location. The most common file location where PHP will typically be extracted to is C:\php.

    Configure php.ini
    The php.ini file is used to configure the settings for PHP. This does not exist by default, but a development copy exists under the filename php.ini-development file. Open your terminal (aka command prompt) as an administrator, change the directory to where PHP was extracted, and copy the php.ini-development to php.ini. Here is an example, assuming your file was extracted to c:/php:
    Code:
    cd c:/php
    copy php.ini-development php.ini
    Once the php.ini file is created, you will need to enable any extensions that you want your PHP application(s) to use. By default extensions may be commented out, as indicated by a semicolon at the start of the line. To enable an extension, simply remove the leading semicolon of an existing extension or add a new line in the format extension=name.

    If you want to send emails using PHP's mail function (documentation) then you will need to enter the details of an SMTP server in the [mail function] section.

    Add PHP to the PATH Environment Variable
    Open up advanced system settings by either using the shortcut windows + pause (aka break) and clicking on Advanced System Settings or by using Cortana to search for the phrase System Environment Variables. Click on Environment Variables to bring up the environment variables dialog. Select the row for the user variable Path and click on Edit. Click on New and enter the path that PHP was extracted to (e.g. c:/php). Then click on OK and OK again to close out of the Environment Variables dialog.

    Setting up the Apache module
    Apache should have been included with the PHP download, but if not then you will need to download the latest Apache for Win64 ZIP package from https://www.apachelounge.com/download/. After downloading the ZIP package, extract it to a file location. The most common file location where Apache will typically be extracted is C:\Apache24 (or C:\Apache25 if the version changes).

    Open Apache's httpd.conf file in a text editor, this will typically be located in your Apache directory's conf directory. Add the following lines at the bottom of the file, changing any relative path or file locations:
    Code:
    # PHP module
    PHPIniDir "C:/php"
    LoadModule php_module "C:/php/php8apache2_4.dll"
    AddType application/x-httpd-php .php
    Setting up a Live Reloader
    Perhaps the best IDE to use for PHP development as of writing this is Visual Studio Code. This section is specific to this application.

    Launch Visual Studio Code and open its extensions panel. Search the Marketplace for Live Server by Ritwick Dey. Install the extension and restart Visual Studio Code. Follow these instructions for configuring PHP with the extension: https://github.com/ritwickdey/live-s.../docs/Setup.md
    Last edited by dday9; Feb 9th, 2023 at 11:29 AM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width