Problems installing laravel with composer
You have successfully installed Composer globally and verified that the CLI tool works, yet you are hitting a command not found error when trying to invoke the Laravel installer. This specific issue stems from how your operating system handles executable paths. The error message bash: laravel: command not found indicates that the shell cannot locate the binary file responsible for installing the framework.
The solution lies in understanding the difference between a global PHP installation and a local Composer vendor directory. When you run composer global require "laravel/installer=~1.1", Composer creates a directory structure in your home folder, typically at ~/.composer/vendor/bin. Inside this directory sits the laravel executable script.
The core problem is that your current shell session does not know where to find this new binary. By default, macOS and Linux only search for executables in specific system directories (like /usr/local/bin) or directories explicitly added to the PATH environment variable. The ~/.composer/vendor/bin directory is not part of the standard path.
To resolve this, you must manually add the path to that directory to your shell configuration file. This process involves editing a file like .zshrc (for macOS with Zsh) or .bash_profile (for Bash). You need to append a line that prepends the vendor bin directory to your existing PATH:
export PATH="$HOME/.composer/vendor/bin:$PATH"
After saving this change, you must reload your shell configuration for it to take effect. If you are using Zsh on macOS, run source ~/.zshrc. For Bash, use source ~/.bash_profile or simply log out and log back in. Once the environment variable is updated, running composer will again display the logo, but now laravel should also be recognized as a valid command.
Creating the Project Locally
Once the executable is accessible system-wide, you can proceed to create your project in the desired location. Your goal is to install Laravel into HomeFolder/sites/test. The standard Composer workflow for this is:
composer create-project laravel/laravel sites/test
Note that while older documentation suggested using php composer.phar ... or relying on a global installer command, the modern and preferred approach is to use create-project. This command ensures that Composer handles both downloading the framework source code and installing its dependencies into a dedicated vendor folder within your project directory. It isolates the project's requirements from any global versions of PHP packages you might have installed elsewhere.
Understanding the Trade-offs
It is important to distinguish between global and local installations. Global installs are useful for CLI tools that need to be available anywhere on your machine, like laravel or php artisan. However, if you intend to run multiple projects with different dependency versions, a global installation can lead to conflicts. For example, one project might require PHP 8.0 while another requires PHP 7.4; mixing these in a global environment is risky.
The recommended practice for professional development is often to use Composer locally within each project directory. However, the Laravel installer (laravel/installer) is frequently installed globally to save typing commands like php artisan install:default during setup. As long as your PATH is correctly configured, having the global installer does not hinder the ability to create isolated local projects using create-project.
If you encounter issues with PHP configurations mentioned in forums, such as updating php.ini, be cautious. Most Composer and Laravel installation errors related to missing commands are purely path-related, not configuration-related. Changing PHP extensions or settings is rarely the solution for a "command not found" error unless the underlying PHP binary itself is broken. Stick to fixing the environment variables first before investigating deeper configuration files.
For further reading on managing your development environment and best practices for Laravel deployment, you might find additional resources at https://laravelcompany.com.