You know that PHP is a server-side scripting language.
But, You can execute the PHP script through the command prompt or terminal as well.
You are going to see:
Set-up Localhost Set-up Localhost
To execute the PHP on your computer you need the localhost environment.
You can install the:
- Local by Flywheel
If you already installed it then you can skip this step.
Check PHP is available in the command line Check PHP is available in the command line
To test the PHP is available with the command line.
- Open Terminal (CMD)
You can see something similar on the screen.
If you see an error like:
'php' is not recognized as internal or external command, operable program or batch file.
Try PHP with the Hello World example Try PHP with the Hello World example
I’m using the XAMPP, So, giving an example of XAMPP.
You can use any localhost server.
Step 1: Create a file
test.php in c:\xampp\htdocs\examples
Step 2: Copy and paste the below code into the file
<?php echo 'Hello World';
Step 3: Open a terminal or CMD (Command Prompt) and navigate to the examples directory.
Step 4: Execute the command
You can see Hello World on the terminal screen like: