{"id":335,"date":"2025-06-14T12:05:41","date_gmt":"2025-06-14T12:05:41","guid":{"rendered":"https:\/\/www.sudeepa.com\/?p=335"},"modified":"2025-06-23T09:35:11","modified_gmt":"2025-06-23T09:35:11","slug":"setting-up-aws-virtual-hosting-amazon-linux","status":"publish","type":"post","link":"https:\/\/www.sudeepa.com\/?p=335","title":{"rendered":"Setting up AWS Virtual Hosting Amazon Linux"},"content":{"rendered":"\n<p>1) Create Linux Instance<\/p>\n\n\n\n<p>Set Up an AWS EC2 Instance<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open your browser and visit <a href=\"https:\/\/aws.amazon.com\">https:\/\/aws.amazon.com<\/a><\/li>\n\n\n\n<li>Click &#8220;Sign In to the Console&#8221;.<\/li>\n\n\n\n<li>Log in with your AWS credentials.<\/li>\n<\/ol>\n\n\n\n<p>Launch an EC2 Instance<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the AWS Console, search for \u201cEC2\u201d in the search bar and click on it.<\/li>\n\n\n\n<li>Click the \u201cLaunch Instance\u201d button.<\/li>\n\n\n\n<li>Give your instance a name (e.g., MyWebServer).<\/li>\n<\/ol>\n\n\n\n<p>Choose an AMI (Amazon Machine Image)<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Select Amazon Linux 2023 (or Amazon Linux 2).<\/li>\n\n\n\n<li>This is a free-tier eligible image ideal for beginners.<\/li>\n<\/ol>\n\n\n\n<p>Choose an Instance Type<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Select t3.micro (free-tier eligible).<\/li>\n<\/ol>\n\n\n\n<p>Configure Key Pair (SSH Access)<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Under Key pair (login), choose \u201cCreate new key pair\u201d.<\/li>\n\n\n\n<li>Give it a name (e.g., my-key).<\/li>\n\n\n\n<li>Select .pem format if using Linux\/macOS, or .ppk for Windows PuTTY.<\/li>\n\n\n\n<li>Click Create key pair and it will download automatically \u2014 keep it safe!<\/li>\n<\/ol>\n\n\n\n<p>Allow,<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>SSH traffic from<\/li>\n\n\n\n<li>HTTPS traffic from the internet<\/li>\n\n\n\n<li>HTTP traffic from the internt<\/li>\n<\/ol>\n\n\n\n<p>Launch the Instance<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Click \u201cLaunch Instance\u201d.<\/li>\n\n\n\n<li>Wait a few seconds, then click \u201cView all instances\u201d.<\/li>\n<\/ol>\n\n\n\n<p>2) Connect to Your Instance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>On Windows (with PuTTY):<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open PuTTYgen and convert your .pem to .ppk (if needed).<\/li>\n\n\n\n<li>Open <strong>PuTTY<\/strong>:<\/li>\n\n\n\n<li>Host Name: Instance &#8211; Public IPv4 address<\/li>\n\n\n\n<li>Port 22<\/li>\n\n\n\n<li>In Connection > SSH > Auth \u2013 Credentials, browse and select your .ppk file.<\/li>\n\n\n\n<li>Go to Session \u2013 Click Open<\/li>\n\n\n\n<li>Accept<\/li>\n\n\n\n<li>login as ec2-user<\/li>\n<\/ol>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp; 3) Package installation<\/p>\n\n\n\n<p>Apache<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install <a>Apache<\/a> (httpd): <em>sudo yum install httpd -y<\/em><\/li>\n\n\n\n<li>Start Apache: <em>sudo systemctl start httpd<\/em><\/li>\n\n\n\n<li>Enable Apache: <em>sudo systemctl enable httpd<\/em><\/li>\n<\/ol>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MariaDB<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install MariaDB: <em>sudo yum install mariadb105-server -y<\/em><\/li>\n\n\n\n<li>Start MariaDB: \u00a0<em>sudo systemctl start mariadb<\/em><\/li>\n\n\n\n<li>Enable <a>MariaDB<\/a>: <em>sudo systemctl enable mariadb<\/em><\/li>\n<\/ol>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PHP<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install PHP: <em>sudo yum install php php-mysqlnd -y<\/em><\/li>\n<\/ol>\n\n\n\n<p>3) Map Your Domain to Your AWS EC2 Instance<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Before setting up virtual hosting, you need to map your domain to your EC2 instance using your domain registrar (e.g., Namecheap, GoDaddy, Google Domains)<\/li>\n\n\n\n<li>After saving the records, DNS propagation may take a few minutes to several hours.<\/li>\n<\/ol>\n\n\n\n<p>4) Virtual host Configuration<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a directory for your website\n<ol class=\"wp-block-list\">\n<li>sudo mkdir \/var\/www\/html\/yourdomain.com<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Set the correct permissions\n<ol class=\"wp-block-list\">\n<li>sudo chown -R ec2-user:ec2-user \/var\/www\/yourdomain.com<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Add a test html page (Edit and create sample HTML file using vi)\n<ol class=\"wp-block-list\">\n<li>vi index.html<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Create a virtual host configuration file<ol><li>sudo cd \/etc\/httpd\/conf.d<\/li><\/ol>\n<ol class=\"wp-block-list\">\n<li>vi yourdomain.com.conf<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>Paste the following configuration<\/li>\n<\/ol>\n\n\n\n<p>&lt;VirtualHost *:80&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; ServerName yourdomain.com<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; ServerAlias www.yourdomain.com<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; DocumentRoot \/var\/www\/yourdomain.com\/public_html<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; ErrorLog \/var\/log\/httpd\/yourdomain.com-error.log<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; CustomLog \/var\/log\/httpd\/yourdomain.com-access.log combined<\/p>\n\n\n\n<p>&lt;\/VirtualHost&gt;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Restart Apache to apply changes\n<ul class=\"wp-block-list\">\n<li>sudo systemctl restart httpd<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1) Create Linux Instance Set Up an AWS EC2 Instance Launch an EC2 Instance Choose an AMI (Amazon Machine Image) Choose an Instance Type Configure Key Pair (SSH Access) Allow, Launch the Instance 2) Connect to Your Instance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Windows (with PuTTY): &nbsp;&nbsp;&nbsp;&nbsp; 3) Package installation Apache &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MariaDB &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PHP 3) Map Your Domain<\/p>\n","protected":false},"author":1,"featured_media":336,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-system-administration"],"_links":{"self":[{"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=\/wp\/v2\/posts\/335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=335"}],"version-history":[{"count":1,"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions\/337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=\/wp\/v2\/media\/336"}],"wp:attachment":[{"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sudeepa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}