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
- Once you have clicked on the
Launch Instance, You will get an Wizard to configure your instance
- Choose AMI : Search for
Ubuntu Server 20.04 LTS (HVM), SSD Volume Type
- 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
- 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
- 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.
- 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.
- 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.
- Review : Review your instance settings and click on the Launch
- Choose AMI : Search for
- 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
instancewhich you like to connect and click
- Click on
A standalone SSH clientyou 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 updatebefore 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.
sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip php-mbstringinstall PHP and commonly used PHP extensions.
- Restart your Apache using
sudo service apache2 restart
- 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
- 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 !!