Laravel PHP command not found
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Resolving Laravel PHP Command Not Found Issue in Terminal
Introduction: Laravel is an excellent PHP framework that enables developers to quickly create web applications using expressive syntax, powerful tools, and a robust ecosystem. While installing and managing Laravel with Composer can be smooth, the occasional issue of 'laravel' command not found can arise. In this comprehensive blog post, we will guide you through various solutions to solve this problem and ensure seamless Laravel development.
Body:
1. Ensure you have a valid Laravel installation with Composer
To begin troubleshooting the "laravel" command not found issue, make sure your Laravel framework is properly installed using Composer. Here's how to verify if everything is correct:
- Run the following command in your project directory: `composer create-project --prefer-dist laravel/laravel myapp` (Replace "myapp" with a name of your choice). This will install Laravel 5.x or higher and its dependencies inside a new directory called 'myapp'. It's essential to keep the project directory structure consistent with the convention used by Composer.
- Run `cd myapp` to navigate into the newly created Laravel application directory. You should see the project folder structure, files, and your app running on localhost:8000 upon executing `php artisan serve`.
2. Add ~/.composer/vendor/bin to your PATH environment variable
The most common reason for the "laravel" command not found error is that Laravel's executable files are not in your PATH environment variable. Follow these steps:
- Run `nano ~/.bash_profile` or `nano ~/.bashrc` (depending on your operating system) to open the shell configuration file. The bash_profile is for interactive login shells, while bashrc is for non-login shells like the terminal window.
- Add the following lines to the end of your chosen file:
`# Laravel Composer auto-loader
export PATH="$HOME/.composer/vendor/bin:$PATH"`
- Save and close the file. To make changes take effect, source the profile:
`source ~/.bash_profile` or `source ~/.bashrc`
3. Restart your terminal session to ensure environment variable changes are applied. Try running the "laravel" command again. If you still encounter issues, try one of these alternatives:
- Add a hard link to laravel binaries from Composer in the PATH by executing `ln -s $HOME/.composer/vendor/bin/laravel /usr/local/bin/laravel` (replace laravel with your preferred name or folder location). This approach ensures that your terminal can find and run Laravel commands.
- For Mac users, you may need to add the PATH environment variable in your ~/.bash_profile file by using `export PATH="$HOME/your-laravel-project-folder/vendor/bin:$PATH"`. Replace "your-laravel-project-folder" with the actual path of your Laravel project folder.
- For Windows users, you can add the vendor bin folder to the Windows environment variables by following Microsoft's guidelines on how to set environment variables in Windows.
4. Update Composer and Laravel package version
Sometimes, an issue with the laravel command not found error may be due to outdated versions of Composer or Laravel packages. To resolve this:
- Run `composer self-update` to ensure you have the latest Composer version installed on your system.
- Check if there's a new Laravel version by visiting https://laravel.com/docs/5.x/upgrade, where x refers to your current Laravel version. If a newer version is available, update using `composer global require "laravel/framework:~5.x"` (replace 5.x with the latest version). Remember to follow the appropriate upgrade steps as mentioned in the Laravel upgrade guide.
Conclusion:
The "laravel" command not found error can be frustrating, but by following these thorough troubleshooting steps, you'll be able to use Laravel effectively on your project. It's always good practice to ensure that your setup is up-to-date and well-configured for optimal performance. If you still encounter issues, consider reaching out to the Laravel community or check our blog for more helpful tips on Laravel development.