<?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: Vincent Agu</title>
    <description>The latest articles on DEV Community by Vincent Agu (@vee-op).</description>
    <link>https://dev.to/vee-op</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%2F2646150%2Fe1fe39c8-b30b-4ab2-8980-58ff64df5814.jpeg</url>
      <title>DEV Community: Vincent Agu</title>
      <link>https://dev.to/vee-op</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vee-op"/>
    <language>en</language>
    <item>
      <title>How to Provision an Ubuntu Server &amp; Using Apache for Hosting a Website</title>
      <dc:creator>Vincent Agu</dc:creator>
      <pubDate>Fri, 03 Jan 2025 15:22:43 +0000</pubDate>
      <link>https://dev.to/vee-op/how-to-provision-an-ubuntu-server-using-apache-for-hosting-a-website-3794</link>
      <guid>https://dev.to/vee-op/how-to-provision-an-ubuntu-server-using-apache-for-hosting-a-website-3794</guid>
      <description>&lt;p&gt;In today’s fast-paced digital landscape, the need for reliable and scalable hosting solutions has never been greater. &lt;strong&gt;Amazon Web Services (AWS) EC2 (Elastic Compute Cloud)&lt;/strong&gt; stands out as a powerful service for deploying and managing virtual servers in the cloud. &lt;/p&gt;

&lt;p&gt;My aim in writing this article to demonstrate how web applications can be deployed quickly. It is a practical demonstration of setting up an ubuntu server and using apache2 to deliver webcontents over &lt;em&gt;&lt;code&gt;HTTP&lt;/code&gt;&lt;/em&gt; and Optionally &lt;em&gt;&lt;code&gt;HTTPS&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Taking a practical and beginner-friendly approach, I believe this article has something for everyone, whether you’re a developer exploring cloud technologies, a startup launching your first product, or a tech enthusiast curious about AWS. &lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;An active AWS account&lt;/li&gt;
&lt;li&gt;An SSH Client or Terminal (e.g Termius, GitBash, etc)&lt;/li&gt;
&lt;li&gt;A domain - optional (for configuring https. I used a free domain) &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Setting up an EC2 Instance on AWS&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log into your aws account, navigate to EC2 and click Launch Instance.&lt;/li&gt;
&lt;li&gt;Input the name for your Instance.&lt;/li&gt;
&lt;li&gt;Choose Ubuntu 20.04 LTS as the Amazon Machine Image.&lt;/li&gt;
&lt;li&gt;Select the system architecture 64-bit (x86).&lt;/li&gt;
&lt;li&gt;Select an instance type t2.micro for a simple server (free tier eligible).&lt;/li&gt;
&lt;li&gt;Create a key pair &amp;amp; download the private key for SSH access.&lt;/li&gt;
&lt;li&gt;Ensure the Auto-assign public IP is Enabled&lt;/li&gt;
&lt;li&gt;Create a security group to allow HTTP (port 80), SSH (port 22) 
and optionally HTTPS (port 443).&lt;/li&gt;
&lt;li&gt;Configure Elastic Block Store (EBS) storage (8gb of gp3 for a simple static website).&lt;/li&gt;
&lt;li&gt;Launch the instance and take note of Public IP Address.&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%2Fx42xa45feufg5gdhcs3e.jpg" 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%2Fx42xa45feufg5gdhcs3e.jpg" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. SSH into Instance &amp;amp; Install Apache Web Server&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your SSH client or Terminal (e.g Termius, GitBash, etc)&lt;/li&gt;
&lt;li&gt;Naviagte to where you downloaded the private key and change 
the file permissions.
&lt;code&gt;chmod 400 myprivate-key.pem&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;SSH into the server
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;       ssh &lt;span class="nt"&gt;-i&lt;/span&gt; myprivate-key.pem ubuntu@ipaddress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Update the apt package manager and install Apache Web Server:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nb"&gt;sudo &lt;/span&gt;apt update  &lt;span class="c"&gt;## to update apt package index.  &lt;/span&gt;
    &lt;span class="nb"&gt;sudo &lt;/span&gt;apt upgrade  &lt;span class="c"&gt;## to upgrade all updated applications&lt;/span&gt;
    &lt;span class="nb"&gt;sudo install &lt;/span&gt;apache2 &lt;span class="nt"&gt;-y&lt;/span&gt; &lt;span class="c"&gt;## to install Apache2 webserver (-y means 'Yes' to all prompts &amp;amp; automatically download dependencies)  &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Confirm that Apache2 is up and running using:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status apache2  &lt;span class="c"&gt;##You should see the message active (running).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Create your HTML, CSS &amp;amp; JS File and send a copy to the Instance.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;N/B: For the purpose of this article, I used a HTML file with Internal CSS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Launch Visual Studio Code, create/open a project folder and 
create an index.html file &lt;/li&gt;
&lt;li&gt;Write HTML code and integrated internal CSS for styling for 
your website. (You can skip if you already have your html, css 
and js).&lt;/li&gt;
&lt;li&gt;From your SSH Client or Terminal, copy the index.html file or 
files as the case may be (css &amp;amp; js) to the server using secure 
copy via ssh. 
And move the file(s) to /var/www/html which is the 
default folder in which apache renders from. This should 
automatically replace the default apache's index.html file 
since it's same name &lt;code&gt;index.hmtl&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;scp &lt;span class="nt"&gt;-i&lt;/span&gt; myprivate-key.pem ~/project/index.html ubuntu@ipaddress:/home/ubuntu

&lt;span class="nb"&gt;sudo mv&lt;/span&gt; /home/ubuntu/index.html /var/www/html/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, if you have your project files on Git hosting platforms (github, gitlab, Bitbucket, Gitbucket, etc), you can initialized a repository in your Instance and clone/pull the remote repository into your instance. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure you set the right permissions for your files. And for 
enhanced security, change the /var/www/html directory 
ownership to be owned by Apache's user and group (www-data).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;       &lt;span class="nb"&gt;sudo chmod &lt;/span&gt;644 /var/www/html/yourfile.html 
       &lt;span class="nb"&gt;sudo chown &lt;/span&gt;www-data:www-data /var/www/html &lt;span class="nt"&gt;-R&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Confirm that your page is up and running. By typing your aws 
assigned public ip-address in a browser. Your website should 
displayed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Setting up Firewall and Ensuring you have ports open for SSH, HTTP and optionally HTTPS open&lt;/strong&gt;&lt;br&gt;
UFW (Uncomplicated firewall comes pretty much installed by default in most linux distributions like the Ubuntu 20.04LTS. But it is important to check the status and ensure you have your &lt;strong&gt;SSH&lt;/strong&gt; port open before enabling it to avoid locking yourself out from the server.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check if UFW is already pre-installed &lt;code&gt;ufw --version&lt;/code&gt;. If installed, the version should be shown. After that you should check the status &lt;code&gt;sudo ufw status&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensuring that ports for ssh, http, and optionally https are &lt;br&gt;
open.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;      &lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 22      &lt;span class="c"&gt;# SSH&lt;/span&gt;
      &lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 80      &lt;span class="c"&gt;# HTTP&lt;/span&gt;
      &lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 443     &lt;span class="c"&gt;# HTTPS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enable Firewall
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;      &lt;span class="nb"&gt;sudo &lt;/span&gt;ufw &lt;span class="nb"&gt;enable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Register a Domain, and point the &lt;code&gt;A Record&lt;/code&gt; and &lt;code&gt;CNAME Record&lt;/code&gt; to your servers IP-address&lt;/strong&gt;&lt;br&gt;
The CNAME Record is typically an allias for your website, if you want your website to be accessible from the 'www' and 'non-www' versions of your doamin name &lt;code&gt;(e.g setting 'A Record' to www.vee-op.dev.com and 'CNAME Record' to  vee-op.dev.com)&lt;/code&gt;. Both pointing to same IP-address.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Register in domain platform provider e.g Namecheap, 
GoDaddy,etc. You can also get a free subdomain from a free 
domain platform e.g &lt;code&gt;https://freedns.afraid.org/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Set an &lt;code&gt;A Record&lt;/code&gt; and &lt;code&gt;CNAME&lt;/code&gt; in your doamin DNS settings and 
point both to your AWS server's ip-address.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you are using the above free domain service, navigate to subdomains and click on the ADD NEW. After setting the &lt;code&gt;A Record&lt;/code&gt; you won't be able to set a free &lt;code&gt;CNAME Record&lt;/code&gt; since you don't own the doamin but alternatively you can set a second &lt;code&gt;A Record&lt;/code&gt; with your allias name pointing to your Ip.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Now, Back to your instance from the terminal/ssh client, edit 
the default virtualhost confg file and modify/add ServerName 
and ServerAllias to represent the doamin name you set earlier 
in your Domain provider's platform.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;      &lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/apache2/sites-available/000-default.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;     &amp;lt;VirtualHost &lt;span class="k"&gt;*&lt;/span&gt;:80&amp;gt;
        ServerAdmin webmaster@localhost
        ServerName www.vee-op.dev.com
        ServerAlias vee-op.dev.com
        DocumentRoot /var/www/html
    &amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enabled this new changes on the conf file by;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;      &lt;span class="nb"&gt;sudo &lt;/span&gt;a2ensite 000-default.conf   &lt;span class="c"&gt;# to enable config file&lt;/span&gt;
      &lt;span class="nb"&gt;sudo &lt;/span&gt;apache2ctl configtest       &lt;span class="c"&gt;# Test the config (it should return an "OK") &lt;/span&gt;
      &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart apache2     &lt;span class="c"&gt;# to restart apache2 webserver&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Congrats... Your site should be up and accessible over HTTP&lt;/em&gt;&lt;/strong&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%2F5lv9eay4l658ikialj8p.jpg" 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%2F5lv9eay4l658ikialj8p.jpg" alt="Congratulation image" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Optional - Configuring HTTPS&lt;/strong&gt;&lt;br&gt;
To serve your website over https, you will need an SSL certificate and have port 443 open as shown optionally above on both your AWS security group and UFW if you enabled that too. You can obtain a free SSL from &lt;code&gt;Lets Encrypt&lt;/code&gt;. To do this, you have to install certbot and run the certbot command to obtain the free ssl for your domain(s)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install certbot using: 
While in the server from your terminal/ssh client run the command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;       &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;certbot python3-certbot-apache &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run certbot to obtain free SSL certificate for your 
domain(s).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;certbot &lt;span class="nt"&gt;--apache&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; www.vee-op.dev.com &lt;span class="nt"&gt;-d&lt;/span&gt; vee-op.dev.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If SSL certificates have been acquired sucessful, certbot will automatically create and place a new SSL config. file &lt;code&gt;(usually 000-default-le-ssl.conf or similar name)&lt;/code&gt; in the &lt;code&gt;/etc/apache2/sites-available&lt;/code&gt; and redirect all http traffic to https &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Restart or Relaod Apache
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;       &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart apache2 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Testing:
&lt;/h3&gt;

&lt;p&gt;You can type your domain name in a browser to confirm your webpage is displaying properly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Genius... You did it again!!! I knew you were capable&lt;/em&gt;&lt;/strong&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%2F8mu1574p9xiy9o5o9fst.jpg" 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%2F8mu1574p9xiy9o5o9fst.jpg" alt="Super Mario thumbs up" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;By following this guide, you’ve taken your first steps into the powerful world of cloud computing. From provisioning your instance to setting up a functional web server, you've experienced firsthand how AWS can streamline the process of deploying web applications.&lt;/p&gt;

&lt;p&gt;If you found this guide helpful, I’d love to hear your feedback! Feel free to share your thoughts or questions in the comments below.&lt;/p&gt;

&lt;p&gt;Don’t forget to follow me here and on &lt;a href="https://www.linkedin.com/in/vincent-agu-2ba037285" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://github.com/Vee-op?tab=repositories" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloudcomputing</category>
      <category>ec2</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
