# Tutorial: Install a LAMP web server on Amazon Linux 2

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:

```bash
sudo yum update -y
sudo yum upgrade -y
```

**2\. Install Apache Web Server**

```bash
sudo yum install httpd -y
```

Start the Apache service and enable it to start on the system boot:

```bash
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>`
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738897066115/93467072-2333-4241-8b01-365371232e43.png align="center")

You should see the default Apache welcome page.

**3\. Install MySQL Database Server**

```bash
sudo yum install mysql-server -y
```

Start the MySQL service and enable it to start on system boot:

```bash
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:

```bash
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:

```bash
sudo yum install php php-mysql php-gd php-mbstring php-zip -y
```

Restart Apache for the changes to take effect:

```bash
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`):

```bash
sudo nano /var/www/html/info.php
```

Paste the following code into the file:

```bash
<?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`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738896992940/303a5491-63b2-4145-b06b-79c21ed7db77.png align="center")

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:

```bash
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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738896824894/3a0837cb-4948-4def-b716-ba4e6b1e5b45.png align="center")

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**](https://jineshkumar.bio.link/)
