Prepare LAMP Server

Prepare LAMP Server

Once you’re connected to your Amazon Linux 2 instance, follow these steps to deploy the application.

Create VPC for Linux instance

  1. To ensure all your software packages are up to date, execute the following command:

    sudo yum update -y
    

Create VPC for Linux instance

  1. Install lamp-mariadb10.2-php7.2 and php7.2 using Amazon Linux Extras to get the latest LAMP MariaDB and PHP packages for Amazon Linux 2.

    sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
    

Create VPC for Linux instance

If you encounter the error message sudo: amazon-linux-extras: command not found, it means your instance was launched with the Amazon Linux AMI instead of Amazon Linux 2. You can check your instance type using the following command:

```bash
cat /etc/system-release
```

Create VPC for Linux instance

  1. Install Apache web server, MariaDB, and PHP packages.

    • Use the yum install command to install multiple software packages and their dependencies at once.
    sudo yum install -y httpd mariadb-server
    

Create VPC for Linux instance

  1. Start the Apache web server.

    sudo systemctl start httpd
    

Create VPC for Linux instance

  1. Configure the Apache web server to start on system boot.

    sudo systemctl enable httpd
    

Create VPC for Linux instance

  1. Verify that httpd is enabled by running the following command:

    sudo systemctl is-enabled httpd
    

Create VPC for Linux instance

  1. In the EC2 interface:

    • Select Instances
    • Choose Linux-instance
    • Copy the Public IPv4 address

Create VPC for Linux instance

  1. Paste the Public IPv4 address into your browser to test Apache.

    • Using Public IP

Create VPC for Linux instance

  • Using DNS

Create VPC for Linux instance

  1. Execute the following commands to grant permissions:

    • Add your user (in this case ec2-user) to the apache group.
    sudo usermod -a -G apache ec2-user
    

Create VPC for Linux instance

- Change the ownership of the **/var/www** directory and its contents to the apache group.

```bash
sudo chown -R ec2-user:apache /var/www
```

Create VPC for Linux instance

- To add group write permissions and set group IDs on future subdirectories, change the directory permissions of **/var/www** and its subdirectories.

```bash
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
```

Create VPC for Linux instance

- To add group write permissions, recursively change the permissions for the files in **/var/www** and its subdirectories:

```bash
find /var/www -type f -exec sudo chmod 0664 {} \;
```

Create VPC for Linux instance