How to set up a local web server (Local Web Server) on Windows, macOS, and Linux

When developing your own website, you need to have the ability to observe and evaluate what the website might look like from a regular visitor's perspective. Here are the steps for setting up a local web server on Windows, Mac and Linux

Sometimes you just need to click and view your HTML files in a web browser. But if you want to test dynamic content, you'll need to set up a local web server (Local Web Server).

This is pretty simple and you can easily do it yourself whether you're using a Windows, macOS or Linux PC. There are many types of web servers available, but in this article we will use Apache because it is the most popular server, very easy to set up and has good compatibility with all popular computer operating systems variable current.

Set up a local web server on Linux

Apache is designed for Unix-like operating systems. Linux falls into this category and the installation and configuration of the Apache web server can be done very simply.

Work will be related to command line processing. Most popular Linux distributions nowadays allow you to install Apache without having to compile it from source using just one simple command.

For Debian, Ubuntu and Ubuntu-based distributions:

sudo apt install apache2

For Red Hat and CentOS:

sudo dnf install httpd

Once the installation is complete, open a web browser and navigate to ' 127.0.0.1 ' or ' localhost '. If the screen shows " It Works! " Then your installation of Apache was successful.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 1How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 1

To better understand how Apache is handling this particular website, let's edit it. First, navigate to the root web directory of your local Linux computer.

cd / var / www / html

Open ' index.html ' as the root directory with a text editor on the system.

Search for the phrase ' It Works !' and change it to some random text, such as " Tips Make Easier! ", then save the file.

Now, refresh the website on 127.0.0.1 . You should see a screen displaying the phrase " Tips Make Easier! " Instead of ' It Works! ' formerly.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 2How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 2

Now, you have successfully set up a simple web server. Some configuration settings tweaking can be done in ' apache2.conf '.

sudo nano /etc/apache2/apache2.conf

Note: Every time you make configuration modifications, you will need to restart Apache to apply any changes.

sudo systemctl apache2 restart

If this doesn't work, you can restart it by doing the boot file directly.

sudo /etc/init.d/apache2 restart

Set up a local web server on macOS

The good news is that Apache is currently installed on macOS by default. So all you need to do is turn it on.

In the Finder, navigate to ' Applications -> Utilities ', then double-click Terminal .

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 3How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 3

To enable the pre-installed Apache web server, run the following command:

sudo apachectl start

To check if the web server is running, open a browser and navigate to ' 127.0.0.1 ' or ' localhost '.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 4How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 4

You can of course also change the content of the website by simply navigating to the root directory like you did in Linux. The only thing that is different is the path location.

cd / Library / WebServer / Documents /

Now let's edit the file 'index.html.en' using the text editor on the machine. Change " It works! " To " Hello World! ".

sudo nano index.html.en
How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 5How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 5

Please refresh the website on 127.0.0.1 . You should see a screen showing the phrase " Hello World! " Instead of ' It Works! ' as before.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 6How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 6

To further configure the Apache web server in macOS navigate to the file ' httpd.conf '.

sudo nano /etc/apache2/httpd.conf

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

sudo apachectl restart

Set up a local web server on Windows

Unlike Linux and macOS, Windows is not Unix-based, so the local web server installation will be slightly different.

Fortunately, there are a number of installers that combine things like Apache, MySQL, and PHP together to make the job even easier. One of them is XAMPP.

( Note : XAMPP is also available for Linux and Mac OS X).

Download the Windows version of XAMPP and start installing. Execute the installer when prompted. You can only choose Apache if all you need is a web server. However, if you are planning on using a database, you can also choose MySQL.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 7How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 7

Continue installation and click ' Finish ' when the last step is reached. By default, the XAMPP dashboard will be launched.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 8How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 8

Click ' Start ' for Apache and MySQL, if needed.

If navigating to ' 127.0.0.1 ' or ' localhost ' in your local web browser, you will see the XAMPP configuration page.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 9How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 9

To create a new website, the process is the same as above. Open notepad and create a sample HTML file. Name it ' hello.html '.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 10How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 10

Save the file to the document root directory located in ' c: xampphtdocs '.

Navigate to it by opening a web browser and visiting 127.0.0.1/hello.html . You will be able to view the web page you have created.

How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 11How to set up a local web server (Local Web Server) on Windows, macOS, and Linux Picture 11

Good luck.

4.5 ★ | 2 Vote