Hosting Your Own Website with Apache on Debian/Ubuntu and Securing It with Let's Encrypt
Tags: apache, ssl, hosting
Published: 2023-07-26 13:52:22

## Introduction:

Hey there web enthusiasts! 

Are you eager to take control of your online presence and host your own website with a personalized domain name? 

Look no further! In this step-by-step guide, we'll show you how to set up your very own website using the Apache web server on the latest Debian or Ubuntu LTS versions. 

Plus, we'll walk you through the process of securing your site with the latest version of Let's Encrypt SSL certificates. 

Let's get started!

**Step 1: Installing Apache:**

First things first, let's install the Apache web server on your Debian or Ubuntu system. 

Open your terminal and type the following command:

```bash
sudo apt update
sudo apt install apache2
```

**Step 2: Configuring Apache:**

Once Apache is installed, it's time to configure it. 
You'll need to set up your virtual hosts to serve your website correctly. 

We'll assume your domain name is "yourdomain.com" for this example. Replace it with your actual domain.

Create a new virtual host file for your website:

```bash
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
```

Add the following configuration to the file:

```apache
<VirtualHost *:80>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    DocumentRoot /var/www/yourdomain.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```

Enable the virtual host and restart Apache:

```bash
sudo a2ensite yourdomain.com.conf
sudo systemctl restart apache2
```

**Step 3: Setting Up Your Website:**

Create the directory to store your website files:

```bash
sudo mkdir -p /var/www/yourdomain.com/public_html
```

Next, upload your website files to this directory using your favorite FTP client or by SCP.

**Step 4: Installing Let's Encrypt:**

Now, let's secure your website with Let's Encrypt SSL certificates to protect your visitors' data. 
We'll use the Certbot tool to do this.

```bash
sudo apt install certbot python3-certbot-apache
```

**Step 5: Obtaining SSL Certificates:**

Run Certbot to obtain SSL certificates for your domain:

```bash
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
```

Certbot will guide you through the process, and once it's done, your website will be secured with SSL!

**Step 6: Automating Certificate Renewal:**

Let's Encrypt SSL certificates are valid for a limited time, so it's essential to automate the renewal process. Luckily, Certbot takes care of that for us.

To set up a cron job for automatic renewal, run the following command:

```bash
sudo crontab -e
```

Add the following line to the file and save it:

```bash
30 2 * * 1 /usr/bin/certbot renew --quiet
```

## Conclusion:

Congratulations! 
You've successfully hosted your own website with a custom domain name using Apache on Debian/Ubuntu and secured it with Let's Encrypt SSL certificates. 

Now you have full control over your online presence and can provide a secure experience to your visitors. Keep exploring and learning to enhance your website further. 

**Happy hosting!**