How to Install Laravel and Create a New Project on macOS

How to Install Laravel and Create a New Project on macOS

 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:

laravel new my-app

but you see an error like:

zsh: command not found: laravel

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:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once installed, verify it:

brew --version

Step 2: Install PHP and Composer

Laravel requires PHP and Composer. Install them using Homebrew:

brew install php composer

After installation, check the versions to confirm successful installation:

php -v composer -V

Step 3: Install Laravel Installer

To install the Laravel installer globally, run:

composer global require laravel/installer

After installation, you need to add Composer’s global bin directory to your system path so you can run Laravel commands anywhere.

Run:

echo 'export PATH="$HOME/.composer/vendor/bin:$HOME/.config/composer/vendor/bin:$PATH"' >> ~/.zshrc source ~/.zshrc

Now check if Laravel is installed correctly:

laravel --version

Step 4: Create a New Laravel Project

Once Laravel is installed, you can create a new Laravel project.

Option 1: Using Laravel Installer

Run:

laravel new my-app

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:

composer create-project --prefer-dist laravel/laravel my-app

Step 5: Navigate to Your Project and Start the Server

Now, move into your Laravel project folder:

cd my-app

Run the Laravel development server:

php artisan serve

This will start a local web server, and you can access your Laravel app in your browser at:

http://127.0.0.1:8000

Step 6: (Optional) Install Laravel UI for React

If you want to use React with Laravel, install Laravel UI:

composer require laravel/ui

Then scaffold React:

php artisan ui react npm install && npm run dev

Conclusion

That's it! You’ve successfully installed Laravel on your Mac and created a new project. Now you can start building your application.

Souy Soeng

Souy Soeng

Hi there šŸ‘‹, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
šŸ‘Æ I’m looking to collaborate on open-source PHP & JavaScript projects
šŸ’¬ Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
close