How to install Laravel on macOS

How to install Laravel on macOS

How to Install Laravel on macOS

Laravel is a popular PHP framework for web application development. This guide will help you install Laravel on your macOS system, covering everything from setting up your environment to creating your first Laravel project.

Prerequisites

Before you begin, ensure you have the following installed on your macOS:

  • Homebrew: A package manager for macOS.
  • PHP: Laravel requires PHP 7.3 or higher.
  • Composer: A dependency manager for PHP.

Step 1: Install Homebrew

If you haven’t installed Homebrew yet, open your terminal and run:

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

After installation, ensure Homebrew is updated:

brew update

Step 2: Install PHP

You can install PHP using Homebrew. Run the following command in your terminal:

brew install php

Verify your PHP installation:

php -v

Step 3: Install Composer

Composer is essential for managing Laravel dependencies. To install Composer, run:

curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

Check if Composer is installed:

composer -V

Step 4: Install Laravel

Now you can install Laravel globally via Composer. Run:

composer global require laravel/installer

Make sure to add Composer’s global bin directory to your PATH. You can do this by adding the following line to your .bash_profile, .zshrc, or .bashrc file (depending on your shell):

export PATH="$HOME/.composer/vendor/bin:$PATH"

After adding the line, run:

source ~/.bash_profile # or source ~/.zshrc

Verify that Laravel is installed:

laravel --version

Step 5: Create a New Laravel Project

To create a new Laravel project, navigate to the directory where you want to create your project and run:

laravel new my-laravel-app

Alternatively, you can use Composer to create a new project:

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

Change to your project directory:

cd my-laravel-app

Step 6: Serve Your Application

Laravel includes a built-in development server. Start the server with the following command:

php artisan serve

You should see an output indicating that your application is running. By default, it will be accessible at:

http://127.0.0.1:8000

Open this URL in your web browser, and you should see the Laravel welcome page!

Step 7: Configure Your Environment

Laravel uses a .env file to manage environment configurations. Open the .env file in your project directory to configure your database and other settings:

nano .env

Make any necessary changes (such as database configuration) and save the file.

Conclusion

🎉 Congratulations! You have successfully installed Laravel on macOS. You can now start building amazing web applications using Laravel.

💬 Need help or have questions? Let us know in the comments!

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close