How to Set Up a Local Web Server (Windows, Mac, Linux)

Test and host web pages easily from your own local server.

How To Set Up A Local Web Server Featured

When developing a website, a web designer needs to be able to see his webpages in the same way the end user would. Sometimes simply clicking on and viewing your HTML files in the web browser is enough, but if you want to test dynamic content, you will need to set up a local web server. Doing this is quite simple and can easily be accomplished on Windows, macOS, and Linux. There are many types of web servers available, but we use Apache (check out our comparison of Nginx vs Apache to see which is better for you) in this tutorial, as it is the most common server around, very easy to set up, and compatible with all major operating systems.

If you are running a static website instead of a dynamic one, you can also check out our review of some of the best static website CMS out there.

Set Up a Local Web Server on Linux

Apache was designed for Unix-like operating systems. Linux falls under this category, and the installation and configuration of an Apache webserver can be done in one step.

Here we deal with the command line. Most popular distributions allow you to install Apache without compiling it from source using one simple command.

For Debian, Ubuntu, and Ubuntu-based distro:

sudo apt install apache2

For Red Hat and CentOS

sudo dnf install httpd

Once installed, navigate in your web browser to either “127.0.0.1” or “localhost.” If it displays “It Works!” that means your Apache installation is successful.

Web Server Ubuntu Install Apache

To better understand how Apache is serving this particular webpage, let’s edit it. To do this, navigate to the root web directory of your Linux local machine.

cd /var/www/html

Open “index.html” as root with your favorite text editor.

Search for “It Works!” and change the text to something random like “Make Tech Easier!” (It could be anything really.) Make sure to save the file.

Now refresh the webpage on 127.0.0.1. You should see “Make Tech Easier!” where “It Works!” was formerly.

Web Server Ubuntu Edit Default

Now that you have set up a simple web server, you can play with the configuration settings in “apache2.conf.”

sudo nano /etc/apache2/apache2.conf

Note: be aware that every time you make a configuration change, you will need to restart Apache for it to apply.

sudo systemctl restart apache2

If this does not work, you can restart it by directly executing the upstart file.

sudo /etc/init.d/apache2 restart

Set Up a Local Web Server on macOS

The good thing about macOS is that Apache is installed on it by default. All you need to do is turn it on.

In Finder, go to “Applications -> Utilities,” then double-click on Terminal to open it.

Macos Open Terminal App

To turn on your already pre-installed Apache web server, run the following command:

sudo apachectl start

To test that our web server is running, navigate to “127.0.0.1” or “localhost” in your web browser.

Macos Web Server It Works

We can change the content of the webpage by simply navigating to the document root the same way we did in Linux. The only thing that is different is the path location.

cd /Library/WebServer/Documents/

Now edit the “index.html.en” file using your favorite text editor. Change “It works!” to “Hello World!”

sudo nano index.html.en
mac-nano-open-index-html

If we refresh our webpage hosted on 127.0.0.1, we now see the changes reflected.

Macos Web Server Hello World

To further configure Apache web server under macOS, navigate to the “httpd.conf” file.

sudo nano /etc/apache2/httpd.conf

Like Linux, you can easily restart the Apache service using the apachectl command with root privileges.

sudo apachectl restart

Set Up a Local Web Server on Windows

Unlike Linux and macOS, Windows is not Unix-based, so there is no one-liner to install it. Fortunately, there are several install wizards that bundle things like Apache, MySQL, and PHP together to make our lives easier. One of them is XAMPP.

Note: XAMPP is available for Linux and macOS, too.

Download the Windows version of XAMPP and begin the installation. Execute the installer when prompted. You can select only Apache if all you need is a web server. However, if you are planning on using a database, you may want to select MySQL as well.

How To Set Up A Local Web Server Install Windows

Continue through the installation and click “Finish” when complete. By default, the XAMPP control panel will be launched.

How To Set Up A Local Web Server Xampp Control

Click “Start” for Apache and MySQL, if needed.

If you navigate to “127.0.0.1” or “localhost” in your web browser, you should see the XAMPP configuration page.

How To Set Up A Local Web Server Xampp Config

To create a new webpage, the procedure is the same. Open notepad and create a sample HTML file. Name it “hello.html.”

How To Set Up A Local Web Server Windows Notepad

Save it in the document root located in “c:\xampp\htdocs\”.

Navigate to it using your web browser by going to 127.0.0.1/hello.html. You’ll be able to see the webpage you created.

How To Set Up A Local Web Server Windows Hello

Note: WampServer is another solid option for installing Apache on Windows.

Setup a LAN Server in Windows

Another option is to setup a LAN server in Windows. You don’t need to install anything for this method. However, you will need Ethernet cables for a direct connection to your router or router/modem combo.

  1. Connect your computer via Ethernet cable to your router.
  2. Open Start and search for “Control Panel.” Open the result.
  3. Select “Network and Sharing Center.”
How To Set Up A Local Web Server Network Sharing
  1. Select “Set up a new network or connection.”
How To Set Up A Local Web Server Network Sharing New
  1. Select “Connect to the Internet” and follow the prompts to finish the process.
How To Set Up A Local Web Server Network Sharing New Internet
  1. You can connect other devices to the LAN via Ethernet or Wi-Fi. Obviously, for Wi-Fi, you’ll need to setup a Wi-Fi password and use that to connect other devices. You can also create a Homegroup to share resources from Network and Sharing Center.

If you what you want is to connect to a remote folder, you don’t have to setup a web server to access it. You can easily do it by mapping a WebDAV drive to Windows.

Additional Devices

If you have a Raspberry Pi, you can also turn it into a personal web server. Find out how to do it here.

Frequently Asked Questions

Is Apache the only option for a web server?

Apache is an excellent web server solution, but it is not the only option. You may want to look at IIS as an option for Windows, as it supports many Windows authentication features that Apache does not.

Another option is Python for a simple local HTTP server. It’s already installed on macOS and Linux, but you can install it for Windows from Python.org.

Why am I getting warnings that Apache won't work with my antivirus?

The purpose of antivirus is to keep others out of your computer. When setting up a local web server, you’re opening up your computer to outside connections. Your antivirus can work together with Apache. You just need to allow Apache access via your antivirus. You should get a warning from your antivirus along with a prompt to either deny or allow access. The exact steps vary greatly based on the antivirus you use.

Depending on how you’ll use your server, you may want to take extra steps to secure it. For example, there are a variety of open source tools to secure Linux servers.

Should I use my main computer or a dedicated computer for setting up a web server?

If you’re just doing basic local testing, you’re not going to have much traffic coming to your computer. It’s fine to just use your main computer and turn the server on/off as needed.

If you’re hosting a website or other resource from your computer, it’s better to use a dedicated computer as the server. You’ll be dealing with more traffic, which uses more resources. This makes it harder for your computer to perform as well for your everyday tasks.

Does my ISP mind if I set up a local web server?

Some ISPs do have bandwidth restrictions and may prohibit you from hosting your own server, especially for high traffic sites and P2P downloading or torrents. Also, if you have hard data limits, you’ll probably want to avoid setting up a server outside of basic testing purposes.

Most ISPs don’t mind local servers as they don’t have extreme usage. For instance, basic testing or hosting a calendar server using Baikal. If you’re not sure, contact your ISP to ask and explain what you’re trying to accomplish. If you do need more bandwidth without restrictions, they may set you up with a business account.

Image credit: Clay Banks via Unsplash

Crystal Crowder
Crystal Crowder

Crystal Crowder has spent over 15 years working in the tech industry, first as an IT technician and then as a writer. She works to help teach others how to get the most from their devices, systems, and apps. She stays on top of the latest trends and is always finding solutions to common tech problems.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox