Edited 3 weeks ago by ExtremeHow Editorial Team
ServerWeb HostingApacheNginxUbuntuConfigurationDevOpsSelf-HostingNetworkingServices
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.
Before you begin, you should have the following things:
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.
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.
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
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.
sudo apt-get install apache2
For CentOS, use the following command:
sudo yum install httpd
Start your web server and enable it to start on boot.
sudo systemctl start apache2 sudo systemctl enable apache2
sudo systemctl start httpd sudo systemctl enable httpd
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.
sudo ufw allow 'Apache' sudo ufw enable
sudo firewall-cmd --zone=public --add-service=http --permanent sudo firewall-cmd --zone=public --add-service=https --permanent sudo firewall-cmd --reload
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.
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.
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:
sudo apt-get install certbot python3-certbot-apache
To obtain and install the certificate, run:
sudo certbot --apache
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>
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.
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