How to install Apache 2.4 and PHP 8 on a Windows12 June 2023
In this tutorial, I am installing and configuring Apache 2.4 and PHP 8 on a Windows. I am using Windows 11 for this tutorial. To run the PHP code on a Windows Based Machine, first, you’ll need to install and configure a web server (Apache) that executes the PHP application. Here, you will find the step-by-step guide on “How to install Apache 2.4 and PHP 8 on a Windows”.
Let’s discuss Apache and PHP.
Apache Web Server
The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards. The Apache HTTP Server (“httpd”) was launched in 1995 and it has been the most popular web server on the Internet since April 1996. The Apache HTTP Server is a project of The Apache Software Foundation.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP.
PHP is an acronym for “PHP: Hypertext Preprocessor”. It is a widely-used, open source scripting language. PHP scripts are executed on the server. It is free to download and use.
PHP is an amazing and popular language. It is powerful enough to be at the core of the biggest blogging system on the web (WordPress). It is deep enough to run large social networks. It is also easy enough to be a beginner’s first server side language.
Step – 1 : Download Apache and PHP
Download the Apache 2.4.x and PHP 8 from its official websites, extract the downloaded file and move it to the C drive.
Download Apache 2.4.x – Depending on your system build download the binary zip file accordingly.
Download PHP 8 – Similarly, depending on your system build download the Thread Safe version of PHP.
Step – Install Apache HTTP Server
Extract Downloaded Apache file and move Apache24 folder in C drive. You can choose another location if you want.
Go to the Apache 24 > bin directory path C:\Apache24\bin (it might be different in your case) and set it into your system environment variable path.
Open the command prompt with admin privileges (run as administrator) and run the
httpd -k install command to install the Apache services.
C:\WINDOWS\system32>httpd -k install Installing the 'Apache2.4' service The 'Apache2.4' service is successfully installed. Testing httpd.conf.... Errors reported here must be corrected before the service can be started. AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::ccb2:109d:6198:a489. Set the 'ServerName' directive globally to suppress this message
Start the Apache service with the command
httpd -k start or directly through the
Task Manager » Services » Search for Apache2.4 » Right-click on the service » Start.
Remember – By default, Apache HTTP Server runs on port 80, make sure no other services/servers running on this port.
Open the any web browser and enter localhost URL i.e
localhost:80. If everything is configured correctly, you will see the default index.html web page contents and it is located inside the C:\Apache24\htdocs directory.
Step -3 : Install PHP 8
Now we install PHP 8. To do that, similarly, move the downloaded and extracted PHP 8 binary files to the C drive. In my case, I renamed php-8.2.4 to php folder.
Now Copy the PHP 8 home path i.e C:\php and set it into your machine environment variable just like above “apache setup”.
Open the command prompt and type
php -v to check whether the path is set correctly or not. If the PHP path is set correctly, it will print the PHP version.
Step – 4 : Configure Apache and PHP
Now configure Apache HTTP Server with PHP 8. Go to the C:\Apache24\conf directory, inside the conf directory edit the
httpd.conf file. Go to the end of the file and add the below configuration because, in Apache, PHP is loaded as a module.
# Note: Repalce php_module location with your PHP path and # if the php8apache2_4.dll is not available, # download the non thread safe version of PHP. LoadModule php_module "C:\php\php8apache2_4.dll" AddHandler application/x-httpd-php .php PHPIniDir "C:\php"
Go to the PHP home directory C:\php, and you will find two configuration files
php.ini-production. Create a copy of
php.ini-development and rename it to
Again we will open the
httpd.conf file and search for ServerName, uncomment and edit the ServerName with
# ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # ServerName localhost
And in the same file also search for DirectoryIndex, and append the default index.php file.
# DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
Open the command prompt and run the
httpd -t command to validate. If all seting up steps are configured correctly, it will return Syntax OK if everything is configured correctly.
C:\WINDOWS\system32>httpd -t Syntax OK
Step -5 : Test the configuration of Apache and PHP
For testing the Apache 2.4 and PHP 8 configuration, restart the Apache2.4 service from the Task Manager or cammand and rename the
index.html file to
index.php from the C:\Apache24\htdocs directory and add the below piece of code.
Open the web browser and hit the
localhost in the URL bar, you will get the following details:
References and Useful Links :
Additional Setting For httpd.conf (Optional)
Change the Web Page Root
By default, Apache returns files found in its
C:/Apache24/htdocs folder. It’s good to use a folder on an another drive or partition to make backups and re-installation easier. For the purposes of this example, we’ll create a folder called
D:WebPages and change
- Line 251, set the root:
- Line 252:
There are several lines you should change for your production environment:
- Line 60, listen to all requests on port 80:
- Line 162, enable mod-rewrite by removing the # (optional, but useful):
LoadModule rewrite_module modules/mod_rewrite.so
- Line 227, specify the server domain name:
- Line 224, allow
Additional Setting for PHP.ini (Optional)
You can configure php.ini file accordingly your requirements. PHP’s configuration file is
php.ini. This doesn’t exist initially, so copy
C:\php\php.ini. This default configuration provides a development setup which reports all PHP errors and warnings.
You can edit
php.ini in a text editor like Notepad or any other text editor, and you may need to change lines such as those suggested below (use search to find the setting). In most cases, you’ll need to remove a leading semicolon (
;) to uncomment a value.
First, enable any required extensions according to the libraries you want to use. The following extensions should be suitable for most applications including WordPress:
extension=curl extension=gd extension=mbstring extension=pdo_mysql
If you want to send emails using PHP’s
mail() function, enter the details of an SMTP server in the
[mail function] section (your ISP’s settings should be suitable):
[mail function] ; For Win32 machine only. ; http://php.net/smtp SMTP = mail.myisp.com ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = [email protected]
Thanks for reading. We hope that you like this post. If you have any queries related to this article, leave a comment down below!
Hi, I’m Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let’s connect and explore the tech world together!
If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee!