Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Terminal says laravel or php command not found after installing

Errorzsh: command not found: laravel

Short answer

The shell cannot find the program. For laravel, the installer lives in Composer's global bin directory, which is not on your PATH by default. Ask Composer for that path, add it to your shell profile, and open a new terminal. If php itself is missing, install PHP and Composer first.

  • Applies to Laravel installer 5, Composer 2, PHP 8.3, macOS, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which of the three tools the shell can see. The one that prints nothing is the missing one.

    command -v php composer laravel
  2. 2Match what you see, then jump to its fix

    1. 1command -v php or composer prints nothingPHP and Composer are not installedFix
    2. 2php and composer work, laravel does not, and the global bin folder has no laravel fileThe Laravel installer is not installedFix
    3. 3The laravel file exists in the global bin folder, but the shell still does not find itComposer's global bin directory is not on PATHFix

What does the error look like?

  • zsh: command not found: laravel
  • bash: laravel: command not found
  • zsh: command not found: php

Cause 1 of 3

PHP and Composer are not installed

1Check

Confirm with the version commands.

php -v
composer --version

2Fix

Install them. The Laravel docs give one script per system that installs PHP, Composer and the Laravel installer together. Restart the terminal afterwards. Laravel Herd is the graphical option on macOS and Windows.

# macOS
/bin/bash -c "$(curl -fsSL https://php.new/install/mac/8.4)"
# Linux
/bin/bash -c "$(curl -fsSL https://php.new/install/linux/8.4)"

3Verify

Open a new terminal and print the versions.

php -v
composer --version

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The Laravel installer is not installed

1Check

List Composer's global packages.

composer global show

2Fix

Install the installer globally with Composer.

composer global require laravel/installer

3Verify

The installer shows in the global list.

composer global show laravel/installer

Confirmed by laravel.com

Did this fix it?

Cause 3 of 3

Composer's global bin directory is not on PATH

1Check

Ask Composer for the absolute path of the global bin directory, then compare with your PATH.

composer global config bin-dir --absolute
echo $PATH | tr ':' '\n'

2Fix

Add the printed directory to PATH in your shell profile (~/.zshrc for zsh, ~/.bashrc for bash). Use the path your own machine printed; it depends on the system and on COMPOSER_HOME.

# ~/.zshrc  (uses the directory composer prints on your machine)
export PATH="$PATH:$(composer global config bin-dir --absolute --quiet)"

3Verify

Reload the profile, or open a new terminal, and run the command.

source ~/.zshrc
laravel --version

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Do not mix install methods (Herd, php.new, Homebrew); each puts its own binaries first on PATH.
  • After any PATH edit, open a new terminal before you test.
  • Create new projects with laravel new, or composer create-project, from outside an existing project.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Why a Filament panel feels slow on a Laravel server

The panel is fast on a small demo and slow once there are many resources, pages and widgets

A slow Filament panel on a server is most often running without the production caches.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.