- Open Environment Variables in Windows
- Add PHP or Python to your PATH variable
- How to check if PHP or Python is already in your PATH (before adding it /to avoid duplicates)
1) INSTALLING PHP or Python via Command Line Interface (CLI) on Windows
Guide to installing PHP and Python via Command Line Interface (CLI) on Windows, step-by-step, no GUI needed.
🐘 INSTALL PHP via CLI
1️⃣ Download PHP (latest stable version)
Open PowerShell (Run as Administrator) and run:
curl -LO https://windows.php.net/downloads/releases/php-8.3.12-Win32-vs16-x64.zip
(You can check the latest version at https://windows.php.net/download/)
2️⃣ Extract the ZIP file
mkdir C:\php
tar -xf php-8.3.12-Win32-vs16-x64.zip -C C:\php
3️⃣ Add PHP to PATH
setx PATH "%PATH%;C:\php"
Then close and reopen PowerShell or CMD.
4️⃣ Verify PHP installation
php -v
You should see something like:
PHP 8.3.12 (cli) (built: Sep 2025)
✅ PHP is ready for CLI use.
🐍 INSTALL PYTHON via CLI
1️⃣ Download Python (latest stable Windows installer)
curl -LO https://www.python.org/ftp/python/3.12.6/python-3.12.6-amd64.exe
(You can replace the version with the latest one from https://www.python.org/downloads/windows/)
2️⃣ Run the installer silently (no GUI)
Start-Process python-3.12.6-amd64.exe -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1 Include_test=0" -Wait
🧩 This installs Python for all users and adds it to PATH automatically.
3️⃣ Verify Python installation
python --version
or
py --version
✅ You should see something like:
Python 3.12.6
🔧 Quick Summary Table
| Tool | Details | Logo |
|---|---|---|
| PHP |
Download:curl -LO https://windows.php.net/downloads/releases/php-8.3.12-Win32-vs16-x64.zipInstall Location: C:\phpPATH Command: setx PATH "%PATH%;C:\php"Verify: php -v
|
|
| Python |
Download:curl -LO https://www.python.org/ftp/python/3.12.6/python-3.12.6-amd64.exeInstall Location: C:\Program Files\Python312PATH Command: (auto) Verify: python --version
|
|
2) CONFIGURING/PATH-SETTING (so that being able to run php or python from any folder)
A. Here are several ways to open Environment Variables in Windows 👇
🧭 Method 1: Through System Properties
-
Right-click on This PC (or My Computer) → select Properties.
-
Click Advanced system settings (on the left sidebar).
-
In the System Properties window, under the Advanced tab, click Environment Variables….
✅ This opens the Environment Variables window.
⚙️ Method 2: Using Windows Search
-
Press Windows + S and type:
environment variables -
Choose “Edit the system environment variables” or “Edit environment variables for your account.”
🏃 Method 3: From Run Command
-
Press Windows + R
-
Type:
SystemPropertiesAdvanced -
Hit Enter → click Environment Variables button.
💻 Method 4: From Command Prompt / PowerShell
-
You can open the same window by running:
rundll32 sysdm.cpl,EditEnvironmentVariablesor
SystemPropertiesAdvanced→ then click Environment Variables.
2) CONFIGURING/PATH-SETTING (so that being able to run php or python from any folder)
B. How to add PHP or Python to your PATH variable (so you can run php or python from any folder)!
🧭 Method 1: Using the Windows GUI
✅ Steps:
-
Press Windows + S and search for
➤ “Environment Variables”
Then choose “Edit the system environment variables”. -
In the window that opens, click the Environment Variables… button.
-
Under System variables, find and select Path, then click Edit.
-
Click New, then add your folder path:
-
For PHP →
C:\php -
For Python →
C:\Python39(or whatever version you have)
-
-
Click OK → OK → OK again.
-
Restart Command Prompt or PowerShell for changes to take effect.
-
Test it:
php -vor
python --version
⚙️ Method 2: Using Command Line
You can also add it via CLI (Command Prompt or PowerShell):
➤ For PHP
setx PATH "%PATH%;C:\php"
➤ For Python
setx PATH "%PATH%;C:\Python39"
(Replace C:\Python39 with your actual Python folder.)
After running that command, close and reopen your terminal.
Then test:
php -v
or
python --version
🧩 Quick Tip:
If PHP or Python is installed in a folder with spaces (like C:\Program Files\PHP), wrap it in quotes:
setx PATH "%PATH%;\"C:\Program Files\PHP\""
2) CONFIGURING/PATH-SETTING (so that being able to run php or python from any folder)
C. How to check if PHP or Python is already in your PATH (before adding it /to avoid duplicates)!
🧭 Method 1: Using Command Prompt
✅ Check current PATH
echo %PATH%
This will print a long list of folders separated by semicolons ;.
👉 Look through it and see if you can find:
-
C:\php -
C:\Python39(or another version, likeC:\Users\<YourName>\AppData\Local\Programs\Python\Python312)
If you find one — that means PHP or Python is already in your PATH.
⚙️ Method 2: Using PowerShell (cleaner view)
Run:
$env:PATH -split ';'
This splits the PATH into one line per folder.
You’ll easily see if C:\php or C:\Python39 is listed.
🧰 Method 3: Check Directly via the Command
You can also test whether the command is recognized globally.
For PHP:
where php
For Python:
where python
If you get an output like:
C:\php\php.exe
or
C:\Python39\python.exe
✅ It means that program is already in your PATH.
If it says:
INFO: Could not find files for the given pattern(s).
❌ It means it’s not in PATH yet.
3) RUNNING a PHP/Python file via the Command Line Interface (CLI)
How to run a PHP file via the Command Line Interface (CLI) 👇
⚙️ 1. Make sure PHP is installed and in PATH
Test first:
php -v
✅ If you see version info (e.g. PHP 8.3.12), you’re ready.
❌ If not, check your installation or PATH variable (see previous steps).
📂 2. Navigate to your PHP file’s folder
Use cd (change directory). Example:
cd C:\projects\myapp
If your file is at C:\projects\myapp\test.php, you can also drag the folder into the terminal to auto-fill the path.
▶️ 3. Run the PHP script
Type:
php test.php
or use a full path:
php C:\projects\myapp\test.php
🧩 4. Optional: Make It Executable (with .bat wrapper)
If you want to run it like a normal .exe or command (without typing php each time):
-
Create a new text file named
run-php.bat -
Inside it, write:
@echo off php "%~dp0yourfile.php" %* pause -
Save and double-click
run-php.bat— it will execute your PHP file using PHP CLI.
💡 5. If the script outputs HTML (for web use)
You can preview it locally by running PHP’s built-in web server:
php -S localhost:8000
Then open http://localhost:8000 in your browser.
Comments