Table of Contents
Understanding error
Step 1: Find PHP in your XAMPP installation
Step 2: Add XAMPP’s PHP to your shell’s PATH
Zsh users (macOS default shell)
Bash users
Step 3: Verify PHP installation
Step 4: Restart the terminal (optional)
Alternative: Install PHP using Homebrew
Conclusion
Home Backend Development PHP Tutorial How to Fix the 'PHP Not Found' Error on macOS After Installing XAMPP

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

Jan 11, 2025 am 08:31 AM

How to Fix the

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
Copy after login
Copy after login
Copy after login

If you receive an error message like this:

<code>php not found</code>
Copy after login

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
Copy after login

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

ls /Applications/XAMPP/xamppfiles/bin/php
Copy after login

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:

  1. Open your .zshrc file:
nano ~/.zshrc
Copy after login
  1. Add the following line at the end of the file:
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Copy after login
Copy after login
  1. Press Ctrl O, then Enter, and finally Ctrl X to save and close the file.

  2. Apply changes immediately by running the following command:

source ~/.zshrc
Copy after login

Bash users

If you are still using bash as your shell, edit .bash_profile:

nano ~/.bash_profile
Copy after login

Add the same line:

export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Copy after login
Copy after login

Save and apply changes using:

source ~/.bash_profile
Copy after login

Step 3: Verify PHP installation

After updating $PATH, test whether the php command works:

php -v
Copy after login
Copy after login
Copy after login

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>
Copy after login

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:

  1. If you don’t have Homebrew installed yet, please install:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Copy after login
  1. Install PHP:
brew install php
Copy after login
  1. Verify installation:
php -v
Copy after login
Copy after login
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

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.

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

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 permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

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...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

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�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

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

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

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

See all articles