Terminal says laravel or php command not found after installing
zsh: command not found: laravelShort 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.
Fix it fast
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 laravel2Match what you see, then jump to its fix
- 1
command -v php or composer prints nothingPHP and Composer are not installedFix - 2
php and composer work, laravel does not, and the global bin folder has no laravel fileThe Laravel installer is not installedFix - 3
The laravel file exists in the global bin folder, but the shell still does not find itComposer's global bin directory is not on PATHFix
- 1
What does the error look like?
zsh: command not found: laravelbash: laravel: command not foundzsh: command not found: php
Cause 1 of 3
PHP and Composer are not installed
1Check
Confirm with the version commands.
php -v
composer --version2Fix
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 --versionConfirmed by laravel.com
Cause 2 of 3
The Laravel installer is not installed
1Check
List Composer's global packages.
composer global show2Fix
Install the installer globally with Composer.
composer global require laravel/installer3Verify
The installer shows in the global list.
composer global show laravel/installerConfirmed by laravel.com
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 --versionConfirmed by getcomposer.org
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
The shell cannot find the composer command
bash: composer: command not found
The shell found no file named composer in any folder on your PATH.
4 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack 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 fixBack end
Intervention Image will not save the file in a Laravel app
Can't write image data to path (/var/www/app/public/uploads/photo.jpg)
Intervention Image writes straight to a file path.
3 causes, each with a fixBack end
Laravel file upload returns 413 behind nginx
413 Content Too Large
A 413 means a limit refused the request body before Laravel could use it.
3 causes, each with a fixBack end
Laravel says the bootstrap/cache directory must be present and writable
The /var/www/app/bootstrap/cache directory must be present and writable.
Laravel writes its package manifest into bootstrap/cache and throws when that folder is missing or the current user cannot write to it.
2 causes, each with a fix