Tutorial Install & Konfigurasi Web Server di Debian 9

3 min read 3 hours ago
Published on Oct 05, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial guides you through the installation and configuration of a web server on Debian 9. Setting up a web server is essential for hosting websites, applications, or services. By the end of this guide, you'll have a fully functional web server on your Debian system, ready to serve content to users.

Step 1: Update Your System

Before installing any software, ensure your system is up to date.

  1. Open a terminal.

  2. Run the following commands to update the package list and upgrade the installed packages:

    sudo apt update
    sudo apt upgrade -y
    
  3. Reboot your system if necessary.

Step 2: Install Apache Web Server

Apache is one of the most popular web servers. Follow these steps to install it.

  1. In your terminal, run the command:

    sudo apt install apache2 -y
    
  2. After installation, check if Apache is running with:

    systemctl status apache2
    
    • If it’s not running, start it with:
    sudo systemctl start apache2
    
  3. Enable Apache to start on boot:

    sudo systemctl enable apache2
    

Step 3: Configure Firewall

To allow web traffic, you need to configure the firewall.

  1. Check if UFW (Uncomplicated Firewall) is installed:

    sudo ufw status
    
  2. If UFW is inactive, enable it:

    sudo ufw enable
    
  3. Allow HTTP and HTTPS traffic:

    sudo ufw allow 'Apache Full'
    
  4. Verify the changes:

    sudo ufw status
    

Step 4: Test Your Web Server

Check if your web server is set up correctly.

  1. Open a web browser.
  2. Enter your server's IP address into the address bar (you can find it using the command hostname -I).
  3. You should see the Apache2 Debian Default Page, confirming that your server is running.

Step 5: Configure Apache

You may want to configure Apache to serve your own website.

  1. Create a new directory for your website:

    sudo mkdir /var/www/html/mywebsite
    
  2. Set the correct permissions:

    sudo chown -R $USER:$USER /var/www/html/mywebsite
    
  3. Create an index.html file:

    nano /var/www/html/mywebsite/index.html
    
    • Add some HTML content, for example:
    <html>
    <head>
        <title>Welcome to My Website</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
        <p>This is my first web page on Apache.</p>
    </body>
    </html>
    
  4. Save and exit the editor (Ctrl + X, then Y, and Enter).

  5. Create a new Apache configuration file for your site:

    sudo nano /etc/apache2/sites-available/mywebsite.conf
    
    • Add the following configuration:
    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/mywebsite
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    
  6. Enable the new site and reload Apache:

    sudo a2ensite mywebsite.conf
    sudo systemctl reload apache2
    

Conclusion

You have successfully installed and configured a web server on Debian 9 using Apache. You've also created a simple web page to test your setup. Moving forward, you can explore adding more features, such as PHP support, database integration, or SSL for secure connections. Keep your server updated and secure for optimal performance.