<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Florence Okoli</title>
    <description>The latest articles on DEV Community by Florence Okoli (@florenceokoli).</description>
    <link>https://dev.to/florenceokoli</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1378128%2F0b9e687f-fdb5-4ee9-a477-408e73b6d476.jpg</url>
      <title>DEV Community: Florence Okoli</title>
      <link>https://dev.to/florenceokoli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/florenceokoli"/>
    <language>en</language>
    <item>
      <title>Automating User and Group Management Using Bash Script</title>
      <dc:creator>Florence Okoli</dc:creator>
      <pubDate>Wed, 03 Jul 2024 21:33:59 +0000</pubDate>
      <link>https://dev.to/florenceokoli/automating-user-and-group-management-using-bash-script-4a7o</link>
      <guid>https://dev.to/florenceokoli/automating-user-and-group-management-using-bash-script-4a7o</guid>
      <description>&lt;p&gt;Bash, short for Bourne Again Shell, is a Unix shell and command language that has been a fundamental part of system administration and development for many years. As the default shell on many Unix-like operating systems, including Linux and macOS, Bash is renowned for its powerful capabilities in scripting and automation.&lt;/p&gt;

&lt;p&gt;Imagine having to create user accounts, assign them to appropriate groups, set up home directories, and generate secure passwords for each new developer joining your team. Doing this manually can be tedious and error-prone. This is where Bash comes in. You can automate these repetitive tasks with Bash scripting, ensuring consistency and saving valuable time.&lt;/p&gt;

&lt;p&gt;In this article, I used a Bash script to automate the onboarding process for new developers. This script reads a text file containing usernames and their respective groups, creates users, assigns them to groups, sets up their home directories, generates random passwords, and logs all actions. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A Unix-based system (Linux or macOS)&lt;/li&gt;
&lt;li&gt;Basic knowledge of Unix commands and Bash scripting&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Objective
&lt;/h2&gt;

&lt;p&gt;The script should create users and groups as specified, set up home directories with appropriate permissions and ownership, generate random passwords for the users, and log all actions to /var/log/user_management.log. Additionally, store the generated passwords securely in /var/secure/user_passwords.txt&lt;/p&gt;

&lt;h2&gt;
  
  
  My create_users.sh Script
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Log file and password storage
LOG_FILE="/var/log/user_management.log"
PASSWORD_FILE="/var/secure/user_passwords.txt"

# Ensure the /var/secure directory exists
if [ ! -d "/var/secure" ]; then
    mkdir -p /var/secure
    chmod 700 /var/secure
fi

# Ensure the log file and password file exist and have correct permissions
touch $LOG_FILE
touch $PASSWORD_FILE
chmod 600 $PASSWORD_FILE

# Function to log messages
log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" &amp;gt;&amp;gt; $LOG_FILE
}

# Check if the file is supplied
if [ $# -ne 1 ]; then
    log_message "ERROR: No input file supplied"
    echo "Usage: $0 &amp;lt;name-of-text-file&amp;gt;"
    exit 1
fi

INPUT_FILE=$1

# Check if input file exists
if [ ! -f $INPUT_FILE ]; then
    log_message "ERROR: Input file does not exist"
    echo "ERROR: Input file does not exist"
    exit 1
fi

# Read the input file line by line
while IFS=';' read -r username groups; do
    # Trim whitespace
    username=$(echo $username | xargs)
    groups=$(echo $groups | xargs)

    # Skip empty lines
    if [ -z "$username" ]; then
        continue
    fi

    # Create a personal group for the user
    if ! getent group $username &amp;gt;/dev/null; then
        groupadd $username
        log_message "Group $username created."
    else
        log_message "Group $username already exists."
    fi

    # Create the user with the personal group
    if ! id -u $username &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then
        useradd -m -g $username $username
        log_message "User $username created."
    else
        log_message "User $username already exists."
    fi

    # Assign the user to additional groups
    IFS=',' read -ra ADDR &amp;lt;&amp;lt;&amp;lt; "$groups"
    for group in "${ADDR[@]}"; do
        group=$(echo $group | xargs)
        if [ ! -z "$group" ]; then
            if ! getent group $group &amp;gt;/dev/null; then
                groupadd $group
                log_message "Group $group created."
            fi
            usermod -aG $group $username
            log_message "User $username added to group $group."
        fi
    done

    # Generate a random password
    password=$(openssl rand -base64 12)

    # Set the user's password
    echo "$username:$password" | chpasswd
    log_message "Password set for user $username."

    # Store the password securely
    echo "$username,$password" &amp;gt;&amp;gt; $PASSWORD_FILE
done &amp;lt; "$INPUT_FILE"

# Set the correct permissions on the password file
chmod 600 $PASSWORD_FILE

log_message "User creation process completed."

echo "User creation process completed. Check $LOG_FILE for details."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A detailed breakdown of the Script
&lt;/h2&gt;

&lt;p&gt;Here is what this script does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Shebang&lt;br&gt;
The &lt;code&gt;#!/bin/bash&lt;/code&gt; known as the shebang indicates that the script should be run on the BASH shell.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Path to Log file and Password file&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOG_FILE="/var/log/user_management.log"
PASSWORD_FILE="/var/secure/user_passwords.txt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;LOG_FILE&lt;/code&gt; and &lt;code&gt;PASSWORD_FILE&lt;/code&gt; are variables that store the path to the log file and password file respectively.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create /var/secure directory and set permission if it doesn't exist
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if [ ! -d "/var/secure" ]; then
    mkdir -p /var/secure
    chmod 700 /var/secure
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create Log file and Password file if they don't exist and set permission
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch $LOG_FILE
touch $PASSWORD_FILE
chmod 600 $PASSWORD_FILE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;touch $LOG_FILE&lt;/code&gt; and &lt;code&gt;touch $PASSWORD_FILE&lt;/code&gt; creates the log and password files if they do not already exist.&lt;br&gt;
&lt;code&gt;chmod 600 $PASSWORD_FILE&lt;/code&gt; sets the permissions for the password file so that only the file owner can read and write to it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log message function
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" &amp;gt;&amp;gt; $LOG_FILE
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;log_message&lt;/code&gt; function takes a message as an argument and appends it to the log file with a timestamp.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check if input file is provided
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if [ $# -ne 1 ]; then
    log_message "ERROR: No input file supplied"
    echo "Usage: $0 &amp;lt;name-of-text-file&amp;gt;"
    exit 1
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This checks if &lt;code&gt;[ $# -ne 1 ]; then&lt;/code&gt; checks if exactly one argument (the input file) is supplied to the script.&lt;br&gt;
If not, it logs an error, prints a usage message, and exits the script.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;INPUT_FILE=$1&lt;/code&gt; assigns the first argument (input file) to the variable INPUT_FILE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if the input file exists&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if [ ! -f $INPUT_FILE ]; then
    log_message "ERROR: Input file does not exist"
    echo "ERROR: Input file does not exist"
    exit 1
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;if [ ! -f $INPUT_FILE ]; then&lt;/code&gt; checks if the input file exists.&lt;br&gt;
If not, it logs an error, prints an error message, and exits the script.Cre&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read and process the input file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;while IFS=';' read -r username groups; do&lt;/code&gt; starts a loop to read the input file line by line, expecting each line to contain a username and groups separated by a semicolon (;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The command below trims whitespace from the username and groups variables if any.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    username=$(echo $username | xargs)
    groups=$(echo $groups | xargs)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;While&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    if [ -z "$username" ]; then
        continue
    fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Skips empty lines (where username is empty).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a group for user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    if ! getent group $username &amp;gt;/dev/null; then
        groupadd $username
        log_message "Group $username created."
    else
        log_message "Group $username already exists."
    fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a personal group for the user if it doesn't exist and logs the action.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates user for group
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; if ! id -u $username &amp;gt;/dev/null 2&amp;gt;&amp;amp;1; then
        useradd -m -g $username $username
        log_message "User $username created."
    else
        log_message "User $username already exists."
    fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates the user with their group if they don't already exist and logs the action.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates additional groups for users.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IFS=',' read -ra ADDR &amp;lt;&amp;lt;&amp;lt; "$groups"
    for group in "${ADDR[@]}"; do
        group=$(echo $group | xargs)
        if [ ! -z "$group" ]; then
            if ! getent group $group &amp;gt;/dev/null; then
                groupadd $group
                log_message "Group $group created."
            fi
            usermod -aG $group $username
            log_message "User $username added to group $group."
        fi
    done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command splits the group's string into an array, iterates over it, checks if the group exists (creating it if necessary) and adds the user to the group, logging each action.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Generate a random password&lt;br&gt;
The &lt;code&gt;password=$(openssl rand -base64 12)&lt;/code&gt; generates a random password using the OpenSSL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the user's password&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    echo "$username:$password" | chpasswd
    log_message "Password set for user $username."
    echo "$username,$password" &amp;gt;&amp;gt; $PASSWORD_FILE
done &amp;lt; "$INPUT_FILE"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above sets the user's password and then appends the username and password to the PASSWORD_FILE &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This &lt;code&gt;done &amp;lt; "$INPUT_FILE"&lt;/code&gt; code ends the loop that reads from the INPUT FILE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;chmod 600 $PASSWORD_FILE&lt;/code&gt; code ensures the password file's permissions are secure after all passwords have been added.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Log completion of the user creation process&lt;br&gt;
&lt;code&gt;log_message "User creation process completed."&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Test the Script
&lt;/h2&gt;

&lt;p&gt;To test this script, let's create a &lt;code&gt;users.txt&lt;/code&gt; file&lt;br&gt;
&lt;code&gt;nano users.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the text file, enter the usernames and groups&lt;br&gt;
&lt;code&gt;wendy; engineering,webteam&lt;br&gt;
florenceokoli; admins, dev_team&lt;br&gt;
chi; support&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Execute the Script
&lt;/h2&gt;

&lt;p&gt;`chmod create_users.sh&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the Script
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;sudo ./create_users.sh users.txt&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Management Log&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n8tuyvsuqe1ew8se087.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8n8tuyvsuqe1ew8se087.png" alt="Management Log File" width="800" height="597"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Password.txt File&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw94og8h91738x2k3e20u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw94og8h91738x2k3e20u.png" alt="Password.txt file" width="800" height="125"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Bash is a powerful scripting tool used to automate various tasks on Unix-like operating systems. This script is designed to read a text file containing usernames and their respective groups, create users and their personal groups, assign users to additional groups, set up home directories, generate random passwords, and log all these actions for auditing purposes. Additionally, it stores the generated passwords securely in a dedicated file.&lt;/p&gt;

&lt;p&gt;This project is a stage 1 task in the Devops HNG-11 Internship. For more information about the HNG Internship and its various opportunities, visit &lt;a href="https://hng.tech/" rel="noopener noreferrer"&gt;HNG Internship&lt;/a&gt; and &lt;a href="https://hng.tech/hire" rel="noopener noreferrer"&gt;HNG Hire&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>bash</category>
      <category>devops</category>
      <category>sysadmin</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Hosting WordPress on Ubuntu: A Step-by-Step Guide</title>
      <dc:creator>Florence Okoli</dc:creator>
      <pubDate>Sun, 26 May 2024 22:10:15 +0000</pubDate>
      <link>https://dev.to/florenceokoli/hosting-wordpress-on-ubuntu-a-step-by-step-guide-3707</link>
      <guid>https://dev.to/florenceokoli/hosting-wordpress-on-ubuntu-a-step-by-step-guide-3707</guid>
      <description>&lt;p&gt;Let's say you are a blogger or even a small business owner looking for a way to share your insights or products with the world at large. For this, you would need a perfect platform for your website that is also flexible with a vast array of plugins.&lt;br&gt;
Well, here comes &lt;strong&gt;WordPress&lt;/strong&gt; to the rescue. &lt;/p&gt;

&lt;p&gt;You now have a great platform, but you may want the freedom to customize your server environment and ensure that every aspect of your website runs exactly as you want, without relying on managed hosting services.&lt;br&gt;
Okay. &lt;strong&gt;Ubuntu&lt;/strong&gt; comes into play and combined with the power of the &lt;strong&gt;LAMP&lt;/strong&gt; stack (Linux, Apache, MySQL, PHP) gives you complete control over your website.&lt;/p&gt;

&lt;p&gt;All these may seem daunting at first but in this guide, I will walk you through the process of hosting WordPress on Ubuntu using the LAMP stack.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overview of Key Components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we delve into the step-by-step process, let's take a brief look at what WordPress, Ubuntu, and the LAMP stack are, and their roles in this project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;WordPress&lt;/strong&gt; - WordPress is a widely used content management system (CMS) for creating and managing websites. It is well-known for its user-friendly interface and extensive library of plugins and themes. With WordPress, you can build anything from basic blogs to advanced e-commerce sites without requiring advanced technical skills. In this guide, WordPress will serve as the platform for creating and managing your website's content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ubuntu&lt;/strong&gt; - Ubuntu is a popular, open-source Linux operating system known for its stability, security, and ease of use. In this project, Ubuntu serves as the foundation, hosting the web server and other essential software components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;LAMP Stack&lt;/strong&gt; - LAMP is a set of open-source software for creating web servers, comprising Linux (Ubuntu as the operating system), Apache (webserver), MySQL (database), and PHP (scripting language). Each component is important and here is what they will do in this project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linux: Provides the Operating System foundation.&lt;/li&gt;
&lt;li&gt;Apache: Handles browser requests and serves web pages.&lt;/li&gt;
&lt;li&gt;MySQL: Manages the WordPress database.&lt;/li&gt;
&lt;li&gt;PHP: Processes dynamic content and interacts with the 
database.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An Ubuntu Server: You can use either a local machine(Vagrant virtual box)or a cloud-based virtual private server from AWS, Digital Ocean or Google Cloud.&lt;/li&gt;
&lt;li&gt;A basic understanding of Linux commands&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Steps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update your package index&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This command &lt;code&gt;sudo apt update&lt;/code&gt; updates the package lists for upgrades and new package installations from the repositories defined in your system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fisha8cqjhtgw8h3bx2zx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fisha8cqjhtgw8h3bx2zx.png" alt="sudo apt update" width="612" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To install Apache2 and PHP, run the following command
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install apache2 \
                 ghostscript \
                 libapache2-mod-php \
                 mysql-server \
                 php \
                 php-bcmath \
                 php-curl \
                 php-imagick \
                 php-intl \
                 php-json \
                 php-mbstring \
                 php-mysql \
                 php-xml \
                 php-zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Copy and paste this command into a text file before pasting it into your virtual environment to avoid errors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foqtzczfqwsdxv2pwe621.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foqtzczfqwsdxv2pwe621.png" alt="Installing Dependencies" width="738" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install WordPress&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let's create a new directory first and change the ownership of 
this directory to the user &lt;code&gt;www-data&lt;/code&gt; to ensure that the 
webserver has the appropriate access to these files.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3s2k2igz3gbaz39irvw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3s2k2igz3gbaz39irvw7.png" alt="Create a new directory" width="638" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, let's download the latest version of WordPress and extract it into the &lt;code&gt;/srv/www&lt;/code&gt; directory.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnx807vsna6084fx9rj2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnx807vsna6084fx9rj2.png" alt="Download the latest version of Wordpress" width="800" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is what the code does:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This &lt;code&gt;curl https://wordpress.org/latest.tar.gz&lt;/code&gt; command uses &lt;code&gt;curl&lt;/code&gt; to download the file at the given URL, which is the latest version of WordPress in a gzipped tarball format. &lt;br&gt;
The pipe &lt;code&gt;|&lt;/code&gt; command takes the output of the command on its left and uses it as the input to the command on its right.&lt;br&gt;
&lt;code&gt;sudo -u www-data&lt;/code&gt;: This runs the following command as the &lt;code&gt;www-data&lt;/code&gt; user. This is done because the &lt;code&gt;/srv/www directory&lt;/code&gt; is owned by &lt;code&gt;www-data&lt;/code&gt;, which we set earlier if you can remember &lt;br&gt;
This command &lt;code&gt;tar zx -C /srv/www&lt;/code&gt; extracts the gzipped tarball. The &lt;code&gt;z&lt;/code&gt; option tells tar to uncompress the file (as it is gzipped), the &lt;code&gt;x&lt;/code&gt; option tells it to extract the files from the tarball, and the &lt;code&gt;-C /srv/www&lt;/code&gt; option tells it to change to the &lt;code&gt;/srv/www&lt;/code&gt; directory before doing so.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To confirm you followed the above step correctly, run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -l /srv/www/wordpress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see an image like the one below, then you are on track.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flz2ec25aejvzu60zoydc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flz2ec25aejvzu60zoydc.png" alt="Confirm Installation of WordPress" width="796" height="421"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Configure Apache for WordPress&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To configure Apache for WordPress, run this command to create and edit WordPress configuration file
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vi /etc/apache2/sites-available/wordpress.conf

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnp2oaekg89a2i5wmvg3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqnp2oaekg89a2i5wmvg3.png" alt="Create a wordpress.conf file" width="800" height="33"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command above opens up an empty configuration file. Copy the codes below and paste them into the configuration file. Then, save it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
    DocumentRoot /srv/www/wordpress
    &amp;lt;Directory /srv/www/wordpress&amp;gt;
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    &amp;lt;/Directory&amp;gt;
    &amp;lt;Directory /srv/www/wordpress/wp-content&amp;gt;
        Options FollowSymLinks
        Require all granted
    &amp;lt;/Directory&amp;gt;
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8y0wcjxbkycjew55ocz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8y0wcjxbkycjew55ocz.png" alt="WordPress Configuration File" width="757" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When this is done, enable the site using this command - &lt;code&gt;sudo 
a2ensite wordpress&lt;/code&gt;  and then enable URL rewriting using this 
command &lt;code&gt;sudo a2enmod rewrite&lt;/code&gt; lastly, disable the default site 
using &lt;code&gt;sudo a2dissite 000-default&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7dggujk9mbd7417etns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7dggujk9mbd7417etns.png" alt="Enable, disable site and rewrite URL" width="574" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To finish up with this step, reload apache2 to apply all these 
changes
&lt;code&gt;sudo service apache2 reload&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Configure MySQL Database&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Before we proceed, it is important to note that MySQL commands end with ; or /g&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's begin with opening up the MySQL CLI using this command&lt;br&gt;
&lt;code&gt;sudo mysql -u root&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This command opens the MySQL command-line client as the root user&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft00a895yvqwmie32wn8f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft00a895yvqwmie32wn8f.png" alt="MySQL CLI" width="710" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now, we create a database called wordpress, create a user for 
this database and give it a unique password. Next, we grant 
privileges to this user and with the flush privileges command, 
we reload the user privileges from the grant tables in the 
MySQL database.
Here is the code at play:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE wordpress;
CREATE USER wordpress@localhost IDENTIFIED BY '&amp;lt;your-password&amp;gt;';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO wordpress@localhost;
FLUSH PRIVILEGES;
quit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Please note that these commands should be copied one after the * other into the CLI to avoid errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6dhqcgvs1xkucbik3ao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6dhqcgvs1xkucbik3ao.png" alt="Create MySQL Database" width="800" height="317"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To apply these changes we made, let's enable the MySQL service 
with this command here - &lt;code&gt;sudo service mysql start&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Configure WordPress to connect to the database&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, let's create a new configuration file for WordPress by 
copying the sample configuration file to &lt;code&gt;wp-config.php&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fun8wt4algx215yeukocs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fun8wt4algx215yeukocs.png" alt="Copy WordPress Sample Config file" width="800" height="15"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, we configure the credentials in the configuration file. 
Please note that the only thing you are expected to change in 
the commands below is your password. 
Remember the unique password you created when you were creating 
the MySQL database? Yeah, that's the one.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here/&amp;lt;your-password&amp;gt;/' /srv/www/wordpress/wp-config.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk9yg8mdx2qqxqoeof3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwk9yg8mdx2qqxqoeof3j.png" alt="Credentials of the config file" width="800" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we need to edit the WordPress config file. Use this command 
to open and edit the config file &lt;code&gt;sudo -u www-data 
/srv/www/wordpress/wp-config.php&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;In your config file, scroll down to where you will find the 
commands below:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now delete these commands above and replace them with the 
content you will find &lt;a href="https://api.wordpress.org/secret-key/1.1/salt/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. (This address is a randomiser that 
returns completely random keys each time it is opened.) 
See mine below:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwkcgbhx34wkyqo7qsxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwkcgbhx34wkyqo7qsxy.png" alt="WordPress Configuration" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This step is important to ensure that your site is not vulnerable to attacks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Save the changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customize WordPress to serve your web pages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On your terminal, run this command &lt;code&gt;ip a&lt;/code&gt; to copy the IP 
address of your local machine. Copy and then paste the address 
on your browser. You will see an image similar to the one below 
upon loading your browser. Click on "continue" to customize 
WordPress for hosting your web pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxan309b5rnvhxqm0ww1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxan309b5rnvhxqm0ww1.png" alt="Customize WordPress" width="800" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, enter the title of your new site, username, password, and 
a valid e-mail address. Note that the username and password you 
choose here are for the WordPress site and not the ones you 
used for the MySQL database earlier.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Click on Install WordPress to continue&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzexzknzqwl3jly4ki4ic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzexzknzqwl3jly4ki4ic.png" alt="Information page" width="800" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now, let's log in with our details&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo43to9ehsewrfyyfvr4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo43to9ehsewrfyyfvr4u.png" alt="Login Page" width="613" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once you log in to the WordPress dashboard, you will find a variety of icons and options to customize your website according to your preferences.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8blnwclnt8mgomn95u6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8blnwclnt8mgomn95u6g.png" alt="Customize your site" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;C'est fini!!&lt;/p&gt;

&lt;p&gt;Congratulations on taking the first step toward creating your own WordPress website on Ubuntu using the powerful LAMP stack! By following this guide, you've set up a flexible and customizable platform for sharing your insights, products, or even services with the world.&lt;/p&gt;

&lt;p&gt;I hope you found this tutorial helpful and easy to follow. &lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>ubuntu</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Automate your tasks and schedule cronjobs with a script</title>
      <dc:creator>Florence Okoli</dc:creator>
      <pubDate>Thu, 23 May 2024 12:30:39 +0000</pubDate>
      <link>https://dev.to/florenceokoli/automate-your-tasks-and-schedule-cronjobs-with-a-script-2de5</link>
      <guid>https://dev.to/florenceokoli/automate-your-tasks-and-schedule-cronjobs-with-a-script-2de5</guid>
      <description>&lt;p&gt;Have you ever wondered how computers can do tasks all by themselves without anyone touching them? It's like magic, but there's a special way to tell the computer what to do, step by step. This is called scripting. &lt;br&gt;
This article will explore the basics of Bash scripting, provide practical examples, and guide you through creating your scripts.&lt;br&gt;
Let's dive in! &lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is Bash Scripting?&lt;/strong&gt; &lt;br&gt;
Bash scripting is a powerful tool for automating tasks on Unix-like operating systems, such as Linux and macOS. &lt;br&gt;
Bash, short for the "Bourne Again Shell," is a powerful scripting language that enables users to automate repetitive tasks, streamline complex workflows, and efficiently manage system operations instead of doing them manually.&lt;br&gt;
Overall, bash scripting is an essential skill for system administrators, developers, and anyone looking to optimize their computing tasks.&lt;/p&gt;

&lt;p&gt;In Bash scripting, the Shebang &lt;code&gt;#!/bin/bash&lt;/code&gt;, serves as the interpreter used to execute tasks on any script. In other words, it tells the system to use the specified interpreter to run the script. &lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Vagrant virtual machine&lt;/li&gt;
&lt;li&gt;Good understanding of Linux commands&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Basics to Know Before Writing a Bash Script
&lt;/h2&gt;

&lt;p&gt;Before diving into writing Bash scripts, it's essential to understand some fundamental concepts and components of Bash scripting. Here are the basics you need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Familiarize yourself with basic Unix commands like &lt;code&gt;mkdir&lt;/code&gt;, &lt;code&gt;touch&lt;/code&gt;, and &lt;code&gt;echo&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand file permissions and how to change them using &lt;code&gt;chmod&lt;/code&gt;. For example, to make your script executable, use &lt;code&gt;chmod +x&lt;/code&gt;. The X stands for execution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use a text editor like Nano or Vim to write and edit scripts. &lt;br&gt;
For Nano - &lt;code&gt;nano myscript.sh&lt;/code&gt; For Vim - &lt;code&gt;vi myscript.sh&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add comments in your scripts using &lt;code&gt;#&lt;/code&gt; symbol. They help explain what the script does and are ignored during execution.&lt;br&gt;
&lt;code&gt;# This is a comment&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Always start your script with a Shebang. It specifies the interpreter to be used. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lastly, for every script, you must make sure to follow the syntax which includes the spacing, indentation, and punctuation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's begin&lt;/p&gt;
&lt;h2&gt;
  
  
  Practical Examples of Bash Scripting
&lt;/h2&gt;

&lt;p&gt;Let's start by creating a new directory that will house all our scripts. Once the directory is created, &lt;code&gt;cd&lt;/code&gt; into the folder and create a file with the &lt;code&gt;.sh&lt;/code&gt; extension. The &lt;code&gt;.sh&lt;/code&gt; tells you that the file is a script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir bashscript
cd bashscript
touch myscript.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn633k6qfrqiwodvibjd9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn633k6qfrqiwodvibjd9.png" alt="Create new directory and file for your scripte" width="794" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's make our newly created scripts executable. This will enable us to run our script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x myscript.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsin8d70q82q3lsl23z4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsin8d70q82q3lsl23z4w.png" alt="Execute script and check file permission" width="800" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ll&lt;/code&gt; command shows the permissions for the myscript.sh file&lt;/p&gt;

&lt;p&gt;Next, let's play around with automation.&lt;/p&gt;

&lt;p&gt;To do this, let's write a script that updates and upgrades our system.&lt;br&gt;
This command &lt;code&gt;vi myscript.sh&lt;/code&gt; opens the file named &lt;code&gt;script.sh&lt;/code&gt; in the &lt;code&gt;vi&lt;/code&gt; text editor.&lt;/p&gt;

&lt;p&gt;When the file is opened in the Vim text editor, write the following codes below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
sudo apt update -y
sudo apt upgrade -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhqrohe5ttnzayjy3jmr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhqrohe5ttnzayjy3jmr.png" alt="System Update and Upgrade" width="699" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Close your text editor and run this command - &lt;code&gt;./myscript.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvr2kksk9s9tyblfspv19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvr2kksk9s9tyblfspv19.png" alt="Run your script" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have seen what automation looks like using a bash script, let's get more practical.&lt;/p&gt;

&lt;h2&gt;
  
  
  Statements in Bash Scripting
&lt;/h2&gt;

&lt;p&gt;i. Printing statements using the &lt;code&gt;echo&lt;/code&gt; command. &lt;br&gt;
The echo command in Bash scripting is used to print output to the terminal. Let's try it out.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;First, create a script. I called my script &lt;code&gt;myscript.sh&lt;/code&gt;. Then use the Vim text editor to open it &lt;code&gt;vi myscript.sh&lt;/code&gt; Remember to start your script with the Shebang &lt;code&gt;#!/bin/bash&lt;/code&gt; interpreter followed by the &lt;code&gt;echo&lt;/code&gt; command and your text in quotes. Then close the editor.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo "Florence is a Cloud Engineer who loves bash Scripting"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0g4viicrpzxa322ny6i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs0g4viicrpzxa322ny6i.png" alt="Echo Command" width="800" height="102"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run your script using the &lt;code&gt;./&amp;lt;name of your script&amp;gt;&lt;/code&gt; The output will look like the image below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6o1jpzo1idj799n7ekj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy6o1jpzo1idj799n7ekj.png" alt="Output of Echo Command" width="800" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ii. Declaring variables. &lt;br&gt;
Variables in bash scripting are used to store data and can be referenced in your script to perform operations. Here is how to declare a variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
name="Florence"
job="Cloud Engineer"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03txw6kyfio25a2l1in8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03txw6kyfio25a2l1in8.png" alt="Declare Variable" width="800" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There should be no spaces around the equals sign. The value can be a number, a string, or the result of a command.&lt;br&gt;
To read or use the value stored in a variable, you prepend the variable name with a dollar sign &lt;code&gt;$&lt;/code&gt;. For example:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
echo "My name is $name and I'm a $job"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytnqgv5f3a932iq9yl5z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytnqgv5f3a932iq9yl5z.png" alt="Declare Variables" width="621" height="43"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When this script is run using the &lt;code&gt;./myscript.sh&lt;/code&gt; this is what it will look like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqeico4rbdkcpuvsha4cu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqeico4rbdkcpuvsha4cu.png" alt="Output" width="790" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iii. If Statements&lt;br&gt;
The If statement allows your script to make decisions and perform different actions depending on whether a condition is true or false. In the example below, we are going to run a script that checks whether a given number is an even or odd number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;read -p "Enter a number: " number

if (( $number % 2 == 0 )); then
   echo "$number is an even number"
else
   echo "$number is an even number"
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv8vaors1onnalal3erjq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv8vaors1onnalal3erjq.png" alt="Snippet of the if statement" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A breakdown of the script:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;read -p "Enter a number: " number&lt;/code&gt;: Prompts the user to enter a number and stores it in the number variable.&lt;br&gt;
&lt;code&gt;if (( number % 2 == 0 )); then&lt;/code&gt;: Checks if the number is even.&lt;br&gt;
&lt;code&gt;echo "The number $number is even."&lt;/code&gt;: Prints that the number is even if the condition is true.&lt;br&gt;
&lt;code&gt;else&lt;/code&gt;: Executes the following code if the number is not even.&lt;br&gt;
&lt;code&gt;echo "The number $number is odd."&lt;/code&gt;: Prints that the number is odd.&lt;br&gt;
&lt;code&gt;fi&lt;/code&gt;: Ends the if statement.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When the above script is run, here is what the result will look like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2h1vs16rb5fyrqc9miz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2h1vs16rb5fyrqc9miz.png" alt="Output of the if statement" width="786" height="249"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iv. While Loop&lt;br&gt;
In Bash scripting, the &lt;code&gt;while&lt;/code&gt; loop allows you to repeatedly execute a block of code as long as a specified condition remains true. Once the condition becomes false, the loop stops executing. This is similar to a washing machine cycle: it keeps running until the timer reaches zero.&lt;/p&gt;

&lt;p&gt;Let's write a script that checks if a particular directory exists or not. In this case, we are checking if the &lt;code&gt;~bash/loopdir&lt;/code&gt; exists in our system&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

while [ -d ~bash/loopdir ]; do
    echo "Directory exists"
done
    echo"Directory does not exist"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68cw0xyymwzqmbcz0fmc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68cw0xyymwzqmbcz0fmc.png" alt="Snippet of the While Loop" width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A breakdown of the script:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;while [ -d ~/bash/loopdir ]; do&lt;/code&gt;: Starts a while loop that checks if the directory ~/bash/loopdir exists.&lt;br&gt;
&lt;code&gt;echo "Directory exists"&lt;/code&gt;: If the directory exists, prints "Directory exists".&lt;br&gt;
&lt;code&gt;done&lt;/code&gt;: Ends the while loop when the directory no longer exists.&lt;br&gt;
&lt;code&gt;echo "Directory not found"&lt;/code&gt;: After exiting the loop, prints "Directory not found" when the directory is no longer present.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, that you have gotten to this point, let's do something interesting. Let's create a script that monitors the uptime of a server and logs it periodically. In this script, we are also going to incorporate a cronjob that will record the server's uptime at specified intervals.&lt;/p&gt;

&lt;p&gt;Before we start, let me explain what a cronjob does and why it is needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A cron job is just like that magical clock for your computer! It helps your computer remember to do certain tasks automatically, without you having to tell it every time.&lt;br&gt;
Let me be more technical now. &lt;br&gt;
A cron job is a time-based job scheduler in Unix-like operating systems, including Linux. It allows users to schedule commands or scripts to run periodically at fixed times, dates, or intervals. These scheduled tasks are referred to as cron jobs, and they can automate repetitive tasks, such as backups, system maintenance, uptime monitoring, log rotation, etc.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, let's create that script!&lt;br&gt;
With this command &lt;code&gt;sudo vi log_uptime.sh&lt;/code&gt; I will create a script for this particular task and make it executable using &lt;code&gt;sudo chmod +x log_uptime.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81lhsq1ve5ufvt81uhbl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81lhsq1ve5ufvt81uhbl.png" alt="Create Script" width="683" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's write the script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Define the log file
LOG_FILE="$HOME/uptime_log.txt"

# Create the log file if it doesn't exist
if [ ! -f "$LOG_FILE" ]; then
    touch "$LOG_FILE"
    echo "Log file created at $LOG_FILE"
fi

# Get the current date and uptime
CURRENT_DATE=$(date '+%Y-%m-%d %H:%M:%S')
UPTIME=$(uptime -p)

# Append the uptime to the log file
echo "$CURRENT_DATE - Uptime: $UPTIME" &amp;gt;&amp;gt; "$LOG_FILE"
echo "Uptime logged at $CURRENT_DATE"

# Define the cron job command
CRON_JOB="0 * * * * $HOME/log_uptime.sh"

# List existing cron jobs
echo "Current Cron Jobs:"
crontab -l

# Add the cron job
echo "Adding new cron job:"
echo "$CRON_JOB" | crontab -

# Confirmation of added cron job
echo "New cron job added:"
crontab -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl78tvlnwkhxh9ldzsm2n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl78tvlnwkhxh9ldzsm2n.png" alt="Bash script" width="688" height="935"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When this script is run using the &lt;code&gt;./log_uptime.sh&lt;/code&gt; command, here is what the output will be&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqhewfjzz76zkmtz1jav.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqhewfjzz76zkmtz1jav.png" alt="Output of the Script" width="544" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Scripting in Bash is like giving instructions to your computer to do tasks automatically. This article introduced the basics of Bash scripting, providing practical examples by creating readable scripts. With Bash scripting, you can automate repetitive tasks and manage system operations efficiently.&lt;/p&gt;

&lt;p&gt;Your feedback is very important to me. Were the explanations clear? Did the examples make sense? Let me know if there's anything specific you'd like me to cover in more detail. I'm here to ensure I meet your needs.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

</description>
      <category>bash</category>
      <category>devops</category>
      <category>cloudcomputing</category>
      <category>cronjob</category>
    </item>
    <item>
      <title>Hosting a static website on an S3 bucket using Amazon CloudFront</title>
      <dc:creator>Florence Okoli</dc:creator>
      <pubDate>Sat, 11 May 2024 20:27:55 +0000</pubDate>
      <link>https://dev.to/florenceokoli/hosting-a-static-website-on-an-s3-bucket-using-amazon-cloudfront-ob2</link>
      <guid>https://dev.to/florenceokoli/hosting-a-static-website-on-an-s3-bucket-using-amazon-cloudfront-ob2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Imagine you're an aspiring photographer, eager to share your stunning portfolio with the world. You've spent countless hours perfecting your website, featuring captivating images that showcase your talent. And you want viewers from across the globe to visit your website and explore your work. Here is where Amazon S3 bucket and CloudFront come in.&lt;br&gt;
Here is what happens when you deploy your photography website using Amazon S3 bucket and CloudFront. S3 securely stores your high-resolution images and website files in a bucket, while CloudFront ensures that these objects are delivered swiftly to visitors worldwide.&lt;br&gt;
In this guide, we will host a static website on an Amazon S3 bucket(private bucket) but with a public read policy assigned, using CloudFront for Content Delivery Network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Static Website&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A static website is a type of website that presents fixed content to users, using basic web technologies. It is lightweight, fast-loading, and easy to maintain. A static website consists of only client-side technologies such as HTML, CSS, and JavaScript. It doesn't require a server to generate or serve content dynamically.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Amazon S3&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An Amazon S3 (Simple Storage Service) bucket is a fundamental component of Amazon Web Services (AWS) that provides scalable object storage in the cloud. An Amazon S3 (Simple Storage Service) bucket serves as a fundamental storage container within the S3 service. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Amazon CloudFront &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amazon CloudFront is a content delivery network (CDN) service provided by Amazon Web Services (AWS). Its primary function is to deliver content, such as web pages, videos, images, and other static or dynamic assets, to users with low latency and high transfer speeds.&lt;/p&gt;

&lt;p&gt;By integrating these two services, you can easily store your website's content on Amazon S3 and deliver it quickly to your users using CloudFront's content delivery network (CDN)  &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An AWS account&lt;/li&gt;
&lt;li&gt;Files or folders for your static website. I used this template &lt;a href="https://startbootstrap.com/theme/agency" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Follow the steps below to host a static website on an S3 bucket using CloudFront.
&lt;/h2&gt;

&lt;p&gt;Step 1.  Create an Amazon S3 bucket&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log in on your AWS management console and search for the S3 service. Proceed to create a bucket as seen below:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq57wxaxl5p5n8b9n97e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq57wxaxl5p5n8b9n97e.png" alt="Create S3 bucket" width="800" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the general purpose type for your bucket and a unique name for your bucket. 
If the name is not unique, you won't be able to create a bucket.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6y51x7znbd2utmdzw4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6y51x7znbd2utmdzw4e.png" alt="Bucket type and name" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leave all other settings on default. Scroll down and click on Create Bucket.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxru7y28bs2qq0zzfmos7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxru7y28bs2qq0zzfmos7.png" alt="Click on Create Bucket" width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once the bucket has been successfully created, click on &lt;em&gt;view details&lt;/em&gt; or your bucket name to view the details of the bucket created.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6pg2d7cu3llpabtfndm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6pg2d7cu3llpabtfndm.png" alt="Click on view bucket details" width="800" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 2. Upload files into the S3 bucket&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the bucket overview page, under the objects tab, click on upload to upload the files/folders for your website.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4tzb2jc8mu16rzqhuxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4tzb2jc8mu16rzqhuxz.png" alt="Upload Objects" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Drag and drop your files or add them as files/folders.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnq0oi301lldkh53300kc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnq0oi301lldkh53300kc.png" alt="Add files/folders" width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scroll to the end of the page and click on upload.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcorxej2c78eyklmy5oev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcorxej2c78eyklmy5oev.png" alt="Upload files" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once the upload has been successful as seen in the image below, close the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxacewqfjqygf47q6a25.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxacewqfjqygf47q6a25.png" alt="Successful Upload" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 3. Create a CloudFront Distribution for content delivery&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the AWS management console, search for Cloudfront and click on it. Then proceed to create a CloudFront distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifgzp8z6lj0vqjoamx8a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifgzp8z6lj0vqjoamx8a.png" alt="CloudFront Service" width="800" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, enter an origin name. It should be the same as the name you have as your bucket.
Proceed to create a new Origin Access Control. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The reason for introducing Origin Access Control is to restrict access to the bucket. Remember we are trying to make our S3 bucket private right? The Origin Access Control will do that for us.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See the image below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe036t4f2c1m7xgok63l9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe036t4f2c1m7xgok63l9.png" alt="Origin name" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favaxpamm129f9cydial5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favaxpamm129f9cydial5.png" alt="Origin Access Control" width="800" height="757"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set your WAF to &lt;strong&gt;Do not enable security protection&lt;/strong&gt; since this is for practice. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgqjb0n3motoxg63p2pj4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgqjb0n3motoxg63p2pj4.png" alt="WAF Security settings" width="800" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leave every other setting on default and proceed to create your distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff59gea4tbl0eaia0kdxk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff59gea4tbl0eaia0kdxk.png" alt="CloudFront Settings" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To complete the distribution configuration, copy the policy and click on &lt;strong&gt;Go to S3 permissions to update policy&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzsoxr3u177a0no2qcghy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzsoxr3u177a0no2qcghy.png" alt="CloudFront Distribution Config" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the permissions tab under your bucket, scroll to bucket policy and click edit. Then paste the policy. Here is what it should look like
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
        "Version": "2008-10-17",
        "Id": "PolicyForCloudFrontPrivateContent",
        "Statement": [
            {
                "Sid": "AllowCloudFrontServicePrincipal",
                "Effect": "Allow",
                "Principal": {
                    "Service": "cloudfront.amazonaws.com"
                },
                "Action": "s3:GetObject",
                "Resource": "arn:aws:s3:::florence-okoli/*",
                "Condition": {
                    "StringEquals": {
                      "AWS:SourceArn": "arn:aws:cloudfront::xxxxxxxxxxxx:distribution/E1FC6K30Z0Z15Y"
                    }
                }
            }
        ]
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5gywjgeqjjbcxbj8p1ze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5gywjgeqjjbcxbj8p1ze.png" alt="New Bucket Policy" width="800" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save changes and proceed to your CloudFront page to copy your Distribution domain name. Paste it on your browser and add /index.html to it. Make sure to use your Distribution domain name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxleurlapkk0r0tnfpp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxleurlapkk0r0tnfpp3.png" alt="Distribution Domain Name" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finally, the outcome of your page should look like this&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3xavzk3samo9m7t7l1ym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3xavzk3samo9m7t7l1ym.png" alt="Final outlook of your website" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To avoid incurring charges on AWS, delete the resources you used in this guide, including S3 buckets and the CloudFront Distribution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations on successfully hosting your static website with Amazon S3 and CloudFront! &lt;br&gt;
By combining the benefits of storage durability with the global performance optimization of a content delivery network (CDN), you have created a fast and reliable website for users across the world to enjoy. &lt;br&gt;
By configuring your CloudFront with an Origin Access Identity (OAI), you have ensured that your S3 bucket remains private while delivering content swiftly and securely. &lt;/p&gt;

</description>
      <category>devops</category>
      <category>aws</category>
      <category>cloud</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to host a web page with Apache</title>
      <dc:creator>Florence Okoli</dc:creator>
      <pubDate>Mon, 29 Apr 2024 15:41:49 +0000</pubDate>
      <link>https://dev.to/florenceokoli/how-to-host-a-web-page-with-apache-25kb</link>
      <guid>https://dev.to/florenceokoli/how-to-host-a-web-page-with-apache-25kb</guid>
      <description>&lt;p&gt;Deploying websites on cloud servers has become a standard practice due to its scalability, flexibility, and accessibility. This article delves into the process of hosting a custom web page on Amazon Web Services (AWS) using Apache as the web server and Ubuntu as the operating system. &lt;/p&gt;

&lt;p&gt;Table of Contents&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Set up EC2 Instance&lt;/li&gt;
&lt;li&gt;Install Apache webserver&lt;/li&gt;
&lt;li&gt;Deploy your custom web page.&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;- Introduction&lt;/strong&gt;&lt;br&gt;
The Apache web server is like a reliable backbone that confidently handles the traffic powering websites and applications worldwide. Its versatility goes beyond simply hosting web pages. It is a powerhouse of features designed to keep your online presence secure, performant, and easily customizable.&lt;br&gt;
In other words, Apache is a widely used open-source web server software that serves web content over the internet with key functionalities such as HTTP protocol handling, content delivery, virtual hosting among others. Apache is also highly compatible with various operating systems (e.g., Linux, Unix, Windows)&lt;br&gt;
This article provides a detailed guide on how to host your custom web page with Apache.&lt;/p&gt;

&lt;p&gt;Let's begin!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Set up EC2 Instance&lt;/strong&gt;&lt;br&gt;
Log in to your AWS console. On the search bar, type in EC2. On the EC2 dashboard, scroll down and proceed to launch an instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxj2fgj12zh3mbss4q6f5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxj2fgj12zh3mbss4q6f5.png" alt="EC2 Launch" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose a name for your EC2 instance&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62umtq9nu0r39d9ihjyy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62umtq9nu0r39d9ihjyy.png" alt="EC2 launch page " width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Proceed to select your AMI(Amazon Machine Image). For this article, we will select the Ubuntu AMI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfvvtf52yxoj7rlp65yz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfvvtf52yxoj7rlp65yz.png" alt="Ubuntu AMI" width="800" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll down to generate your key pair. We need it to be able to connect to the terminal. If you already have a key pair, you can use it at this point.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg85daa26z2hvjusbnc6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg85daa26z2hvjusbnc6x.png" alt="Key pair generation" width="800" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's create a key pair. Choose a name for your key pair, select the key pair type and proceed to create it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsehfesfieai6nghz9218.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsehfesfieai6nghz9218.png" alt="Create key pair" width="800" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the security group settings, set the SSH, HTTPS and HTTP to allow traffic from anywhere and also from the internet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F73iu3s324c4w17ww682m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F73iu3s324c4w17ww682m.png" alt="Security group" width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Leave every other setting on default and proceed to launch your instance.&lt;br&gt;
Once the EC2 instance has been launched successfully, you will see 2/2 checks passed underneath the status check.&lt;/p&gt;

&lt;p&gt;Next, click on the instance ID &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxhsbfzlt2x6odzegm4s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxhsbfzlt2x6odzegm4s.png" alt="Instance ID" width="800" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And connect via the EC2 Instance Connect. &lt;br&gt;
See the images below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzmvoxlq8wacjaumfkxdo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzmvoxlq8wacjaumfkxdo.png" alt="EC2 connect" width="800" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxf8gmxhokkzn7o95kuw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcxf8gmxhokkzn7o95kuw.png" alt="Ec2 Instance connect" width="800" height="370"&gt;&lt;/a&gt;&lt;br&gt;
Take note of the public IP address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Install Apache Web Server&lt;/strong&gt;&lt;br&gt;
Once you have connected and are in the terminal, run this command first to update your packages and dependencies.&lt;br&gt;
&lt;code&gt;sudo apt update&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2id83q6uwe4g9nloquf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2id83q6uwe4g9nloquf.png" alt="Isudo apt update" width="800" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, install apache2.&lt;br&gt;
&lt;code&gt;sudo apt install apache2 -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The "-y" flag in the command above instructs the package manager to proceed with the installation without asking for confirmation. In other words, it bypasses the user's input during installations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nvvlzfhmixqvaomalwc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nvvlzfhmixqvaomalwc.png" alt=" " width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Deploy your custom web page&lt;/strong&gt;&lt;br&gt;
i. Let's install git since we will be cloning a Github repo for this article.&lt;br&gt;
&lt;code&gt;sudo apt install git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ru1h5bhgew89rvt7t50.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ru1h5bhgew89rvt7t50.png" alt="Install git" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ii. Create a directory. This directory will be the location where you clone your Github repo. I'm using Florence as my directory, you can use any name of your choice.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir Florence&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wi8upnlc61hn444rftb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wi8upnlc61hn444rftb.png" alt="mkdir Florence" width="681" height="28"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's change our directory to the one we just created.&lt;br&gt;
&lt;code&gt;cd Florence/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5rbrx0iki2z83xojmiq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5rbrx0iki2z83xojmiq.png" alt="cd Florence/" width="532" height="37"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iii. Let's initialize git in the Florence directory.&lt;br&gt;
&lt;code&gt;git init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy3rqpgob6hunkounna6y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy3rqpgob6hunkounna6y.png" alt="git init" width="800" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iv. Let's clone our GitHub repository. This is the &lt;a href="https://github.com/WendyOkoli/AltSchool-Assignment-3" rel="noopener noreferrer"&gt;link &lt;/a&gt;to my GitHub repository. &lt;/p&gt;

&lt;p&gt;See the image below on how to copy the link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fily73bikik58ursz87dk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fily73bikik58ursz87dk.png" alt="Github repo" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To clone the GitHub repo&lt;br&gt;
&lt;code&gt;git clone https://github.com/WendyOkoli/AltSchool-Assignment-3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffmir8xhgwbh00khnmzls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffmir8xhgwbh00khnmzls.png" alt="Github repo clone" width="800" height="132"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iv. Let's create another directory but this time the directory will store web server files like &lt;em&gt;index.html, index.css&lt;/em&gt;, etc.&lt;br&gt;
To do this, let's run this command&lt;br&gt;
&lt;code&gt;sudo mkdir /var/www/FlorenceOkoli&lt;/code&gt;&lt;br&gt;
Whatever name you choose to call your directory, please note that the '/var/www/'should be in it for it to achieve the purpose of storing web server files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faritbzjpu14bsynsb3se.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faritbzjpu14bsynsb3se.png" alt="/var/www/FlorenceOkoli" width="800" height="20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;v. Let's copy the content of our 'Florence' directory into the one we just created.&lt;br&gt;
&lt;code&gt;sudo cp -R ./* /var/www/FlorenceOkoli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxkzbe3re0p4xo4m1uz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxkzbe3re0p4xo4m1uz8.png" alt="copy content" width="800" height="19"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's a breakdown of the command:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;sudo&lt;/strong&gt;&lt;/em&gt;: This stands for "superuser do". This command allows you to run other commands with administrative (root) privileges. It's necessary for commands that change system settings or modify system files, like this one.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;cp&lt;/strong&gt;&lt;/em&gt;: This is the command to copy files and directories.&lt;/p&gt;

&lt;p&gt;-R: This option tells cp to copy directories recursively, meaning it will copy all the files and subdirectories within any directory you specify.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;.&lt;/strong&gt;*&lt;/em&gt;: This is a wildcard that matches all files and directories in the current directory.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;/var/www/FlorenceOkoli&lt;/strong&gt;&lt;/em&gt;: This is the destination directory where the files and directories will be copied.&lt;/p&gt;

&lt;p&gt;vi. Let's create a new file named FlorenceOkoli.conf&lt;br&gt;
&lt;code&gt;sudo touch /etc/apache2/sites-available/ForenceOkoli.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrpjj7qtsxtknncoox8u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrpjj7qtsxtknncoox8u.png" alt="Create empty conf file" width="800" height="14"&gt;&lt;/a&gt;&lt;br&gt;
The command sudo touch &lt;code&gt;/etc/apache2/sites-available/FlorenceOkoli.conf&lt;/code&gt; creates a new empty file named &lt;code&gt;FlorenceOkoli.conf&lt;/code&gt; in the &lt;code&gt;/etc/apache2/sites-available/ directory&lt;/code&gt;.&lt;br&gt;
This is the first step in setting up a new web page with Apache.&lt;/p&gt;

&lt;p&gt;vii. Let's create a copy of the default Apache site configuration file and name it FlorenceOkoli.conf.&lt;br&gt;
To do this, let's run the command below&lt;br&gt;
&lt;code&gt;sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/FlorenceOkoli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkewi4yimjgyjfwizw145.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkewi4yimjgyjfwizw145.png" alt="copy 000-default.conf file to the .conf file" width="800" height="24"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;viii. Now that the FlorenceOkoli.conf file has been created, let's edit it to add the configuration of our new site.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo nano /etc/apache2/sites-available/FlorenceOkoli.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lyy6xxc0puaw7gws4zj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lyy6xxc0puaw7gws4zj.png" alt="Edit the file" width="800" height="17"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your conf file should look exactly like the image below. Edit the DocumentRoot to be &lt;code&gt;/var/www/name of your conf file&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03av454agaukjh6ls59v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03av454agaukjh6ls59v.png" alt="Conf file" width="800" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Save your file and exit.&lt;/p&gt;

&lt;p&gt;ix. Enable the FlorenceOkoli.conf file and disable the 000-default.conf file&lt;/p&gt;

&lt;p&gt;First, enable the FlorenceOkoli.conf file&lt;br&gt;
&lt;code&gt;sudo a2ensite FlorenceOkoli.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then disable the 000-default.conf file&lt;br&gt;
&lt;code&gt;sudo a2dissite 000-default.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F666w77tg8zf8zillzkag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F666w77tg8zf8zillzkag.png" alt="a2ensite &amp;amp; a2dissite" width="800" height="114"&gt;&lt;/a&gt;&lt;br&gt;
When these commands are run, it enables the site in the FlorenceOkoli.conf file and disables the site in 000-default.conf file.&lt;/p&gt;

&lt;p&gt;To activate these new configurations in the conf file, run this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo systemctl reload apache2&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F14aq1xk0wxxv3zg0v3k6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F14aq1xk0wxxv3zg0v3k6.png" alt="systemctl reload apache2" width="800" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, on your web browser where you have the displayed Apache web page, reload it and you will see your custom web page displayed. &lt;br&gt;
If you used my GitHub repo, the output of your web page should look like the image below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F478r6cr5cfx9jo5yxlbi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F478r6cr5cfx9jo5yxlbi.png" alt="WP web page" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As soon as you are done following this guide, please terminate your EC2 instances to avoid incurring costs from AWS. Let the images below guide you on how to terminate your instance.&lt;/p&gt;

&lt;p&gt;Go back to your console where you have your instance ID. Expand the Instance state box, click on terminate instance and follow the prompt.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4f0qqyfrn2f9yqu20fyd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4f0qqyfrn2f9yqu20fyd.png" alt="Instance termination" width="800" height="236"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj348e4lbgjanjye52c9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjj348e4lbgjanjye52c9.png" alt="Instance termination" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once this is done, you will find a pop-up like the image below to show that your instance has been successfully terminated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkamsu1i2t2qdorthkxsi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkamsu1i2t2qdorthkxsi.png" alt="Instance termination complete" width="800" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Congratulations on successfully hosting your custom web page using Apache on AWS! In this guide, we covered the essential steps to set up an EC2 instance, install an Apache web server, and deploy a custom web page. By leveraging cloud infrastructure and open-source tools like Git and Apache, you've created a scalable and accessible platform for showcasing your web page.&lt;/p&gt;

&lt;p&gt;Remember to terminate your EC2 instance to avoid unnecessary costs. Follow the provided steps to gracefully shut down your resources and manage your AWS environment efficiently.&lt;/p&gt;

&lt;p&gt;I encourage you to explore further with Apache and AWS, experiment with different configurations, and customize your web hosting setup to meet your specific needs. Your feedback is valuable to me- please feel free to share your thoughts and experiences with this guide. I'm here to assist and improve based on your insights.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>apache2</category>
      <category>awsdeployment</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>SMTP &amp; mailutils: How to send your mails via the Linux terminal.</title>
      <dc:creator>Florence Okoli</dc:creator>
      <pubDate>Sun, 28 Apr 2024 22:08:10 +0000</pubDate>
      <link>https://dev.to/florenceokoli/smtp-mailutils-how-to-send-your-mails-via-the-linux-terminal-1m7o</link>
      <guid>https://dev.to/florenceokoli/smtp-mailutils-how-to-send-your-mails-via-the-linux-terminal-1m7o</guid>
      <description>&lt;p&gt;Table of Contents&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Prerequisite&lt;/li&gt;
&lt;li&gt;Generate Google App password&lt;/li&gt;
&lt;li&gt;Launch your EC2 Instance&lt;/li&gt;
&lt;li&gt;Configuration of SSMTP&lt;/li&gt;
&lt;li&gt;Write and send your mail&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine being able to compose, attach files and send emails directly from your CLI using a few concise Linux commands. Well, the Linux terminal offers a streamlined and efficient alternative for sending emails using mailutils and the Simple Mail Transfer Protocol (SMTP). &lt;/p&gt;

&lt;p&gt;What is SMTP?&lt;br&gt;
SMTP stands for Simple Mail Transfer Protocol. It is a protocol used by email servers to send and receive email messages over the Internet. For instance, the email you send is transferred over the internet from one server to the other using SMTP. &lt;/p&gt;

&lt;p&gt;What is &lt;code&gt;mailutils&lt;/code&gt;?&lt;br&gt;
The &lt;code&gt;mailutils&lt;/code&gt; is a set of versatile utilities that manages emails directly from the CLI or Linux terminal using SMTP and other protocols. Some of the utilities include: &lt;br&gt;
&lt;code&gt;mail&lt;/code&gt;: This utility allows you to read and send emails interactively from the command line. &lt;br&gt;
&lt;code&gt;movemail&lt;/code&gt;: A utility that moves mail from one location to another.&lt;br&gt;
&lt;code&gt;frm&lt;/code&gt;: A utility to list the subject lines of email in a mailbox.&lt;br&gt;
&lt;code&gt;readmsg&lt;/code&gt;: A utility to read and print messages.&lt;/p&gt;

&lt;p&gt;This article will provide a guide on how to send mail seamlessly via the Linux terminal using SMTP and mailutils.&lt;/p&gt;

&lt;p&gt;Now, let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Prerequisite
&lt;/h2&gt;

&lt;p&gt;For this article, you will need:&lt;br&gt;
i. A Google account for your app password generation&lt;br&gt;
ii. A Linux terminal. I used the AWS console. You can sign up for a free 1yr tier account &lt;a href="https://aws.amazon.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Generate Google App Password
&lt;/h2&gt;

&lt;p&gt;On your Google account, locate the settings icon and click on manage your Google account. Take a look at the image attached below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvc0a9kw4mq9r2ph2fon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvc0a9kw4mq9r2ph2fon.png" alt="Google Account" width="800" height="659"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, go to the security settings and turn on your 2-step verification.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F18rq4589exi7xlzcx4w1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F18rq4589exi7xlzcx4w1.png" alt="Two-step verification" width="800" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll down the 2-step verification page and click on the App passwords. Type a name for your app and a password will be generated automatically. Make sure to copy and save this password as we will need it later.&lt;br&gt;
See the images attached below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F634dt1yvopzzktuu9r03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F634dt1yvopzzktuu9r03.png" alt="App Password" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk3te2w9sskf9elvw3rh6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk3te2w9sskf9elvw3rh6.png" alt="Generated App Password" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Launch EC2 Instance
&lt;/h2&gt;

&lt;p&gt;Once you log in on your AWS console, in the search bar, type EC2 and click on EC2. Click on instance and choose a name for your instance. See image below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ysbwf1obaacgv5ykofq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ysbwf1obaacgv5ykofq.png" alt="EC2 Instance" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select your AMI. For this article, we will use the Ubuntu AMI. So, go ahead and select your Ubuntu AMI. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjsh4pg5hd1wyomp86si.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjsh4pg5hd1wyomp86si.png" alt="ubuntu" width="800" height="548"&gt;&lt;/a&gt;&lt;br&gt;
Click on Launch instance.&lt;/p&gt;

&lt;p&gt;Next, click on instance ID. See the image below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd669vhfakjwfh5xlm7i2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd669vhfakjwfh5xlm7i2.png" alt="instance id" width="800" height="115"&gt;&lt;/a&gt;&lt;br&gt;
Then connect to the terminal&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ohnwh708p6hk79trh2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ohnwh708p6hk79trh2l.png" alt="Connect to your terminal" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Configuration of SMTP
&lt;/h2&gt;

&lt;p&gt;i. On your terminal, run &lt;code&gt;sudo apt update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F778855697yv2yo0bw53c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F778855697yv2yo0bw53c.png" alt="Sudo apt update" width="800" height="146"&gt;&lt;/a&gt;&lt;br&gt;
This command is run before installing new software with apt install to ensure you get the latest versions of packages and all their dependencies.&lt;/p&gt;

&lt;p&gt;ii. Install mailutils &lt;br&gt;
  &lt;code&gt;sudo apt update mailutils&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpp5jf36utwny6kqxkeb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpp5jf36utwny6kqxkeb.png" alt="mailutils" width="800" height="371"&gt;&lt;/a&gt;&lt;br&gt;
Please note that while the installation is running, a postfix configuration will pop up, select the internet site option using your arrow keys and then click ok to finish up with the installation.&lt;/p&gt;

&lt;p&gt;iii. Install SSMTP&lt;/p&gt;

&lt;p&gt;Why install SSMTP?&lt;/p&gt;

&lt;p&gt;SSMTP is a simple mail transfer agent (MTA) used to send emails from a Linux system. In other words, it forwards emails to another SMTP server for delivery.&lt;/p&gt;

&lt;p&gt;To install SSMTP&lt;br&gt;
&lt;code&gt;sudo apt install ssmtp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1kf6sfeb4t4ub4dawpse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1kf6sfeb4t4ub4dawpse.png" alt="SSMTP" width="800" height="121"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iv. Configuration of SSMTP file&lt;br&gt;
To configure the ssmtp file, &lt;code&gt;sudo nano /etc/ssmtp/ssmtp.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftir9gamdn87iacs2bjks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftir9gamdn87iacs2bjks.png" alt="Conf file command" width="733" height="32"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the arrow keys, edit your ssmtp configuration file to look exactly like the images attached below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5tov9l98nhai1xnxo4g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu5tov9l98nhai1xnxo4g.png" alt="SSMTP Conf File" width="800" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6yczf03ityb3ebyv4yhu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6yczf03ityb3ebyv4yhu.png" alt="SSMTP Conf File" width="612" height="226"&gt;&lt;/a&gt;&lt;br&gt;
In this configuration file,&lt;br&gt;
Your root should be your email address. &lt;br&gt;
Your AuthUser should be your email address. &lt;br&gt;
Your AuthPass should be the 16-character string generated from the app password in your Google account. When typing it in, remember not to include the spaces.&lt;br&gt;
The rewriteDomain should be gmail.com, but if you are not using Gmail's SMTP server to send your email, replace gmail.com with your domain.&lt;br&gt;
Lastly, uncomment the FromLineOverride as shown in the image above. &lt;br&gt;
Save your file.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Write and send your mail
&lt;/h2&gt;

&lt;p&gt;To send your mail, run the command below&lt;br&gt;
&lt;code&gt;echo "I'm a Cloud Engineer" | mail -s "Hello there!" your email address&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtyyalnh31b9zjmyu64l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqtyyalnh31b9zjmyu64l.png" alt="Send email" width="800" height="40"&gt;&lt;/a&gt; &lt;br&gt;
Once this is done, check your Gmail to see the mail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rijxw1j1tuff1pnxg1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5rijxw1j1tuff1pnxg1x.png" alt="Gmail inbox" width="800" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how to use SMTP and mailutils to send emails from the Ubuntu terminal.&lt;br&gt;
As soon as you are done following this guide, please terminate your EC2 instances to avoid incurring costs from AWS. Let the images below guide you on how to terminate your instance.&lt;/p&gt;

&lt;p&gt;Go back to your console where you have your instance ID. Expand the Instance state box and click on terminate instance&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bnelp90dblri0fe33wh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bnelp90dblri0fe33wh.png" alt="Terminate Instance" width="800" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once this is done, you will find a pop-up like the image image below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzr9bjhrs9nzg8hz5eek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuzr9bjhrs9nzg8hz5eek.png" alt="Successful instance termination" width="800" height="94"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations on successfully setting up your Linux terminal to send emails using SMTP and mailutils! You've learned how to configure your environment step by step, from generating a Google App password to launching an EC2 instance and configuring SSMTP.&lt;/p&gt;

&lt;p&gt;Sending emails from the command line can be a powerful and efficient way to handle communications, especially in automated scripts or remote environments. By following this guide, you've gained valuable insights into how SMTP works and how to leverage it within your Linux terminal.&lt;/p&gt;

&lt;p&gt;Your feedback is important to me! If you encounter any issues or have suggestions for improvement, please don't hesitate to share your thoughts. Your insights can help refine this guide and make it even more helpful for others.&lt;/p&gt;

</description>
      <category>cloudcomputing</category>
      <category>linux</category>
      <category>devops</category>
      <category>smtp</category>
    </item>
  </channel>
</rss>
