How to Install Laravel and Create a New Project on macOS
If you're trying to create a new Laravel project on your Mac using the command:
but you see an error like:
it means Laravel is not installed globally on your system. Follow this step-by-step guide to install Laravel and start your new project.
Step 1: Install Homebrew (If Not Installed)
Homebrew is a package manager for macOS that helps install PHP and other dependencies easily.
Open your Terminal and run:
Once installed, verify it:
Step 2: Install PHP and Composer
Laravel requires PHP and Composer. Install them using Homebrew:
After installation, check the versions to confirm successful installation:
Step 3: Install Laravel Installer
To install the Laravel installer globally, run:
After installation, you need to add Composer’s global bin directory to your system path so you can run Laravel commands anywhere.
Run:
Now check if Laravel is installed correctly:
Step 4: Create a New Laravel Project
Once Laravel is installed, you can create a new Laravel project.
Option 1: Using Laravel Installer
Run:
This will generate a new Laravel project named my-react-app.
Option 2: Using Composer (If laravel new
Doesn't Work)
Alternatively, you can use Composer to create the project:
Step 5: Navigate to Your Project and Start the Server
Now, move into your Laravel project folder:
Run the Laravel development server:
This will start a local web server, and you can access your Laravel app in your browser at:
Step 6: (Optional) Install Laravel UI for React
If you want to use React with Laravel, install Laravel UI:
Then scaffold React:
Conclusion
That's it! You’ve successfully installed Laravel on your Mac and created a new project. Now you can start building your application.