Home  >  Article  >  How to install PHP on Windows 10 using Command Prompt

How to install PHP on Windows 10 using Command Prompt

WBOY
WBOYforward
2023-05-08 17:13:081333browse

Install PHP on Windows using Command Prompt or PowerShell

Install Chocolatey Choco Package Manager

I tried the Windows default package managerWinget but it didn't work Install PHP through it. So, the other best option left is to use the popular Chocolatey package manager.

But unlike Winget, Choco does not exist in our Windows system by default, so we need to install it manually on our system.

Go to your Windows 10 or 11 search box and type CMD, select "Run as administrator"## when it appears

#Copy and paste the given command on our

prompt to install Chocolatey package manager.

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey .org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Restart the system to allow the package manager to integrate correctly.

Commands to set up PHP on Windows 10/11

Now that we have the package manager, the next task is to use it to download and install PHP on Windows. This is the command to type:

choco install php

For the ThreadSafe version, if you plan to use PHP with Apache

choco install php --package-parameters='"/ThreadSafe ""/InstallDir:C:\PHP"""'。

Press

A and press Enter button and let Choco install all the packages needed to set up PHP.

The above command will install the latest version of PHP on Windows, however, those interested in some earlier versions can use the given syntax:

For example get php7.4

choco install php --version=7.4

Well, those who want to downgrade the latest version

to some previous version or plan on Windows 10 For those who have multiple versions of PHP installed on 11 or 11, you need to define a parameter using the Choco command.

For example:

Downgrade the latest version to some older version.

Assuming you already have 8.2 but now want to install the 7.4 version of PHP, the command parameters to add will be --allow-downgrade.<pre class="brush:bash;toolbar:false;">choco install php --version=7.4 --allow-downgrade</pre>

To install multiple versions of PHP side by side:

If you don't want to remove the current latest version from your PC, but also want to install some older versions, use this

- -side-by-side

parameter. <pre class="brush:bash;toolbar:false;">choco install php --version=7.4 --side-by-side</pre>Check PHP version Windows command

After downloading and installing PHP, confirm that it is configured correctly on Windows 10 or 11, we can run

php -v

to check its version and other details. <pre class="brush:bash;toolbar:false;">php -v</pre>To check for available or installed PHP extensions, use:

php -m

Php Information Page in Windows

Check for another version of PHP on Windows 11 or 10 One way is to use a single line of code that

phpinfo();

will display all the necessary information, including the extension and its version.

To do this, on your command prompt or terminal type:

notepad info.php
After that

paste

the following code and save and close the file.

如何在 Windows 10 上安装 PHP | 11 使用命令提示符Now, if you may not know, PHP comes with its own web server that we can use to test our PHP based applications. So, in the same
directory where you created info.php

run:

php -S localhost:8000

如何在 Windows 10 上安装 PHP | 11 使用命令提示符You will see PHP's built-in The web server will
start at your current Windows command prompt.

Now, open your browser and type :

http://localhost:8000/info.php
You will see details about the installed PHP

version.

The above is the detailed content of How to install PHP on Windows 10 using Command Prompt. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yundongfang.com. If there is any infringement, please contact admin@php.cn delete