Installing a Local Web Server with PHP Support on Windows

Riley Entertainment Web Dev
5 min readAug 20, 2021

While you likely won’t be hosting your website from your home computer, having your own local web server helps you test things out before you publish to the world. This article will be covering the Apache HTTP Server, which is commonly used by web hosting providers. Nginx is a more modern choice that has gained traction over the past decade.

My choice of Apache was based on familiarity — I believe it’s what my hosting provider uses, so I wanted to be able to mimic their setup as closely as possible. My choice of PHP was based on what’s available to me on my current web host. I actually would prefer to build the dynamic portions of my website with NodeJS and Node Express, but, well… I don’t plan to build anything too complicated, so affordability was more important to me when picking a web host. 😉

TL;DR Version

If you’re here to get up and running as quickly as possible, here’s the short version:

  1. Download and install Apache HTTP Server Win64 binaries from Apache Lounge. Check out the ReadMe.txt file for important information.
  2. Test out the server by running httpd.exe (from the bin folder) on the command line, then navigating to “localhost” in a web browser.
  3. Download and install PHP. Check out the Windows installation information in the PHP manual to get it working with Apache.

Or for those looking for more detailed instructions, read on…

Installing Apache HTTP Server

At first glance, getting the Apache HTTP Server installed on Windows looks like it might be quite the adventure. The official site makes the source code available, giving you the super spiffy option of building the executable yourself. In a past life, I might have welcomed the challenge. My goal today, however, is to get my website up and running so I can focus on game development. The official download page has a rather nondescript line about the Win32 distribution (image from apache site) with a link to additional information. From there, I chose the Apache Lounge website, which also happens to be the recommended distribution mentioned on the PHP website.

I also found a good article on sitepoint about this very topic. It includes a number of other installation options, all of which look like more work than I wanted to tackle for the time-being.

As of the time of this writing, the Apache HTTP Server is at version 2.4.48. The download option is a ZIP file, so installation just involves extracting its contents into the directory of your choice. It includes a readme file, and an Apache24 folder containing the server software. The readme file provides some important notes for getting going.

If you extracted to a location other than the default C:\Apache24\, you’ll have to open up “conf\httpd.conf” in a text editor and modify the line that reads “Define SRVROOT”.

httpd.conf

To run the web server, open up a Windows command prompt, navigate to the “bin” folder, and run “httpd”. The first time you run it, Windows will likely bring up a security alert from Windows Defender Firewall:

If you open a web browser and point it at “localhost”, you should see the default “It Works” page:

Why are you using Firefox, Riley? Because I was taking a screenshot, yo. Do you have any idea how many Chrome tabs I have open at any given time?

Installing PHP

As of the time of this writing, the latest stable release of PHP is at version 8.0.9. My hosting provider, however, is currently using version 7.4, so I’ve chosen to download that in order to match my production environment. The PHP download page has a handy “Which version do I choose?” section to guide your choice. To work with the Apache web server, I’ve chosen the VS16 x64 Thread Safe version. The download is a ZIP file, so installation involves extracting its contents to the directory of your choice.

The online PHP manual provides a section dedicated to installation and configuration on Windows machines. These were the important items to get Apache and PHP to work together:

  1. Add the root folder of your PHP installation to the system path.
  2. Make a copy of the “php.ini-development” file, saving it as “php.ini” in the root folder.
  3. To ensure PHP module extensions operate, uncomment the line that reads extension_dir = “ext”. Ensure that any extensions you’ll make use of are included in the “Dynamic Extensions” section.
  4. Update your Apache’s httpd.conf file to include a section to load the PHP module. This is slightly different for each PHP version. For PHP 7, it looks something like so:
    PHPIniDir "C:\path\to\php"
    LoadModule php7_module "C:\path\to\php\php7apache2_4.dll"
    AddType application/x-httpd-php .php
  5. If you want “index.php” files to be served automatically when a user navigates to a folder, add it to the DirectoryIndex entry in httpd.conf.

Once PHP has been configured, you can test it out by restarting the Apache server and creating a simple PHP file. The scriptlet below will output a rather verbose table listing everything you could possibly want to know (and plenty you probably don’t care about) about your configuration:

<html><head>
<title>PHP Test</title>
</head>
<body><?php echo phpinfo(); ?></body></html>
Scroll for details. Then scroll some more. And scroll even more.

And that should be good to get started with Apache and PHP on Windows! There’s plenty of configuration options and modules to consider, but each is likely worthy of a whole article on its own.

My next post will involve reading the RSS feed from a Medium blog from PHP and/or JavaScript, to integrate on a website. You can get a glimpse of where I plan to do this over on the Riley Entertainment site.

--

--

Riley Entertainment Web Dev
0 Followers

Indie Game Dev and Content Creator, sole proprietor of Riley Entertainment