How to Install PHP 8 on Windows

Kaima Abbes
4 min readNov 27, 2020

In this post, we’ll learn how to install PHP 8 on Windows.

Why Developing with PHP?

PHP is one of the most popular server-side programming languages on the world. It is installed by most web hosts, has an easy learning curve, close ties with the MySQL database, and a good number of libraries to improve your productivity. PHP may not be perfect, but it should certainly be considered for your next web application. Both Yahoo and Facebook use it with great success.

Recently PHP 8 was released with many new features and improvements such as named parameters, attributes, union types, constructor properties,

Why Install PHP 8 Locally?

Having PHP 8 installed on your development machine enables you to create web applications without risking the production data or resources on your real-world website. This post will teach you how to install PHP 8 in the Windows version of Apache.

All-in-One packages

There are some excellent all-in-one Windows distributions that contain Apache, PHP 8, MySQL and other applications in a single installation file, e.g. XAMPP (including a Mac version), WampServer and Web.Developer. There is nothing wrong with using these packages, although manually installing Apache and PHP will help you learn more about the system and its configuration options.

The PHP Installer

Although an installer is available from php.net, I would recommend the manual installation if you already have a web server configured and running.

Manual Installation

Manual installation offers several benefits:

  • backing up, reinstalling, or moving the web server can be achieved in seconds and
  • you have more control over PHP 8 and Apache configuration.

Step 1: Download the files

Download the latest PHP 8 ZIP package from www.php.net/downloads.php

As always, virus scan the file and check its MD5 checksum using a tool such as fsum.

Step 2: Extract the files

We will install the PHP files to C:\php, so create that folder and extract the contents of the ZIP file into it.

PHP 8 can be installed anywhere on your system, but you will need to change the paths referenced in the following steps.

Step 3: Configure php.ini

Copy C:\php\php.ini-development to C:\php\php.ini. There are several lines you will need to change in a text editor (use search to find the current setting). Where applicable, you will need to remove the leading semicolon to uncomment these setting.

Define the extension directory:

extension_dir = "C:/php/ext"

Enable extensions. This will depend on the libraries you want to use, but the following extensions should be suitable for the majority of applications:

extension=curl
extension=gd2
extension=mbstring
extension=mysql
extension=pdo_mysql
extension=xmlrpc

If you want to send emails using the PHP 8 mail() function, enter the details of an SMTP server (your ISP’s server should be suitable):

[mail function]
; For Win32 only.
SMTP = mail.myisp.com
smtp_port = 25
; For Win32 only.
sendmail_from = my@emailaddress.com

Step 4: Add C:\php to the path environment variable

To ensure Windows can find PHP 8, you need to change the path environment variable. Open Settings, type ‘environment variables’ into the search field and open the result. Select the “Advanced” tab, and click the “Environment Variables” button.

Scroll down the System variables list and click on “Path” followed by the “Edit” button. Click “Edit text” and add ;C:\php to the end of the Variable value line (remember the semicolon).

Now click OK until you’re out. You might need to reboot at this stage.

Build faster websites and apps

Learn the skills to boosting your data-driven web apps performance

Read the book now

Step 5: Configure PHP 8 as an Apache module

Ensure Apache is not running (use net stop Apache2.2 from the command line) and open its confhttpd.conf configuration file in an editor. The following lines should be changed:

On line 239, add index.php as a default file name:

DirectoryIndex index.php index.html

At the bottom of the file, add the following lines (change the PHP file locations if necessary):

# PHP8 module
LoadModule php8_module "c:/php/php8apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"

Save the configuration file and test it from the command line (Start > Run > cmd):

cd Apache2bin 
httpd -t

Step 6: Test a PHP file

Create a file named index.php in Apache’s web page root (either htdocs or D:WebPages) and add this code:

<?php phpinfo(); ?>

Ensure Apache has started successfully, open a web browser and enter the address http://localhost/. If all goes well, a “PHP version” page should appear showing all the configuration settings.

--

--