How to Install PHP on Apache in Windows?
Last Updated :
16 Dec, 2022
PHP is a Hypertext Preprocessor, earlier it known as Personal Home Page. It is an open-source server (available for free) side scripting language (everything is implemented on the webserver) that is embedded into HTML and used for web development. PHP script starts with <?PHP and ends with?>. Some common features of PHP are:
- Open Source
- Platform Independent
- Used to create dynamic web pages
- Provides Security encryption
- Cost-Efficient
- Compatibility
- Website function faster
Facebook, Wikipedia, WordPress, Tumbler, and yahoo are some of the major companies using PHP
Why PHP on Apache?
PHP and MySQL both are compatible with an Apache server. These two are open source and easy to set up. PHP runs on many platforms like Windows, Linux, and Unix. Because of these advantages, PHP is used on Apache servers. Before installing the PHP make sure that the Apache server is already installed on your PC.
How to Install PHP on Apache?
Follow the steps below in order to set up PHP on Apache without facing any difficulties.
Step 1: Visit the official website of PHP. Here you will find the two different packages called Non-Thread Safe and Thread Safe Packages. Download the zip folder under the Thread Safe section because we are working on Apache.

Step 2: Extract the files and rename the extracted file to PHP8.1(It’s completely on the user’s wish) and move to the directory where the Apache folder is located. Add the path to the system variables. To add the copied address to the system variables, search for Control Panel > System & Security > System > advanced system settings > Environment variables > System Variables > Path > Edit > New and paste the copied address.

Note: Make sure that both Apache and PHP extracted files should be in the same folder
Step 3: To check whether the PHP directory is added to the path of system variables or not. Open PowerShell as an administrator. Change PowerShell mode to the command prompt by entering the command cmd. Then type path hit enter if the directory path is visible on the screen, then the path is successfully added to the system variables. To know the version of the PHP type php -v and then hit enter

Step 4: Now it’s time to configure Apache for this open C: > Apache24 > conf > httpd.conf

Scroll down the httpd.conf file to the end and write the below three lines. In Apache, PHP is loaded as a module so load the module using LoadModule, read PHP files with the file handler and finally add the PHP file located address within the double quotes
LoadModule php_module “C:\PHP8.1\php8apache2_4.dll”
AddHandler application/x-httpd-php .php
PHPIniDir “C:\PHP8.1”

Step 5: In the PHP8.1 directory there are two default configuration files “php.ini-development” and “php.ini-production. Copy-paste the “php.ini-development” and rename the copied file as “php.ini”

Step 6: Set ServerName parameter as localhost for this search (Ctrl+F) “ServerName” in “httpd.conf” file and set ServerName as localhost below the “#ServerName www.example.com:80” line ServerName localhost

Step 7: Open PowerShell in command prompt mode as an administrator and type “httpd –t” and hit enter. If everything is ok then it displays “Syntax OK”

Step 8: Specify the default PHP page. For this search for ” DirectoryIndex ” in httpd.conf file. Inside Dir-module add “index.php”

Step 9: Open htdocs folder which is present inside the Apache24 folder and create a PHP file with the below code and save it as index.php (users wish) for testing. To test the program, open your favorite browser and then type localhost and hit enter.
PHP CODE :
<?php
phpinfo();
?>
Running PHP code on Apache server
Now Apache server is ready to run PHP codes. Let’s understand how to run the first PHP code on the Apache server. For this open an editor write an example PHP code and save it in Apache24 > htdocs > projectfolder > filename.php.

a projectfolder is your folder with your projectname and filename.php is your filename which should store inside your projectfolder. Now it’s time to run the example program. For this open your favorite browser and then type “localhost/projectfolder/filename.php”. then it will show the below output

Similar Reads
How to install XAMPP on Windows ?
XAMPP is the most popular software package which is used to set up a PHP development environment for web services by providing all the required software components. During the process of software deployment, most of the web servers use almost similar components, so use of XAMPP provides easy transit
4 min read
How to Install and Set up a WAMP Server ?
Windows, Apache, MySQL and PHP is commonly abbreviated as WAMP. Some people may confuse with LAMP but the only difference between the two is their operating systems. In case of LAMP, L stands for Linux. Setting up a server included the installation of all the software listed in the abbreviation. Ano
3 min read
How to install PHP in Windows 10?
PHP is a general-purpose scripting language geared towards web development. It is an open-source software (OSS), which is free to download and use. PHP stands for "Hypertext Preprocessor". PHP files are saved with an extension called .php. It supports many databases MySQL, Oracle, etc. Installation
2 min read
How to Install PHP on Linux?
PHP is a popular server-side scripting language that is especially used in web development. If you're working on a Linux environment, whether it's a personal development setup or a production server, you will likely need PHP installed. In this article, we will see the step-by-step guide to install P
2 min read
How to Install PHP on MacOS?
PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites. It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call extern
3 min read
How to set PHP development environment in windows ?
What is PHP ? PHP (Hypertext PreProcessor) is a general-purpose programming language developed by Rasmus Lerdorf in 1994 for web development. This is one of the most popular programming language for beginners in web development because of its simplicity, large community and accessibility.Steps to se
3 min read
How to set up a PHP Console ?
PHP is a backend server-side language of web development. In general, we don't need to take input from the console but sometimes we need to run a small function or block of code, for which we need to take input from the console. Requirements: Server: xampp or WampServer How to set up PHP Console ? S
1 min read
How to Install IMAP Extension in PHP on MacOS?
Imap stands for Internet Message Access Protocol, It is a protocol used by email clients to retrieve email messages from mail servers, It is an application layer protocol in the OSI model. Imap allows us to store our messages on servers so that they can be accessed from multiple devices, whereas POP
4 min read
How to Install PHP GD-library on CentOS?
GD is an open-source code library that helps to create and manipulate PNG, JPEG, and GIF images in PHP. GD is commonly used for the development of websites. Image resizing, cropping, drawing, and adding effects to dynamic rendering can easily be done with its help. Picture handling and GD capacities
2 min read
How to Install PHP Extensions on Windows?
PHP is a general-purpose server scripting language. It is a powerful and important tool for developing dynamic and interactive Web pages. It is widely used, free, fast, flexible, and pragmatic. After installing PHP and a web server on Windows, extensions are also needed because they provide added fu
2 min read