 
		- Set Up a LAMP Server on AL2023 (Amazon Linux 2023)
Prerequisites
Before beginning:
- Launch an AL2023 instance on Amazon EC2 with a public DNS.
- Allow SSH (port 22), HTTP (port 80), and HTTPS (port 443) in your security group.
Step 1: Prepare Your LAMP Server
1. Connect to Your Instance
Use an SSH client (like PuTTY) to connect to your EC2 instance.
2. Update Software
Run the following command to ensure all packages are up to date:
sudo dnf upgrade -y3. Install Apache and PHP
Install Apache and the latest PHP version (8.1) with this command:
sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel4. Install MariaDB
Install MariaDB, the database server:
sudo dnf install mariadb105-server5. Start Apache
Start the Apache web server:
sudo systemctl start httpdEnable Apache to start on boot:
sudo systemctl enable httpd6. Check HTTP Port Access
Make sure your security group allows inbound HTTP (port 80) traffic. Update rules in the EC2 console if necessary.
Step 2: Set Up File Permissions
To manage files in Apache’s root directory (/var/www/html):
- Add the - ec2-userto the- apachegroup:
sudo usermod -a -G apache ec2-user2. Log out and log back in to apply the changes:
exit3. Verify group membership:
groupsYou should see apache listed.
4. Change ownership and permissions of /var/www:
sudo chown -R ec2-user:apache /var/wwwsudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;find /var/www -type f -exec sudo chmod 0664 {} \;Step 3: Test Your Web Server
- Open your instance’s public DNS in a browser. If the - /var/www/htmldirectory is empty, you should see Apache’s test page: “It works!”
- Add a test PHP file to verify PHP functionality: 
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php3. Open the file in your browser:
http://<your-public-DNS>/phpinfo.phpYou should see a PHP information page.
