WindowsMacSoftwareSettingsSecurityProductivityLinuxAndroidPerformanceConfigurationApple All

How to Set Up a Linux Web Server

Edited 3 weeks ago by ExtremeHow Editorial Team

ServerWeb HostingApacheNginxUbuntuConfigurationDevOpsSelf-HostingNetworkingServices

How to Set Up a Linux Web Server

This content is available in 7 different language

A web server is a software application that enables web content to be hosted so that users can access it over the Internet. Setting up a web server involves several important steps, including configuring your server software, adjusting firewall settings, and connecting your domain name to your server. In this guide, we will go through the process of setting up a Linux web server step by step.

Prerequisites

Before you begin, you should have the following things:

Step 1: Choose a Linux distribution

The first step is to decide which Linux distribution you want to use for your web server. Popular choices include Ubuntu Server, CentOS, and Debian. Each distribution has its own package manager and support community. For beginners, Ubuntu is often recommended due to its user-friendliness and large online documentation.

Step 2: Install Linux

Once you've chosen your distribution, install it on your server machine. This usually involves downloading an ISO image from the distribution's official website, creating a bootable USB drive, and following the installation instructions.

Step 3: Update the system

After installation, update the system to ensure you have the latest software packages.

sudo apt-get update sudo apt-get upgrade

The above commands are for Ubuntu. For CentOS, you can use:

sudo yum update

Step 4: Install the web server software

The next step is to install the web server software. The most popular choices are Apache and Nginx. In this guide, we will show how to install Apache.

Installing Apache on Ubuntu

sudo apt-get install apache2

For CentOS, use the following command:

sudo yum install httpd

Step 5: Start the web server

Start your web server and enable it to start on boot.

Starting Apache on Ubuntu

sudo systemctl start apache2 sudo systemctl enable apache2

Starting Apache on CentOS

sudo systemctl start httpd sudo systemctl enable httpd

Step 6: Adjust firewall settings

Make sure your firewall is configured to allow traffic on popular web server ports such as port 80 for HTTP and port 443 for HTTPS.

Using ufw for Ubuntu:

sudo ufw allow 'Apache' sudo ufw enable

Firewalld access for CentOS:

sudo firewall-cmd --zone=public --add-service=http --permanent sudo firewall-cmd --zone=public --add-service=https --permanent sudo firewall-cmd --reload

Step 7: Verify the web server

Open a web browser and type the IP address of your server to check if it is working. If the web server is set up correctly, you should see the default Apache welcome page.

Step 8: Set up the domain name

To make access to your web server easier, bind a domain name to your server. You can purchase a domain name from a registrar and update the DNS records to point to your server's IP address.

Step 9: Enable HTTPS

Securing web traffic with HTTPS is important. You can enable HTTPS using a free certificate from Let's Encrypt.

First, install Certbot, a tool for obtaining SSL certificates:

Installing Certbot on Ubuntu

sudo apt-get install certbot python3-certbot-apache

To obtain and install the certificate, run:

sudo certbot --apache

Step 10: Deploy a test website

Create a basic HTML file in the Apache web directory to test your setup.

sudo nano /var/www/html/index.html

Insert a simple HTML page:

<!DOCTYPE html> <html> <head> <title>Welcome to My Web Server</title> </head> <body> <h1>Hello, World!</h1> <p>My Linux web server is successfully running.</p> </body> </html>

Step 11: Advanced configuration (optional)

You may want to consider more advanced configurations for a production environment, such as setting up virtual hosts for multiple domain hosting, configuring load balancing, or installing a database server such as MySQL or PostgreSQL.

Conclusion

Once you're familiar with the Linux command line and basic server management, setting up a Linux web server is a straightforward process. This guide walks you through the essentials, from selecting a distribution, installing and configuring necessary software, securing your server, and deploying a simple web page. Be sure to keep your software updated and consider additional security measures such as a firewall and regular backups to maintain the integrity of your server over time.

If you find anything wrong with the article content, you can


Comments