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:
After installation, ensure Homebrew is updated:
Step 2: Install PHP
You can install PHP using Homebrew. Run the following command in your terminal:
Verify your PHP installation:
Step 3: Install Composer
Composer is essential for managing Laravel dependencies. To install Composer, run:
Check if Composer is installed:
Step 4: Install Laravel
Now you can install Laravel globally via Composer. Run:
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):
After adding the line, run:
Verify that Laravel is installed:
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:
Alternatively, you can use Composer to create a new project:
Change to your project directory:
Step 6: Serve Your Application
Laravel includes a built-in development server. Start the server with the following command:
You should see an output indicating that your application is running. By default, it will be accessible at:
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:
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!