How to Install PHP on Windows 11
Install PHP on Windows 11 step by step, connect it to Apache, configure php.ini, and start running PHP locally.
Download PHP
Download the latest PHP x64 Thread Safe ZIP package from:
https://windows.php.net/download/
Extract
Extract all to C:\php
Configure Apache
Open Apache config file at:
C:\Apache24\conf\httpd.conf
Add the following to the top of the file:
LoadModule php_module "c:/php/php8apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "c:/php"
Restart Apache
Option 1:
Open Services, find Apache 2.4 - right click - Restart
Option 2:
Open the Command Prompt as an Administrator:
C:\Windows\System32>net stop "Apache2.4"
C:\Windows\System32>net start "Apache2.4"
Configure PHP
PHP’s configuration file is php.ini. This doesn’t exist initially, so copy:
C:\php\php.ini-development
to
C:\php\php.ini
You can edit php.ini in a 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=mysqli
extension=pdo_mysql
extension=openssl
extension=zip
Change the default index to index.php:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
Add C:\php to the PATH environment variable
To ensure Windows can find the PHP executable, you must add it to the PATH environment variable.
Click the Windows Key button and type “env”, press Enter. Select the Advanced tab, and click the Environment Variables button.
Scroll down the System variables list and click Path, followed by the Edit button. Click New and add C:\php.
Now OK your way out. You shouldn’t need to reboot, but you may need to close and restart any CMD terminals you have open.
Greetings, World!
Create a new file called greetings.php in Apache htdocs directory with this code:
<?php
echo "Greetings, World!;"
?>
Open up Command Prompt and type:
cd C:\Apache24\htdocs
php greetings.php