
Title: Troubleshooting “php artisan serve” Command: ‘php’ is not recognized
Introduction: Running into the error “The term ‘php’ is not recognized as the name of a cmdlet, function, script file, or operable program” when trying to use the php artisan serve command in Laravel can be frustrating. This issue is commonly encountered on Windows systems, and it is typically due to the PHP executable not being recognized in the system environment.
php : The term 'php' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ php artisan serve
+ ~~~
    + CategoryInfo          : ObjectNotFound: (php:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
- PHP not in the System PATH:
- The PHP executable is not added to the system’s PATH variable, preventing the command prompt from recognizing the ‘php’ command.
 
Solution:
Option 1: Add PHP to the System PATH
Step 1: Find PHP Installation Directory
- Locate the directory where PHP is installed. Common paths include C:\xampp\phporC:\wamp\bin\php\phpx.x.x.
Step 2: Add PHP to the System PATH
- Right-click on “This PC” or “Computer” on your desktop or in File Explorer.
- Select “Properties.”
- Click on “Advanced system settings” on the left.
- Click the “Environment Variables” button.
- In the “System variables” section, select the “Path” variable, then click “Edit.”
- Click “New” and add the path to the PHP executable (e.g., C:\xampp\php).
Step 3: Open a New Command Prompt
- Close any existing command prompt windows and open a new one to apply the changes.
Step 4: Retry the Artisan Command
- Run php artisan serveagain in the command prompt.
Option 2: Use the PHP Executable Directly
Step 1: Use Full Path to PHP Executable
- Run the php artisan servecommand with the full path to the PHP executable:
"C:\xampp\php\php.exe" artisan serve
Replace "C:\xampp\php\php.exe" with the actual path to your PHP executable.
After this you still getting the same error then check your composer. If there is no composer then install composer