


How to Fix the 'PHP Not Found' Error on macOS After Installing XAMPP
When macOS developers use XAMPP to set up a local development environment, they often encounter the frustrating "PHP not found" error. Even though XAMPP comes with PHP, the terminal may still not recognize the php command.
This article will guide you step by step to solve this problem and ensure that the system can find PHP.
Understanding error
Run the following command:
php -v
If you receive an error message like this:
<code>php not found</code>
This means that your system shell (such as zsh or bash) cannot find the PHP executable in its environment. This happens even though XAMPP contains its own PHP binary, because the directory containing PHP is not included in the shell's $PATH.
Let’s fix this problem!
Step 1: Find PHP in your XAMPP installation
XAMPP contains its own PHP installation, usually located in the following directory:
/Applications/XAMPP/xamppfiles/bin/php
To verify that the PHP executable exists in this location, run:
ls /Applications/XAMPP/xamppfiles/bin/php
If this command lists PHP files, you are on the right track.
Step 2: Add XAMPP’s PHP to your shell’s PATH
To make the PHP executable globally available, you need to add the XAMPP PHP directory to your shell's $PATH.
Zsh users (macOS default shell)
Starting with macOS Catalina, zsh is the default shell. Please follow these steps to update your $PATH:
- Open your .zshrc file:
nano ~/.zshrc
- Add the following line at the end of the file:
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
-
Press Ctrl O, then Enter, and finally Ctrl X to save and close the file.
-
Apply changes immediately by running the following command:
source ~/.zshrc
Bash users
If you are still using bash as your shell, edit .bash_profile:
nano ~/.bash_profile
Add the same line:
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Save and apply changes using:
source ~/.bash_profile
Step 3: Verify PHP installation
After updating $PATH, test whether the php command works:
php -v
You should see the version of PHP that comes with XAMPP, for example:
<code>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</code>
If it works, congratulations! Your system now recognizes the php command.
Step 4: Restart the terminal (optional)
If the above steps do not take effect immediately, please restart the terminal and try running php -v again. Sometimes changes to the shell configuration file require a terminal restart to take effect.
Alternative: Install PHP using Homebrew
If you prefer a system-wide PHP installation rather than relying on the bundled version of XAMPP, you can install PHP using Homebrew:
- If you don’t have Homebrew installed yet, please install:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install PHP:
brew install php
- Verify installation:
php -v
This will install the latest version of PHP and automatically configure your $PATH.
Conclusion
"PHP not found" errors can be quickly fixed once you understand how the shell's $PATH works. Whether you add XAMPP's PHP to your PATH or choose Homebrew, this guide will make sure you're up and running in no time. Now you can focus on what matters most – developing great apps!
Let us know in the comments if this guide was helpful, or share your tips for managing PHP on macOS!
The above is the detailed content of How to Fix the 'PHP Not Found' Error on macOS After Installing XAMPP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
