How to Execute PHP File From Command Line

To Execute PHP File From Command Line, we can use 2 methods to execute PHP file code by PHP command,

  1. By using XAMPP Shell or Command line.
  2. Inbuilt command line of Windows OS.

Note: If you want to use inbuilt command line interface of Windows OS, you have install PHP manually from PHP official package. Here is the complete step by step process to install PHP How To Install PHP In Windows 10.

Execute PHP File Using XAMPP Shell

Steps to Execute PHP Code Using XAMPP Command Line

  • If you do not have XAMPP package, install from official site Download XAMPP (apachefriends.org)
  • Open XAMPP control panel by clicking on the icon.
  • Click on Shell option in sidebar of control panel.
  • It will open the command line then you go for file path by using CD command.
  • At last run the PHP file by using below PHP command.

XAMPP Shell for Run PHP Script
XAMPP Shell for Run PHP Script

Execute PHP File Using Inbuilt Command Line

Here are some major steps to execute PHP code using the Windows command line interface,

  • Install PHP by official PHP package How To Install PHP In Windows 10.
  • Set the path of PHP in environment variable at the time PHP installation.
  • Open CMD interface and run the below command.
Run PHP on Command Line Interface
Run PHP on Command Line Interface

Here is the complete step by step process of How to run the PHP file from the command line interface of Windows and XAMPP Shell.

If you get something error in implementation please comment below.

Also Read:

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.
Posts created 188

4 thoughts on “How to Execute PHP File From Command Line

Leave a Reply

Your email address will not be published.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top