How to install Lamp web server or Amazon Linux 2


Please briefly explain why you feel this question should be reported .


The LAMP model has been converted to other elements, though standard one is free and open source software. For example, parallel installation of Microsoft Windows applications is known as WAMP and parallel installation in macOS is known as MAMP. [Citation needed]

With the increasing use of archetypal LAMP, differences and retronyms have emerged in other application combinations, web server, database, and software language. For example, a parallel installation in the Microsoft Windows family application is known as WAMP. Another IIS that works instead of Apache is called WIMP. Variations that include other applications include MAMP (macOS), SAMP (Solaris), FAMP (FreeBSD), AMP (Series) and XAMPP (cross-platform).

The web server or data management system also varies. LEMP is a version in which Apache has been replaced by the lightweight web server Nginx. [5] The form in which MySQL is replaced by PostgreSQL is called LAPP, or sometimes by keeping the original dictionary, LAMP (Linux / Apache / Middleware (Perl, PHP, Python, Ruby) / PostgreSQL). [6]

Lots of LAMP can be integrated with other free and open source software packages, including:

netsniff-ng for safety and durability testing
Snort, intrusion detection (IDS) and intrusion detection system (IPS)
RRDtool of drawings
Nagios, Collectd or Cacti, for caution.

In this article we will learn how to install a Lamp web server on Amazon Linux 2.

Step 1: Prepare the LAMP server


  • Before implementing this tutorial make sure that  you have already launched a new instance through Amazon Linux 2, Your public DNS name should be reachable from the internet. Your system must function well with security groups like SSH, HTTP, HTTPS.
  • You can follow this tutorials process to install the latest PHP version of Amazon Linux 2. If you want to use different PHP applications then you should check their compatibility with PHP 7.2 first.
To prepare the LAMP server

  1. Connect to your instance.
  2. For having a seamless installation of Lamp server, we recommend you to perform a software update in your system.

    The -y option is provided to install updates automatically. You can change the option for manual update also.

    [ec2-user ~]$ sudo yum update -y
  3. Install the lamp-mariadb10.2-php7.2 and php7.2 for getting the latest versions of PHP packages and LAMP MariaDB.
    [ec2-user ~]$ sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2

    If you receive an error stating sudo: amazon-linux-extras: command not found, then it means you are using Amazon Linux 2 AMI which is not supported. You can fix this problem by the help of the following command.

    cat /etc/system-release

    To set up a LAMP web server on Amazon Linux AMI , see Tutorial: Install a LAMP web server on the Amazon Linux AMI.

  4. Now as your current example, you can install Apache web server, MariaDB, and PHP software package.Use yum command to install multiple software packages and all related dependencies simultaneously.
    [ec2-user ~]$ sudo yum install -y httpd mariadb-server

    Current versions of each and every package can viewed with the help of following codes:-

    yum info package_name
  5. Start the Apache web server.
    [ec2-user ~]$ sudo systemctl start httpd
  6.  systemctl is the command to configure the Apache web server.
    [ec2-user ~]$ sudo systemctl enable httpd

    The below command is given to check httpd is running properly or not:-

    [ec2-user ~]$ sudo systemctl is-enabled httpd
  7. Launch wizard has been set by default for the security rule. You have to change it to allow HTTP port 80 for better results. While the launch wizard allows single rule of SSH connection.
    1. Amazon EC2 –
    2. Click instances for selecting your desired instance.
    3. On the Security tab, view the inbound rules. You should see the following rule:
      Port range   Protocol     Source
      22           tcp
    4. Choose the link for the security group. Enter the following values for other security bound options.
      • Type: HTTP
      • Protocol: TCP
      • Port Range: 80
      • Source: Custom
  8. Check your web server. In a web browser, enter your public DNS address (or public IP address) for your status. If there is no content in / var / www / html, you should see the Apache test page. You can get public DNS for your example using the Amazon EC2 console (check the Public DNS column; if this column is hidden, select Show / Hide Columns (gear-shaped icon) and then select Public DNS).

    You will have to configure the firewall also if you don’t have Amazon linux in your pc. The following information will give you more details.

    Apache test page

All the files of root document are kept in Apache directory which is owned by httpd . The Amazon Linux Apache document root is /var/www/html, which is owned by root.

To allow the ec2 user account to manage files in this directory, you must change the ID and directory permissions. There are many ways to do this work. In this tutorial, you can add an ec2 user to the apache group, grant the apache group id / var / www group and grant write permissions to the group.

To set file permissions

  1. Add your user (in this case, ec2-user) to the apache group.
    [ec2-user ~]$ sudo usermod -a -G apache ec2-user
  2. Log out and then log back in again to pick up the new group, and then verify your membership.
    1. Log out (use the exit command or close the terminal window):
      [ec2-user ~]$ exit
    2. To verify your membership in the apache group, run the below command after reconnecting it.
      [ec2-user ~]$ groups
      ec2-user adm wheel apache systemd-journal
  3. Change the group ownership of /var/www and its contents to the apache group.
    [ec2-user ~]$ sudo chown -R ec2-user:apache /var/www
  4. To add group write permissions and to set the group ID on future subdirectories, change the directory permissions of /var/www and its subdirectories.
    [ec2-user ~]$ sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
  5. To add group write permissions, recursively change the file permissions of /var/www and its subdirectories:
    [ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} \;

Now, ec2-user as well as any new or other members of Apache members can add, delete, and edit files in the Apache document root, enabling you to add content, like astatic website.

Step 2: Test your LAMP server

After performing all parts properly and granting permission to all files., your ec2-user account should be able to create a PHP file in the /var/www/html directory that is available from the internet.

To test your LAMP server

  1. Now, you have to build a PHP file in root.
    [ec2-user ~]$ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

    Restart your extensions if you face any problems like permission denial.

  2. Next, enter the URL of your newly built file. For example:

    You should see the PHP information page:


    If you do not see this page, verify that the /var/www/html/phpinfo.php file was created properly in the previous step. You can also verify that all of the required packages were installed with the following command.

    [ec2-user ~]$ sudo yum list installed httpd mariadb-server php-mysqlnd

    If some of the required packages are not in your export list, install them at the Sudo yum install package. Also make sure that the addition of php7.2 and lamp-mariadb10.2-php7.2 is enabled in the command of the amazon-linux-extras.

  3. Delete the phpinfo.php file. Although this can be useful information, it should not be broadcast to the internet for security reasons.
  4. [ec2-user ~]$ rm /var/www/html/phpinfo.php
  5. If you add content to the Apache document root at /var/www/html, you should be able to view that content at the public DNS address for your instance.

Step 3: Secure the database server

The automatic installation of the MariaDB server has several positive features in testing and development, but should be disabled or removed from production servers. The mysql_secure_installation command goes through the process of setting the root password and removing insecure features from your installation. Even if you do not plan to use the MariaDB server, we recommend doing this process.

To secure the MariaDB server

  1. Start the MariaDB server.
    [ec2-user ~]$ sudo systemctl start mariadb
  2. Run mysql_secure_installation.
    [ec2-user ~]$ sudo mysql_secure_installation
    1. When prompted, type a password for the root account.
    2. Type Y to remove the anonymous user accounts.
    3. Type Y to disable the remote root login.
    4. Type Y to remove the test database.
    5. Type Y to reload the privilege tables and save your changes.

Step 4: (Optional) Install phpMyAdmin

phpMyAdmin is a tool of management that you can use to edit the MySql databases on your EC2 instance. Follow the steps below to install and configure phpMyAdmin on your Amazon Linux instance.

To install phpMyAdmin

  1. Now, the time of installing dependencies:-
    [ec2-user ~]$ sudo yum install php-mbstring php-xml -y
  2. apache needs to be restarted.
    [ec2-user ~]$ sudo systemctl restart httpd
  3. Restart php-fpm.
    [ec2-user ~]$ sudo systemctl restart php-fpm
  4. Navigate to the Apache document root at /var/www/html
Abhay Singh 4 months 2021-05-10T00:05:59+05:30 0 Answers 1 views 0

Leave an answer