How to Set Up a Basic Web Server on Ubuntu

How to Set Up a Basic Web Server on Ubuntu

This guide offers a straightforward approach to setting up a basic web server on Ubuntu. Targeted at beginners and intermediate users, it outlines the key steps for installing, configuring, and maintaining a web server on this user-friendly Linux-based operating system. This article is an essential resource for anyone interested in hosting websites or applications using Ubuntu.

What Is a Web Server on Ubuntu

A web server is a software system that delivers web pages, images, and other content to users over the internet or an intranet. It responds to requests from clients, usually web browsers, using the Hypertext Transfer Protocol (HTTP). Ubuntu is a popular Linux distribution that is widely used for hosting web servers because it is stable, secure, and user-friendly. Web servers on Ubuntu can range from serving simple static websites to hosting complex web applications. Here it’s key features:

  1. Variety of Web Server Software Options. Ubuntu supports various web server software like Apache, Nginx, and Lighttpd, each with unique features such as Apache’s modularity and Nginx’s efficient handling of static content and heavy traffic.
  2. Ease of Installation and Configuration. Ubuntu’s APT system simplifies the installation and updating of web server software, offering tested and stable versions in its repositories. Well-documented and organized configuration files further ease the setup process.
  3. Strong Security Features. Ubuntu includes essential security features like AppArmor and regular updates, supported by a security-focused community, ensuring a secure web server environment.
  4. Compatibility with Common Web Technologies. Seamless integration with essential web technologies and databases such as PHP, Python, Ruby, MySQL, and PostgreSQL is a hallmark of these servers, making them ideal for a variety of web applications.
  5. Community and Documentation Support. Ubuntu’s dynamic community provides extensive learning and troubleshooting resources, including detailed documentation, tutorials, and forums, aiding users of all levels in web server setup and maintenance.

In the following section, we will discuss the process of setting it up on Ubuntu.

Process for Setting Up a Basic Web Server on Ubuntu

To set up a basic web server on Ubuntu, follow the step-by-step instructions provided below.

  1. Updating the System. Begin by updating your Ubuntu system to ensure all packages are current. The system will fetch the list of available updates and then apply them.
sudo apt update && sudo apt upgrade
  1. Installing the Web Server Software (Apache). Install Apache, a popular web server software.
sudo apt install apache2

Sample Output:

  1. Adjusting the Firewall. Modify the firewall settings to allow web traffic. Firewall rules will be updated to allow access to Apache by using this command.
sudo ufw allow 'Apache Full'
  1. Checking Apache Installation. Verify that Apache was successfully installed and is running. A status message indicating that Apache is active and running should show up by using this command below.
sudo systemctl status apache2

Sample Output:

  1. Creating a Test Web Page. Create a simple HTML file to test the Apache server.
echo "<html><body><h1>Hello, Ubuntu Server!</h1></body></html>" | sudo tee /var/www/html/test.html

A new HTML file named ‘test.html’ will be created in the web root directory.

  1. Accessing the Test Page. Access the test page via a web browser. When you navigate to http://your_server_IP/test.html, you should see the message “Hello, Ubuntu Server!” displayed in your browser, confirming that Apache is serving web pages correctly.
  2. Setting Up Virtual Hosts (Optional). If you plan to host multiple sites, set up virtual hosts. Instructions will vary based on the domain and content. Separate directories for each website, allowing for individual site hosting.
  3. Securing Your Web Server (Optional). Implement SSL/TLS for secure data transmission. This involves acquiring a certificate (e.g., Let’s Encrypt) and configuring Apache. An encrypted connection established between your server and its visitors.

Congratulations! By following these steps, you now have a basic yet fully functional web server running on Ubuntu, ready to host websites and web applications. This process can be customized and expanded based on your specific hosting needs and more advanced configurations.

Conclusion

Want to run Ubuntu in a virtual environment? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Ubuntu:

Choose an instance

How to Set Up a Basic Web Server on Ubuntu

Subscribe
to our newsletter

Get the latest industry trends, exclusive insights, and Gcore
updates delivered straight to your inbox.