Set Up Virtual Hosts on Free MAMP

Learn how to install and configure the free version of MAMP on your Mac for a seamless local development experience with CodeIgniter 4.

published on 29 Mar 2025 in PHPWeb DevelopmentCodeIgniter

In this tutorial, we'll guide you through setting up a robust local development environment for your CodeIgniter 4 applications using the free version of MAMP on macOS. This setup is also ideal for Laravel and any modern PHP framework relying on a public folder architecture. No need for MAMP Pro - we'll show you how to get a professional setup with the free version!

In this guide, we'll use a CodeIgniter 4 application generated with CodeIgniter Wizard, our powerful application generator. Stay tuned for an upcoming video where we'll explore the exciting new features of CodeIgniter Wizard 3.x!

Table of Contents


Part 1: Downloading MAMP

Let's begin by downloading MAMP. Visit www.mamp.info in your web browser.

On the MAMP website, you'll see options for both MAMP and MAMP PRO. For this tutorial, the free version of MAMP is sufficient. Click on "Free MAMP download" and save the installer package for macOS.

Once the download is complete, run the installer and follow the on-screen instructions to install MAMP on your system.

Part 2: Understanding the Basics

After installation, open MAMP. The control panel allows you to manage Apache (or Nginx) and MySQL servers. MAMP provides pre-configured settings for ease of use.

A crucial concept is the "htdocs" folder. This is Apache's document root, where it looks for website files. Accessing localhost in your browser, by default, serves files from this folder.

While placing your entire CodeIgniter 4 or Laravel project in "htdocs" might seem straightforward, it leads to routing and path issues. The recommended approach is to create a virtual host, directing web requests to your application's public folder.

Part 3: Setting Up a Virtual Host

We'll now create a virtual host to access our CodeIgniter 4 application using a custom domain like ci4app.local instead of localhost/ci4app/public.

Step 1: Locate the Configuration Files

Find the Apache configuration files within the MAMP installation directory. For macOS, navigate to:

/Applications/MAMP/conf/apache/

You'll find these files:

  • httpd.conf (Main Apache configuration)
  • extra/httpd-vhosts.conf (Virtual hosts configuration)

Step 2: Enable Virtual Hosts in httpd.conf

Open httpd.conf in a text editor. Find and uncomment the following line by removing the #:

Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

Save and close httpd.conf.

Step 3: Configure the Virtual Host

Open extra/httpd-vhosts.conf in a text editor. Add the following virtual host configuration at the end of the file, replacing /path/to/your/codeigniter4-app with the actual path to your CodeIgniter 4 application's root directory:


    ServerName ci4app.local
    DocumentRoot "/path/to/your/codeigniter4-app/public"

    <Directory "/path/to/your/codeigniter4-app/public">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    

    ErrorLog "logs/ci4app.local-error_log"
    CustomLog "logs/ci4app.local-access_log" common

Save and close httpd-vhosts.conf.

Step 4: Update Hosts File

Open Terminal and edit the hosts file:

sudo nano /etc/hosts

Add this line to the end of the file:

127.0.0.1    ci4app.local

Save and exit the hosts file.

Step 5: Restart MAMP

Restart MAMP servers using the control panel.

Part 4: Testing the Setup

Open your browser and navigate to http://ci4app.local. Your CodeIgniter 4 application should load correctly, demonstrating the virtual host setup.

If you encounter issues like a blank page, you may need to enable url_rewrite module in Apache. To do this, open httpd.conf again and uncomment the line:

LoadModule rewrite_module modules/mod_rewrite.so

Restart MAMP servers again after this change.

Conclusion

Congratulations! You've successfully set up a virtual host on MAMP for your CodeIgniter 4 application. This best practice approach ensures a development environment that mirrors production, eliminating potential routing and path issues. This method applies to other modern PHP frameworks like Laravel as well.

Don't forget to subscribe to our channel for upcoming videos, including a deep dive into the new features of CodeIgniter Wizard 3.x!

Ask Us Anything!

If you have any questions or run into problems, leave a comment below. We're here to help!

Visit www.ozar.net for more web development tools and resources.


Keywords: #MAMP, #CodeIgniter 4, #Laravel, #Virtual Host, Local Development Environment, #PHP, #Apache, Web Development Tutorial, CodeIgniter Wizard

Share this on

What do you think?