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

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:

For Red Hat and CentOS

READ:  3 Quick Ways to Find Out Who Hosts Your Website

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.

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.

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.

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

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

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

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.

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

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

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.

READ:  5 Reasons Why Web Hosting Is Important For Your Website

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

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

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

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

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.

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

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.

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

READ:  11 Key Considerations When Choosing Your Web Hosting Share

Save it in the document root located in “c:xampphtdocs”.

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.

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

Also read:How to Install and Run the Nginx Server on WindowsHow to Install and Run the Nginx Server 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.”
  1. Select “Set up a new network or connection.”
  1. Select “Connect to the Internet” and follow the prompts to finish the process.
  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

Image credit: Clay Banks via Unsplash