php have a easy way to run a light server:
first cd into php file directory, then

php -S 127.0.0.1:8000

then you can run php

Answer from peter zhang on Stack Overflow
🌐
PHP
php.net › manual › en › features.commandline.usage.php
PHP: Usage - Manual
On Unix systems, the special #! (or "shebang") first line should be added to PHP scripts so that the system can automatically tell which program should run the script. On Windows platforms, it's possible to associate php.exe with the double click option of the .php extension, or a batch file can be created to run scripts through PHP.
Discussions

How to install php and run it?
I take it you're on a Windows system? Might try one of these all in one installers: https://www.wampserver.com/en/ (Apache, MySQL and PHP) https://www.apachefriends.org/index.html (Apache, MariaDB, PHP, & Perl) or just install things separately https://www.php.net/manual/en/install.windows.php More on reddit.com
🌐 r/PHPhelp
8
0
September 10, 2022
function - How can I execute PHP code from the command line? - Stack Overflow
doing function_exists() without ... out in other ways. What function do you want to test for? ... If you're going to do PHP in the command line, I recommend you install phpsh, a decent PHP shell. It's a lot more fun. Anyway, the php command offers two switches to execute code from the command line: -r Run PHP ... More on stackoverflow.com
🌐 stackoverflow.com
How to make PHP environment setup easier for developers
You mean like the php built-in dev server? https://www.php.net/manual/en/features.commandline.webserver.php More on reddit.com
🌐 r/PHP
63
43
February 6, 2024
Execute php file from another php - Stack Overflow
I want to call a PHP file that starts like I get: li... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

How do I run my PHP file?
PHP files are saved in C:/Program Files/XAMPP/htdocs. You have to open it, click on the program, and it will automatically run on localhost.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › how to run a php file using xampp: a step by step guide
How to Run a PHP File Using XAMPP: A Step By Step Guide
How to run PHP files in phpMyAdmin?
Login into PHPMyAdmin, then click on the import tab.  Browse the file with a .sql extension.  Keep in mind to check and uncheck some options.  Choose SQL format and click on Go.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › how to run a php file using xampp: a step by step guide
How to Run a PHP File Using XAMPP: A Step By Step Guide
🌐
Medium
sirolad.medium.com › six-easy-setup-for-local-php-development-beginners-cfbed13c851e
Six Easy Setups for Local PHP Development — Beginners | by Surajudeen Akande | Medium
October 31, 2019 - Just run cmd + I or Ctrl + I. Starting PHP server within Atom editor is easy by using this plugin. With this, you can easily spin up your server with few keys. See example below: I hope you found something of benefit from this simple post.
🌐
Envato Tuts+
code.tutsplus.com › home › php › php scripts
How to Run a PHP File | Envato Tuts+ - Code
April 30, 2020 - The preferred way of running PHP files is within a web server like Apache, Nginx, or IIS—this allows you to run PHP scripts from your browser. That’s how all PHP websites work! The other way is to run PHP scripts on the command line, and it doesn't require you to set up a web server.
🌐
Darwin Biler
darwinbiler.com › different-ways-to-run-php-on-webserver
What are the different ways to run PHP on Web Server? - Darwin Biler
November 22, 2024 - This is because Web servers usually runs on another user other than yours. For example, usually Apache user is "www-data", while your FTP account might be "bob". Two different users accessing same set of files causes a lot of headaches when you are using for example CMS like WordPress, which writes files into the server. On the following section, I'll try to elaborate the table above by mentioning special points like Pros, Cons and Bottomlines. ... mod_php is ideal for situations where resources is very limited and security is not much of concern.
🌐
Fayazmiraz
fayazmiraz.com › how-to-run-your-first-php-code
How to run PHP Program, CODE or File on Your own Computer?
November 13, 2023 - The easiest way to install & run PHP on your own computer is using a software like XAMPP. There are other similar software bundles like MAMP, WAMP etc.
Find elsewhere
🌐
Simplilearn
simplilearn.com › home › resources › software development › how to run a php file using xampp: a step by step guide
How to Run a PHP File Using XAMPP: A Step By Step Guide
July 31, 2025 - Check out the ways to run a PHP file using XAMPP. Explore what XAMPP is and how can it be installed on your system. Read on to know how to execute a PHP script!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Edureka
edureka.co › blog › how-to-run-a-php-program-in-xampp
How to Run a PHP program in Xampp? Step by Step Guide | Edureka
July 23, 2024 - Save your PHP code in a file with .php extension and run/host it on localhost using web servers like Apache. The PHP CLI can also be used for the same. We can use the php command followed by the file name to run the PHP script on command line.
🌐
Quora
quora.com › How-do-I-run-a-PHP-source-code
How to run a PHP source code - Quora
July 23, 2025 - Answer (1 of 3): To run any php file you need to install Apache web server on your localhost. Also you need to install MySQL server for any database programming. You can install these separately or there is easy way to achieve the same by installing ...
🌐
Medium
medium.com › @collinsigeh › running-php-locally-on-windows-without-installing-xampp-or-an-additional-server-9922c438f6c
Running PHP Locally on Windows Without Installing XAMPP or an Additional Server | by Collins Igeh | Medium
April 7, 2023 - A simple Google search came in handy and I discovered that version 5 and the latter versions of PHP come with a lightweight server by default. All that’s needed to run it is to type:
Top answer
1 of 7
315

If you're going to do PHP in the command line, I recommend you install phpsh, a decent PHP shell. It's a lot more fun.

Anyway, the php command offers two switches to execute code from the command line:

-r <code>        Run PHP <code> without using script tags <?..?>
-R <code>        Run PHP <code> for every input line

You can use php's -r switch as such:

php -r 'echo function_exists("foo") ? "yes" : "no";'

The above PHP command above should output no and returns 0 as you can see:

>>> php -r 'echo function_exists("foo") ? "yes" : "no";'
no
>>> echo $? # print the return value of the previous command
0

Another funny switch is php -a:

-a               Run as interactive shell

It's sort of lame compared to phpsh, but if you don't want to install the awesome interactive shell for PHP made by Facebook to get tab completion, history, and so on, then use -a as such:

>>> php -a
Interactive shell

php > echo function_exists("foo") ? "yes" : "no";
no

If it doesn't work on your box like on my boxes (tested on Ubuntu and Arch Linux), then probably your PHP setup is fuzzy or broken. If you run this command:

php -i | grep 'API'

You should see:

Server API => Command Line Interface

If you don't, this means that maybe another command will provides the CLI SAPI. Try php-cli; maybe it's a package or a command available in your OS.

If you do see that your php command uses the CLI (command-line interface) SAPI (Server API), then run php -h | grep code to find out which crazy switch - as this hasn't changed for year- allows to run code in your version/setup.

Another couple of examples, just to make sure it works on my boxes:

>>> php -r 'echo function_exists("sg_load") ? "yes" : "no";'
no
>>> php -r 'echo function_exists("print_r") ? "yes" : "no";'
yes

Also, note that it is possible that an extension is loaded in the CLI and not in the CGI or Apache SAPI. It is likely that several PHP SAPIs use different php.ini files, e.g., /etc/php/cli/php.ini vs. /etc/php/cgi/php.ini vs. /etc/php/apache/php.ini on a Gentoo Linux box. Find out which ini file is used with php -i | grep ini.

2 of 7
16

Using PHP from the command line

Use " instead of ' on Windows when using the CLI version with -r:

Correct

php -r "echo 1;"

Incorrect

php -r 'echo 1;'
  PHP Parse error:  syntax error, unexpected ''echo' (T_ENCAPSED_AND_WHITESPACE), expecting end of file in Command line code on line 1

Don't forget the semicolon to close the line (otherwise, the result is "PHP Parse error: syntax error, unexpected end of file, expecting ';' or ',' in Command line code on line 1").

🌐
WPWeb Infotech
wpwebinfotech.com › wpweb infotech › blog › php › run php in visual studio code: easy setup & debugging tips
How To Run PHP In Visual Studio Code?
December 30, 2025 - Integrated Terminal: VS Code includes a powerful integrated terminal. With it, you can run PHP scripts, Composer commands, and other shell commands directly within the editor. Git Integration: Excellent built-in Git support for version control. That makes it easy to commit, push, pull, and manage branches for your PHP projects.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-run-php-programs
How to run PHP programs ? - GeeksforGeeks
July 23, 2025 - ... To run PHP programs, you need to set up a suitable environment, either locally or on a live web server. For local development, you can install server packages like XAMPP, WAMP, or MAMP, which provide PHP, Apache, and MySQL in one installation.
🌐
Reddit
reddit.com › r/php › how to make php environment setup easier for developers
r/PHP on Reddit: How to make PHP environment setup easier for developers
February 6, 2024 -

After installing PHP locally and running composer install, is it possible to have a development setup similar to “yarn start:dev” for Node, but in PHP without the use of Nginx and php-fpm?

Usually I would need to have a docker-compose.yml containing a docker image in the project file. The docker image is production ready and ends up being deployed to kubenetes, but sometimes it’s difficult for other developers to run cli/console commands, especially those who come from a Node background (as you’d need to bash/shell into the container).

It would be easier if users could start a PHP development environment and the necessary extensions by running an executable, without the use of a docker container. Or would it be easier to have the production container run without nginx and php-fpm?

Does a solution exist?

🌐
UiPath Community
forum.uipath.com › help › studio
How to run file .php in CMD? - Studio - UiPath Community Forum
March 10, 2023 - Hi Everyone, I have a PHP project which includes multiple PHP files and a main PHP file. i would like to execute the main PHP file using the Command Prompt (CMD) in Windows. This main PHP file accepts certain arguments …