Install PHP on Windows
Prerequisite and running on your Windows system, else you will not be able to run PHP Scripts.
Alternatively, you can install WAMP server or AMPPS server to install PHP, MySQL, and Apache Web Server on your Windows machine.
Options for installing PHP on Windows
- You can install php on windows manually.
- You can run the .msi package, i.e. windows installer for php to install php.
- Besides full installation, you can install php extensions on an existing installation of PHP.
- You can upgrade to a higher version of PHP from an existing version.
Install PHP on Windows manually
You have to download zipped binary version of PHP from http://www.php.net/downloads.php.
Extract the downloaded file to php folder which must be created at the root of any of your windows drives (e.g. c:\php or d:\php).
Enter php folder and rename the file php.ini-recommonded to php.ini.
Open the file php.ini with any text editor and find extension_dir within the file.
Change the extension directory, i.e. if you have installed php in php folder of D drive, setting will be extension_dir=D:\php.
Now you open Environment Variables (MyComputer -> System Properties -> Environment Variables), under system variables, select Path and click Edit,
in the Variable value, go to the end of the list and put a semicolon, then add D:\php;D:\php\ext assuming D:\php is the location of your php installation.
Then Click on New under system variable and add PHPRC against Variable name and D:\php against Variable value.
Install PHP on Windows using Windows installer
Simply run the .msi Windows installer file and follow the installation wizard.
Testing if PHP is installed properly
Create a php file containing code and save it as test.php.
Run this file on your web server and if you get an output like this:
then you have installed PHP properly.
Install PHP extensions on Windows
What is a PHP extension?
A PHP extension is a piece of code which is not part of the core PHP and you need it to explore certain functionalities of PHP (e.g. for using mysql you need mysql extension of PHP).
Many extensions are available out of the box in the PHP installer downloaded from php.net or in the .msi package. But many need to be obtained separately from php.net.
In Windows, extensions come in the form of a .dll file which you can download from php.net.
How do you configure an extension on Windows?
You need to change the setting of extension dir in php.ini file. For example, If you are using PHP 5.0.3, and you have installed php in c:\php, then you have to set extension_dir = C:\php\ext in your php.ini file.
After downloading the files needed, you have to open php.ini and enable a line pointing to an extension in question.
For enabling extensions, you have to uncomment a line in your php.ini file. For example, for enabling mysql extension, you have to change; extension = php_mysql.dll to extension = php_mysql.dll in your php.ini file.
You also need to restart your web server and php in order to complete the installation of a specific extension.
Sample php.ini
Previous: PHP Home
Next: Install php on Linux
Follow us on Facebook and Twitter for latest update.
Will php run on windows
This section contains notes and hints specific to getting PHP running from the command line for Windows.
Getting PHP to run from the command line can be performed without making any changes to Windows.
C:\php\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3
But there are some easy steps that can be followed to make this simpler. Some of these steps should already have been taken, but are repeated here to be able to provide a complete step-by-step sequence.
Note:
Both PATH and PATHEXT are important pre-existing system variables in Windows, and care should be taken to not overwrite either variable, only to add to them.
Note: The position in which you place the .PHP will determine which script or program is executed when there are matching filenames. For example, placing .PHP before .BAT will cause your script to run, rather than the batch file, if there is a batch file with the same name.
ftype phpfile="C:\php\php.exe" -f "%1" -- %~2
Following these steps will allow PHP scripts to be run from any directory without the need to type the PHP executable or the .PHP extension and all parameters will be supplied to the script for processing.
The example below details some of the registry changes that can be made manually.
Example #1 Registry changes
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.php] @="phpfile" "Content Type"="application/php" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile] @="PHP Script" "EditFlags"=dword:00000000 "BrowserFlags"=dword:00000008 "AlwaysShowExt"="" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\DefaultIcon] @="C:\\php\\php-win.exe,0" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell] @="Open" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open] @="&Open" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open\command] @="\"C:\\php\\php.exe\" -f \"%1\" -- %~2"
With these changes the same command can be written as:
"C:\PHP Scripts\script" -arg1 -arg2 -arg3
Note:
There is a small problem if you intend to use this technique and use your PHP scripts as a command line filter, like the example below:
dir | "C:\PHP Scripts\script" -arg1 -arg2 -arg3
dir | script -arg1 -arg2 -arg3
You may find that the script simply hangs and nothing is output. To get this operational, you need to make another registry change.
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer] "InheritConsoleHandles"=dword:00000001
Further information regarding this issue can be found in this » Microsoft Knowledgebase Article : 321788. As of Windows 10, this setting seems to be reversed, making the default install of Windows 10 support inherited console handles automatically. This » Microsoft forum post provides the explanation.
How to Install PHP on Windows 11
If you’re into web development then it’s likely that you will need to learn PHP to develop the back-end database of your website. And nowadays web development is going in a craze. Therefore today we’re going to show you How to Install PHP on Windows 11. Follow this tutorial step by step and you’ll be good to go.
Video Tutorial: How to Install PHP on Windows 11
Step 1: Download PHP For Windows 11
1) Firstly we will download the latest version of PHP available on the internet. Follow the below-provided link to download PHP for window 11. There simply click on the Zip button under PHP 8.0(8.0.9) section.
Step 2: Extract Zip File
1) Open up the folder where the downloaded .zip file is available, right-click on the file and click on the Extract All button.
2) In the extraction window click on the Browse button.
3) And create a New Folder with the name PHP8 . After that click on the Select Folder button.
4) Now in the extraction window simply click on the Extract button.
Step 3: Set Up Environment Variables
1) Press Windows button, type Environment Variabl es and hit Enter.
2) Now click on the Environment Variable button.
3) Now, select the Path variable by simply clicking on it and after that click on the Edit button.
4) Now click on the New button and paste the location we’ve provided below in this blank field and click the Ok button.
Location: C:\php8
Step 4: Check PHP Version
1) To check if PHP is installed properly or not, open up your command prompt by pressing the Windows button, type cmd and press enter.
2) In the command prompt type, php —version and press enter to check the installed version of PHP.
Ethix
I’m a coding geek interested in cyberspace who loves to write and read