Here is a simple way to install the PHP
and run the script files on Windows
Environment. in the installation process we'll use the Chocolatey Windows Package Manager which contain about 8785 free community maintained packages, that can be searched and listed here https://community.chocolatey.org/packages.
And we can do it as following…
Now Run Windows PowerShell as an Administrator by:
Press Win Key + R. so a small window will pop up as shown in the screenshot below
Type in the popup window powershell
, then press Ctrl+Shift+Enter or press OK While hold Ctrl+Shift.
1- Install Chocolatey Windows Package Manager
PowerShell
Run The Following Commands to install Chocolatey Windows Package Manager.PowerShell
, by run Get-ExecutionPolicy
command as shown:If not return AllSigned
i.e. Restricted, so we'll need to run the command Set-ExecutionPolicy AllSigned
or Set-ExecutionPolicy Bypass -Scope Process
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
PHP
and Composer
2- Installation PHP Package
choco install php
PS C:\> choco install php Chocolatey v0.11.3 Installing the following packages: php By installing, you accept licenses for the packages. Progress: Downloading php 8.0.10... 100% php v8.0.10 [Approved] php package files install completed. Performing other installation steps. The package php wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): yes Extracting 64-bit C:\ProgramData\chocolatey\lib\php\tools\php-8.0.10-nts-Win32-vs16-x64.zip to C:\tools\php80... C:\tools\php80 PATH environment variable does not have C:\tools\php80 in it. Adding... Creating default php.ini Configuring PHP extensions directory Please make sure you have CGI installed in IIS for local hosting Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type `refreshenv`). The install of php was successful. Software installed to 'C:\tools\php80' Chocolatey installed 1/1 packages. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
The installation path is C:\tools\php80
, and after installation successfully completed, the PHP command will be inserted to the Windows Environment Vars Path Automatically, so can run from any where any terminal.
3- Installation PHP Composer Package For Windows
To install PIP we need to run the command choco install composer
The Windows Environment Vars PATH
will updated too, so you can use composer command in any terminal.
4- Run and Testing PHP Script File
Write a simple hello world script file in working test directory with name hello.php
echo 'echo: Hello World!';
Then run the PHP
script file using the command PHP
with -f
for file Parse and execute, as
> php -f hello.php
And to get the usage PHP
version you can run php --version
in the terminal.
PS C:\tools\test> php --version PHP 8.0.10 (cli) (built: Aug 25 2021 08:46:14) ( NTS Visual C++ 2019 x64 ) Copyright (c) The PHP Group Zend Engine v4.0.10, Copyright (c) Zend Technologies
5- Run And Test PHP Script file In Browser
And for live script testing we can using the PHP built-in web server, and starting a local lightweight server by run php -S localhost:[PORT] -t [DocumentDirectory]
> php -S localhost:8888 -t c:\tools\test\
As Shown, the document directory contain the file hello.php
file with the code script to display the php information.
phpinfo();
And it will be displayed the PHP info when browse to http://localhost:8888/hello.php
If you need help for installing Python
, and PIP
on Windows, Please go to the Post A Simple Way To Installing And Run Python And PIP On Windows.