To configure a LAMP stack (Linux, Apache, MySQL, PHP) on AWS (Amazon Web Services), you can follow these steps:
Step 1: Launch an EC2 Instance
1. Log in to your AWS Management Console.
2. Navigate to the EC2 service.
3. Click on "Launch Instance" to start the instance creation wizard.
4. Select an appropriate Amazon Machine Image (AMI) based on your preferred Linux distribution (e.g., Ubuntu, CentOS, or Amazon Linux).
5. Choose an instance type and configure the instance details as per your requirements.
6. Configure security groups to allow inbound traffic on ports 80 (HTTP) and 443 (HTTPS).
7. Review the configuration and launch the instance.
Step 2: Connect to the EC2 Instance
1. Once the EC2 instance is running, you can connect to it using SSH.
2. Open your preferred SSH client (e.g., Terminal on macOS or Linux, PuTTY on Windows).
3. Use the SSH key pair associated with the EC2 instance to connect to it:
```
ssh -i /path/to/your/key.pem user@public_dns_name
```
Replace `/path/to/your/key.pem` with the actual path to your SSH private key file, `user` with the appropriate username for your Linux distribution (e.g., "ubuntu" for Ubuntu AMIs, "ec2-user" for Amazon Linux), and `public_dns_name` with the public DNS name or IP address of your EC2 instance.
Step 3: Install and Configure LAMP Components
1. Update the package repository and upgrade the system by running the following commands:
sudo apt update (for Ubuntu) or sudo yum update (for CentOS/Amazon Linux)
sudo apt upgrade (for Ubuntu) or sudo yum upgrade (for CentOS/Amazon Linux)
2. Install Apache:
sudo apt install apache2 (for Ubuntu) or sudo yum install httpd (for CentOS/Amazon Linux)
3. Start the Apache service:
sudo systemctl start apache2 (for Ubuntu) or sudo service httpd start (for CentOS/Amazon Linux)
4. Install MySQL (MariaDB):
sudo apt install mysql-server (for Ubuntu) or sudo yum install mariadb-server (for CentOS/Amazon Linux)
5. Secure th MySQL installation:
sudo mysql_secure_installation
For Detailed Instructions Click Here
6. Install PHP and its required modules:
```
sudo apt install php libapache2-mod-php php-mysql (for Ubuntu) or sudo yum install php php-mysql (for CentOS/Amazon Linux)
7. Restart Apache:
sudo systemctl restart apache2 (for Ubuntu) or sudo service httpd restart (for CentOS/Amazon Linux)
Step 4: Test the LAMP Stack
1. Create a test PHP file in the web server's document root directory:
sudo nano /var/www/html/info.php
2. Add the following PHP code to the file:
<?php
phpinfo();
?>
3. Save the file and exit the text editor.
4. Open a web browser and visit your EC2 instance's public IP address or domain name followed by `/info.php` (e.g., `http://public_ip/info.php`).
5. You should see the PHP information page indicating that your LAMP stack is configured correctly.
That's it! You have successfully configured a LAMP stack on an AWS EC2 instance.