When developing a website of your own, you need to possess the ability to observe and evaluate how the website might look from the perspective of the casual visitor.
Sometimes just clicking and viewing your HTML files in a web browser is enough. But if you want to test dynamic content, you will need to set up a local web server (Local Web Server).
It’s 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 this is the most popular server, it is easy to set up and has good compatibility with all popular computer operating systems. current variable.
Setting up a local web server on Linux
Apache is designed for Unix-like operating systems. Linux falls into this category and installing and configuring the Apache web server can be done very simply.
The work will involve command line processing. Most popular Linux distributions today allow you to install Apache without compiling 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 display shows “It Works!” then it means your Apache installation was successful.

To better understand how Apache is handling this particular site, let’s edit it. First, navigate to the root web directory of your local Linux computer.
cd /var/www/html
Open “index.html” as a root folder with a text editor on the system.
Search for the phrase “It Works!” and change it to some random text such as “Make Tech Easier!“, then save the file.
Now, refresh the web page on the address 127.0.0.1. You should see a screen that says “Make Tech Easier!” instead of “It Works!” formerly.
Now, you have successfully set up a simple web server. Some configuration settings can be made in “apache2.conf”.
sudo nano /etc/apache2/apache2.conf
Note: Every time you make a configuration edit, you will need to restart Apache to apply any changes.
sudo systemctl apache2 restart
If this doesn’t work, you can reboot by executing the startup file directly.
sudo /etc/init.d/apache2 restart
Set up a local web server on macOS
The good news is that Apache is now installed on macOS by default. So all you need to do is just turn it on.
In Finder, navigate to “Applications -> Utilities”, then double-click Terminal.
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”.
Of course you can also change the content of the website by simply navigating to the root directory the same way you did in Linux. The only thing that is different is the path location.
cd /Library/WebServer/Documents/
Now, edit the file “index.html.en” with your local text editor. Change “It works!” to “Hello World!“.
sudo nano index.html.en
Please refresh the web page at 127.0.0.1. You should see a screen displaying the phrase “Hello World!” instead of “It Works!” as before.
To further configure the Apache web server in macOS, navigate to the “httpd.conf” file.
sudo nano /etc/apache2/httpd.conf
Like Linux, you can easily restart the Apache service with 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 setting up a local web server is slightly different.
Fortunately, there are a number of installers that combine things like Apache, MySQL, and PHP together to make the job easier. One of them is XAMPP.
(Note: XAMPP is also available for Linux and Mac OS X).
Download Windows version of XAMPP and start the installation. Execute the installer when prompted. You can choose Apache only if all you need is a web server. However, if you are planning to use a database, you can also choose MySQL.
Continue with the installation and click “Finish” when you reach the end. By default, the XAMPP control panel will be launched.
Click “Start” for Apache and MySQL, if necessary.
If you navigate to “127.0.0.1” or “localhost” in your local web browser, you will see the XAMPP configuration page.
To create a new website, the process is the same as above. Open notepad and create a sample HTML file. Name it “hello.html”.
Save the file to the document root directory located in “c:xampphtdocs”.
Navigate to it by opening a web browser and going to 127.0.0.1/hello.html. You’ll be able to see the website you’ve created.
2 comments
[…] How to set up a local web server (Local Web Server) on Windows, macOS and Linux […]
[…] How to set up a local web server (Local Web Server) on Windows, macOS and Linux […]