Skip to content

How to Install Laravel with MAMP on macOS

Laravel is one of the most popular PHP frameworks, known for its elegant syntax and powerful tools. In this guide, I’ll walk you through setting up Laravel on macOS using MAMP, starting from zero. By the end of this tutorial, you’ll have a fully functioning Laravel development environment.

What is MAMP?

MAMP is a free, local server environment that includes Apache, MySQL, and PHP, all pre-configured and ready to go. It’s an excellent choice for developing PHP applications on macOS.

Step 1: Install MAMP

First, let’s start by installing MAMP on your Mac.

  1. Download MAMP:
    • Visit the MAMP website and download the latest version for macOS.
    • Once downloaded, open the installer and follow the on-screen instructions to install MAMP on your machine.
  2. Launch MAMP:
    • After installation, open MAMP from your Applications folder.
    • Start the servers by clicking “Start Servers” in the MAMP control panel.

Step 2: Install Composer

Composer is a dependency manager for PHP, essential for installing Laravel.

  1. Open Terminal:
    • You can find Terminal in your Applications > Utilities folder or simply search for it using Spotlight (Cmd + Space).
  2. Install Composer:
    • First, check if PHP is installed by typing php -v. If you get an error that PHP is not found, follow the steps below to configure PHP with MAMP.
    • To install Composer, run the following command:
      curl -sS https://getcomposer.org/installer | php
      sudo mv composer.phar /usr/local/bin/composer
    • Verify the installation by typing:
      composer --version
    • If you see the Composer version, you’re good to go!

Step 3: Set Up PHP in Your Terminal

MAMP comes with PHP, but your Terminal may not recognize it by default. Let’s fix that.

  1. Find MAMP’s PHP Path:
    • MAMP installs PHP in its own directory, typically something like this:
      /Applications/MAMP/bin/php/php[version]/bin/php
    • Replace [version] with the PHP version you want to use, like php8.2.0.
  2. Add PHP to Your PATH:
    • Open your Terminal and type:
      nano ~/.zshrc
    • Add the following line at the end of the file, replacing [version] with the correct PHP version:
      export PATH="/Applications/MAMP/bin/php/php[version]/bin:$PATH"
    • Save and exit (Ctrl + O, Enter, then Ctrl + X).
    • Apply the changes by running:
      source ~/.zshrc
    • Now, typing php -v should display the PHP version from MAMP.

Step 4: Create a New Laravel Project

Now that Composer is installed and PHP is configured, let’s create a new Laravel project.

  1. Navigate to Your Web Directory:
    • MAMP’s default web root is located at /Applications/MAMP/htdocs. You can also set up a custom directory (e.g., ~/Sites) through MAMP’s Preferences.
    • In Terminal, navigate to your chosen web directory:
      cd /Applications/MAMP/htdocs
  2. Create a New Laravel Project:
    • Run the following command to create a new Laravel project:
      composer create-project --prefer-dist laravel/laravel myProject
    • Replace myProject with your desired project name. Composer will download Laravel and its dependencies.

Conclusion

Setting up a development environment on macOS with MAMP and Laravel is straightforward once you get the hang of it. With this environment, you can now start building your web application using one of the most powerful PHP frameworks available.

Before diving into development, you’ll need to configure a database for your Laravel application. This involves setting up a database through MAMP and connecting it to Laravel via the .env file. While it’s straightforward, it’s a crucial step to ensure your application runs smoothly.

In a future article, I’ll explain how to set up a virtual host for your Laravel project. Virtual hosts are important because they allow you to access your project using a custom local domain, making your development process more professional and organized.

Stay tuned for the next article, where we’ll cover these topics in detail. If you have any questions or run into any issues, feel free to leave a comment below. Happy coding!