How to Install PHP on Windows 10 and 11
Linux as well as macOS users usually are equipped with Apache and PHP already installed or available through package managers. Windows requires a bit more effort. The steps listed below might be compatible with other versions that include Windows, PHP, and Apache. However, in this article, we’ll discuss how to install PHP on Windows 10 and 11 even if you buy a Windows VPS Server and you need PHP on Windows.
Why PHP?
PHP is still the most widely used and well-known server-side programming language available on the Web. It’s used by a majority of web hosts and comes with an easy learning curve, strong ties to MySQL, excellent documentation, and an extensive selection of libraries to reduce the development time. PHP may not be ideal. However, you should think about it as a possible language for your next web-based application. It’s the preferred language to use for Facebook, Slack, Wikipedia, MailChimp, Etsy, and WordPress (the CMS that powers nearly 45% of the internet).
Why Install PHP Locally?
Installing PHP on Windows locally lets you build and test applications and websites without impacting the system or data of your server.
Alternative Installation Options
Before you dive into the water, you might want to consider a more straightforward guide on how to install PHP on Windows or any other OS.
With an all-in-one system
All-in-one programs are offered for Windows. They include Apache, PHP, MySQL, as well as other dependencies, all in one installation file. The packages comprise XAMPP, WampServer, and Web Developer tools.
The software is easy to install. However, they may not work with your current server configuration. Installing PHP on Windows and Apache manually can help you get familiar with the systems and configuration options.
Using the Linux Virtual Machine
Microsoft Hyper-V (provided within Windows Professional) and VirtualBox are free hypervisors that simulate a PC so that you can install a different operating system.
Install any of the versions of Linux and then follow the Apache as well as PHP Installation instructions. Alternately, distros like Ubuntu Server provide them as standard (although they may not be the most recent versions). In addition, you can buy Windows VPS server and ask the hosting provider to install PHP on Windows 11 or any other version of the Windows OS you’d like to be installed on the Windows VPS.
Using Windows Subsystem for Linux 2
WSL2 could also function as a virtual machine. However, it’s fully integrated into Windows; therefore, activities such as sharing files or localhost resolution work seamlessly. It is possible to install a range of Linux distros and refer to the specific Apache as well as PHP instructions.
Utilizing Docker
Docker creates an application wrapper (known in the context of the container) around pre-configured dependencies for applications like Apache, PHP, MySQL, MongoDB, and most other web-based software. Containers resemble fully-fledged Linux Virtual Machines but are much lighter.
When you’ve set up Docker Desktop on Windows, it’s simple to download the application, configure it, and then start Apache along with PHP.
Docker is currently the most effective method of creating a PHP development environment.
How to Install PHP on Windows
As mentioned above, if you are a developer, then you are going to need PHP for Windows. Installation of PHP using the instructions listed below is simple if you manage to stay with us. There’s more than one method of configuring PHP; however, this could be the fastest method.
Step 1: Download the PHP files
Get the latest PHP x64 Thread Safe ZIP package from https://windows.php.net/download/
Step 2: Extract the files
Create a brand new PHP folder inside the root of the C:\ drive. Extract the contents of the ZIP file into it.
You are able to install PHP anyplace on your system. However, you’ll have to alter the path that is listed below if you are using any other path than C:\php.
Step 3: php.ini
The PHP configuration file is typically located in the php.ini file. This doesn’t exist initially, so copy C:\php\php.ini-development to C:\php\php.ini. This default configuration offers the development setting that will report every PHP mistake and alert.
Later on, you can modify php.ini in a text editor, and you might require changing the lines like those listed beneath (use search to locate your setting). Most of the time, you’ll need to eliminate the preceding semicolon (;) to remove a comment on the value.
The first step is to enable the required extensions in accordance with the libraries you wish to utilize. These extensions are compatible with most applications, including WordPress:
extension=curl
extension=gd
extension=mbstring
extension=pdo_mysql
If you wish to send out emails through the PHP email() function, add the information of an SMTP server within the [mail function] section:
[mail function]
; For Win32 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]
Step 4: Add C:\php in the PATH environment variable
To make sure that Windows can locate that PHP executable, you need to include it in the PATH environment variable. Click on the Windows Start button and enter “environment” then click edit the system’s environment variables. Choose the Advanced tab and then select the environment variables button.
Browse down to the system variables list, then click Path, and then click the edit button. Select “New” and then add C:\php (which is the folder you created earlier).
There is no need to reboot, but you might have to shut down and then reopen the cmd terminals that you are running. In case you have it open to install PHP Windows from the command line.
Step 5: Configure PHP to be an Apache module
Ensure Apache is not running and open its C:\Apache24\conf\httpd.conf configuration file in a text editor. Add the following lines at the end of the file to enable PHP to be the Apache module (change the file location depending on the need, but use forward slashes, not Windows backslashes):
# PHP8 module
PHPIniDir “C:/php”
LoadModule php_module “C:/php/php8apache2_4.dll”
AddType application/x-httpd-php .php
Alternatively, you can change or modify the directory index setting to make use of index.php as the default instead of index.html. The default setting is:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
Make it:
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
Then save httpd.conf and test the changes using the cmd command line:
cd C:\Apache24\bin
httpd -t
If everything went as planned If everything went well, you could start Apache by using httpd.
Step 6: Test a PHP file
Create a new file with the name index.php in Apache’s web page root folder located at C:\Apache24\htdocs. Include this PHP code:
<?php
phpinfo();
?>
Open a browser and type in your server’s address http://localhost; the PHP version page will appear and display the complete PHP as well as the Apache setting.
It is now possible to create PHP websites and applications within any subfolder within C:\Apache24\htdocs. If you are required to work in more than one area, think about defining Apache Virtual Hosts so you are able to run different codebases using various localhost ports or subdomains.
Conclusion
In this article, we discussed how to install PHP on Windows 10 and 11 in order to test out your web-based applications on your local machine. There are a few other methods to go about installing PHP on your system. However, we decided to write this guide with the simplest available method so that anyone can follow through.