Install LAMP Web Server on Amazon EC2 with Ubuntu 20.04

This article will help you to install an Apache web server with PHP and MySQL support on your Amazon Linux instance (sometimes called a LAMP web server or LAMP stack). You can use this server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.

Create and Launch EC2 Instance

  • Log into the AWS EC2 Management Console
  • Select your preferred region which you like to create your instance
  • Click on the button Launch Instance
  • Once you have clicked on the Launch Instance, You will get an Wizard to configure your instance
    1. Choose AMI : Search for Ubuntu and select Ubuntu Server 20.04 LTS (HVM), SSD Volume Type
    2. Choose Instance Type : Select your instance type based on your needs and requirement. If you like to use AWS Free Tier then you can select Free tier eligible instance and click Next
    3. Configure Instance : This step allows you to configure the instance to suit your requirements, If you don’t have any preference you can use default configuration by clicking Next
    4. Add Storage : Configure your device storage on this step, By default AWS will attach 8GB EBS with your instance. Click Next after your storage configuration.
    5. Add Tags : Tags help you to manage your Amazon EC2 resources, you can optionally assign your own metadata to each resource in the form of tags.
    6. Configure Security Group : Security group is a set of firewall rules that control the traffic on your instance. On this step, you can add rules to allow specific traffic to reach your instance. Since, we are creating Apache HTTP/Web Server we need to add HTTP as new rule. To add HTTP rule, click on Add Rule and choose HTTP from the dropdown.
    7. Review : Review your instance settings and click on the Launch
  • On Select an existing key pair or create a new key pair window, Select Create a new key pair on dropdown and name your key on Key pair name textbox after that click Download Key Pair to download your key file and then Click Launch
  • Now, Your instance created successfully, On clicking on View Instances, you will be redirecting to the EC2 management console

Connect to EC2 Instance

Using downloaded key file now we will be connection to EC2 instance from our system.

  • Click on your instance which you like to connect and click Connect
  • Click on A standalone SSH client you will get the set of instruction that will help you to connect to your EC2 instance successfully.

Note : You can connect to your instance either with your Public DNS/Public IP.

Install Apache & PHP

  • Upgrade all your package using command sudo apt-get update before installing Apache
  • Now, Install Apache using command sudo apt-get install apache2. After successful installation of Apache you can view the Welcome Page by accessing though your Public DNS/Public IP in your browser.
  • Using sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip php-mbstring install PHP and commonly used PHP extensions.
  • Restart your Apache using sudo service apache2 restart

Install MySql

  • Install MySql Server using sudo apt-get install mysql-server
  • After MySql Server installation, We need to set root password
    for database and secure it by using the command sudo mysql_secure_installation
  • You will be presented a screen where MySQL asks whether you would like to activate the VALIDATE PASSWORD PLUGIN. For now, keeping things simple, type no.
  • In the next type the root password of your choice. Confirm it again.
  • Disallow root login remotely? Type No
  • Remove test database and access to it? Type Yes
  • Reload privilege tables now? Type Yes
  • After the password has been set you can check the whether MySQL is working correctly by logging into the database with the command sudo mysql -u root -p
  • Type exit to get out of MySql

Please leave your valuable comments/suggestions/feedback on below comment box if any.

Thank You !!

Sivasankar

SIVA SANKAR, Working as a Software Engineer, Blogging is my hobby. I completed my Bachelors of Engineering (Computer Science Engineering) in Chennai, India. and my Master of Engineering (Embedded System Technologies) in Tamilnadu, India.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.