Logo

dev-resources.site

for different kinds of informations.

How to Fix the "PHP Not Found" Error on macOS After Installing XAMPP

Published at
1/10/2025
Categories
webdev
developers
php
laravel
Author
saint_vandora
Categories
4 categories in total
webdev
open
developers
open
php
open
laravel
open
Author
13 person written this
saint_vandora
open
How to Fix the "PHP Not Found" Error on macOS After Installing XAMPP

If you’re a developer working on macOS and you’ve installed XAMPP to set up your local development environment, encountering the “PHP not found” error can be frustrating. Even though XAMPP includes PHP, your terminal might still not recognize the php command.

This article walks you through how to resolve this issue step by step and ensure your system knows where to find PHP.

Understanding the Error

When you run the following command:

php -v
Enter fullscreen mode Exit fullscreen mode

and get an error message like this:

php not found
Enter fullscreen mode Exit fullscreen mode

it means your system’s shell (like zsh or bash) cannot locate the PHP executable in its environment. This happens because the directory containing PHP is not included in your shell’s $PATH, even though XAMPP includes its own PHP binary.

Let’s fix that!

Step 1: Locate PHP in Your XAMPP Installation

XAMPP includes its own PHP installation, which is usually located in the following directory:

/Applications/XAMPP/xamppfiles/bin/php
Enter fullscreen mode Exit fullscreen mode

To verify that the PHP executable exists in this location, run:

ls /Applications/XAMPP/xamppfiles/bin/php
Enter fullscreen mode Exit fullscreen mode

If this command lists the PHP file, you’re on the right track.

Step 2: Add XAMPP’s PHP to Your Shell’s PATH

To make the PHP executable accessible globally, you need to add the XAMPP PHP directory to your shell’s $PATH.

For Zsh Users (macOS Default Shell)

Starting with macOS Catalina, zsh is the default shell. Follow these steps to update your $PATH:

1.Open your .zshrc file:

   nano ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

2.Add the following line at the end of the file:

   export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

3.Save and close the file by pressing Ctrl+O, then Enter, and Ctrl+X.

4.Apply the changes immediately by running:

   source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

For Bash Users

If you’re still using bash as your shell, edit the .bash_profile instead:

nano ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Add the same line:

export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

Save and apply changes using:

source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify PHP Installation

After updating your $PATH, test if the php command now works:

php -v
Enter fullscreen mode Exit fullscreen mode

You should see the PHP version that comes with XAMPP, for example:

PHP 8.2.4 (cli) (built: Apr  6 2023 04:12:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.4, Copyright (c) Zend Technologies
Enter fullscreen mode Exit fullscreen mode

If this works, congratulations! Your system now recognizes the php command.

Step 4: Restart Terminal (Optional)

If the above steps don’t work immediately, restart your terminal and try running php -v again. Sometimes, changes to the shell configuration file require a terminal restart to take effect.

Alternative: Use Homebrew for PHP

If you prefer a system-wide installation of PHP instead of relying on XAMPP’s bundled version, you can install PHP using Homebrew:

1.Install Homebrew if you haven’t already:

   /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

2.Install PHP:

   brew install php
Enter fullscreen mode Exit fullscreen mode

3.Verify the installation:

   php -v
Enter fullscreen mode Exit fullscreen mode

This will install the latest version of PHP and automatically configure your $PATH.

Conclusion

The “PHP not found” error can be a quick fix once you understand how your shell’s $PATH works. Whether you’re adding XAMPP’s PHP to your PATH or opting for Homebrew, this guide ensures you’ll be up and running in no time. Now, you can focus on what matters most—developing great applications!

Let us know in the comments if this guide helped you, or share your tips for managing PHP on macOS!

laravel Article's
30 articles in total
Favicon
Serve a Laravel project on Web, Desktop and Mobile with Tauri
Favicon
Host Header Injection in Laravel: Risks and Prevention
Favicon
Laravel 11.30: A Leap Forward in Testing, Model IDs, and Authorization
Favicon
How to Effectively Manage Laravel Request Validation?
Favicon
[Boost]
Favicon
Building a Quick CSV Export Command in Laravel
Favicon
Deploy laravel application using vercel : Amazing
Favicon
How to Image Upload with CKeditor in Laravel 11 Tutorial
Favicon
How to Install and Use Trix Editor in Laravel 11
Favicon
Testing Temporary URLs in Laravel Storage
Favicon
API Vulnerabilities in Laravel: Identify & Secure Your Endpoints
Favicon
Enforcing Strong Passwords in Laravel
Favicon
Beyond MVC: Redefining Backend Development with DataForge
Favicon
From Product Manager to Independent Developer: A Six-Month Transformation Guide
Favicon
"PHP is dead⚰️" .. what's next? Is Laravel worth it? 😎
Favicon
LTS as a Business: How an Old Project Can Become the Foundation for a New Business Model
Favicon
How to Fix the "PHP Not Found" Error on macOS After Installing XAMPP
Favicon
Sending logs to Telegram. Module for Laravel
Favicon
Need someone to contribute in writing test code for my open source project
Favicon
6 Steps to Master PHPUnit Testing with Ease!
Favicon
How to Create a Reusable Laravel Admin Panel for Multiple Projects
Favicon
Day 6: Building APIs with Laravel Sanctum
Favicon
Fix Insufficient Logging & Monitoring in Laravel Easily
Favicon
🎉 Simplify Laravel CRUD Operations with Ease! 🚀
Favicon
Laravel IQ - Level 1 - Part 2
Favicon
Different ways to use where() in Laravel
Favicon
Laravel IQ - Level 1 - Part 1
Favicon
Leveraging Social Media to Attract Top PHP Developers
Favicon
Laravel Eloquent ORM in Bangla Part-3 (Models Retrieving)
Favicon
How to Build a Generic CRUD Controller in Laravel for Multiple Resources

Featured ones: