How to Set Up a Local Web Server on Mac?


Scott Campbell

Setting up a local web server on Mac can be a useful skill for web developers and designers. With a local server, you can test your websites or web applications before deploying them to a live environment. In this tutorial, we will walk through the steps of setting up a local web server on Mac.

Step 1: Install Apache
The first step is to install Apache, the most popular web server software. Fortunately, Mac comes with Apache pre-installed. To start the Apache service, open Terminal and type the following command:

sudo apachectl start

You will be prompted to enter your password. Once entered, Apache will start running on your Mac.

Step 2: Verify Apache Installation
To verify that Apache is successfully installed and running, open your web browser and enter “localhost” in the address bar. If you see the message “It works!”, it means that Apache has been installed correctly.

Step 3: Configure Document Root
By default, Apache serves files from the “/Library/WebServer/Documents” directory. However, you can change this location if desired. To do so, open Terminal and type:

sudo nano /etc/apache2/httpd.conf

This command will open the Apache configuration file in the Nano text editor. Look for the line that begins with “DocumentRoot” and modify it to your desired directory path. For example:

DocumentRoot "/Users/YourUsername/Sites"

Save your changes by pressing Ctrl + X, followed by Y and Enter.

Step 4: Enable PHP (Optional)
If you want to use PHP on your local server, you need to enable it in the Apache configuration file. Open Terminal and type:

Look for the line that begins with “#LoadModule php7_module” and remove the “#” symbol to uncomment the line. Then, save your changes.

Step 5: Test PHP
To test if PHP is working correctly, create a new file called “info.php” in your document root directory. Open Terminal and type:

nano /Users/YourUsername/Sites/info.php

In the Nano editor, enter the following code:


Save your changes. Now, open your web browser and navigate to “localhost/info.php”. If PHP is enabled, you should see a page with detailed information about your PHP configuration.

Step 6: Restart Apache
After making any changes to the Apache configuration file, you need to restart Apache for the changes to take effect. Open Terminal and type:

sudo apachectl restart

You may be prompted to enter your password. Once entered, Apache will restart.

Congratulations! You have successfully set up a local web server on your Mac using Apache. Now you can develop and test websites or web applications locally before deploying them to a live server.


  • Install Apache by starting it using “sudo apachectl start” command.
  • Verify Apache installation by entering “localhost” in your browser’s address bar.
  • Configure the document root folder by modifying the “/etc/apache2/httpd.conf” file.
  • If desired, enable PHP support by uncommenting the appropriate line in “/etc/apache2/httpd.conf”.
  • Create a new file called “info.php” in your document root folder to test PHP functionality.
  • Restart Apache whenever you make changes to its configuration file using “sudo apachectl restart” command.

Now you are ready to develop and test your websites locally on your Mac!

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy