Prepare LAMP Server

Prepare LAMP Server

Once you’re connected to your Amazon Linux 2023 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 dnf update -y
    

    The -y option installs the updates without asking for confirmation. If you would like to examine the updates before installing, you can omit this option.

    Create VPC for Linux instance

  2. Install the latest versions of Apache web server and PHP packages for Amazon Linux 2023.

    sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel
    

    Create VPC for Linux instance

  3. Install the MariaDB software packages.

    • Use the dnf install command to install multiple software packages and all related dependencies at the same time.
    sudo dnf install mariadb105-server
    

    Create VPC for Linux instance

    • You can view the current versions of these packages using the following command:
    sudo dnf info mariadb105
    

    Create VPC for Linux instance

  4. Start the Apache web server.

    sudo systemctl start httpd
    
  5. Configure the Apache web server to start on system boot.

    sudo systemctl enable httpd
    
  6. Verify that httpd is enabled by running the following command:

    sudo systemctl is-enabled httpd
    

    Create VPC for Linux instance

  7. In the EC2 interface:

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

    Create VPC for Linux instance

  8. 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

  9. 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

    • Change the ownership of the /var/www directory and its contents to the apache group.sudo chown -R ec2-user:apache /var/www

    • To add group write permissions and set group IDs on future subdirectories, change the directory permissions of /var/www and its subdirectories. sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;

    • To add group write permissions, recursively change the permissions for the files in /var/www and its subdirectories:find /var/www -type f -exec sudo chmod 0664 {} \;

    Create VPC for Linux instance