Tutorial: Install a LAMP web server on Amazon Linux 2

Cloud Enthusiast working as Cloud Infrastructure Consultant. My Hobby is to build and destroy Cloud Projects for Blogs. Love to share my learning journey about DevOps, AWS and Azure.
Subscribe and Follow up with "CloudCubes".
Thank you and Happy Learning !!
Here's a blog post outlining the steps to install a LAMP (Linux, Apache, MySQL, PHP) web server on Amazon Linux 2:
Tutorial: Install a LAMP web server on Amazon Linux 2
This tutorial will guide you through the process of installing and configuring a LAMP stack on an Amazon Linux 2 instance.
Prerequisites:
An active AWS account.
An Amazon Linux 2 instance running on AWS.
Basic familiarity with the Linux command line.
1. Update and Upgrade the System
Begin by updating the package lists and upgrading the system to ensure you have the latest software and security patches:
sudo yum update -y
sudo yum upgrade -y
2. Install Apache Web Server
sudo yum install httpd -y
Start the Apache service and enable it to start on the system boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Verify that Apache is running correctly by accessing the default Apache page in your web browser:
- Open your web browser and navigate to
http://<your_instance_public_ip>

You should see the default Apache welcome page.
3. Install MySQL Database Server
sudo yum install mysql-server -y
Start the MySQL service and enable it to start on system boot:
sudo systemctl start mysqld
sudo systemctl enable mysqld
4. Secure the MySQL Installation
Run the MySQL secure installation script to set a strong root password, remove anonymous user access, and disable remote root login:
sudo mysql_secure_installation
Follow the on-screen prompts to configure MySQL security settings.
5. Install PHP and related modules
Install PHP and necessary PHP modules for your web applications:
sudo yum install php php-mysql php-gd php-mbstring php-zip -y
Restart Apache for the changes to take effect:
sudo systemctl restart httpd
6. Create a PHP Test File
Create a simple PHP file named info.php in the Apache document root directory (usually /var/www/html):
sudo nano /var/www/html/info.php
Paste the following code into the file:
<?php
phpinfo();
?>
Save and close the file.
7. Access the PHP Information Page
Open your web browser and navigate to:
http://<your_instance_public_ip>/info.php

You should see the PHP information page, confirming that PHP is installed and configured correctly.
8. (Optional) Install PHPMyAdmin
PHPMyAdmin is a web-based tool for managing MySQL databases. To install it:
sudo yum install phpMyAdmin -y
During the installation, you'll be prompted to choose a web server configuration. Select "Apache" and follow the on-screen instructions.

Log in to your phpMyAdmin installation with the root user name and the MySQL root password you created earlier.
9. Test your LAMP Stack
You can now start developing and deploying PHP-based web applications on your Amazon Linux 2 instance.
Important Notes:
This is a basic installation. You may need to install additional software and configure settings based on your specific needs.
Regularly update and patch your server to maintain security and stability.
Refer to the official documentation for Apache, MySQL, and PHP for detailed information and advanced configuration options.
This tutorial provides a foundation for setting up a LAMP stack on Amazon Linux 2. Remember to follow security best practices and regularly update your system to ensure the security and stability of your web server.
I hope this blog post has been helpful. If you have any further questions or encounter any issues, please feel free to leave a comment below.
Thank you for reading! Happy Learning!
Like and Follow for more Azure and AWS content.
Thank you,
Jineshkumar Patel




