Setting Up Apache LAMP with EC2 with Amazon Linux 2023


Nova Web Design Penang would like to give a simple tutorial on how to set up your LAMP virtual server using Amazon AWS. For developers who are hungry for fast and reliable performance, and wish to utilise the power of Amazon EC2, this tutorial will guide you step by step on how you could set up Apache, PHP, MariaDb and PhpMyAdmin.  But before we even start to talk about the technicality of setup, what is Amazon EC2?

“An EC2 instance is simply a virtual server in Amazon Web Services terminology. With an EC2 instance, AWS subscribers can request and provision a computer server within the AWS cloud.”

Pre-requisite before installing anything:

  1. Basic Understanding how to set up an instance using Amazon Linux 2023
  2. Understand what the use of some Linux command such as ‘sudo , cp , ls, cd. vi ‘


To prepare the LAMP server

  1. Connect to your instance. For more information, see Connecting to instances.
  2. To ensure that all of your software packages are up to date, perform a quick software update on your instance. This process might take a few minutes, but it is important to make sure that you have the latest security updates and bug fixes.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. Now let’s installa) Apache ” http”
    b) Php * all the dependancies 
    c) MariaDB
  3. [ec2-user ~]$ sudo dnf update -y
  4. [ec2-user ~]$ sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel
  5. [ec2-user ~]$ sudo dnf install mariadb105-server
  6. Start the Apache web server.
    [ec2-user ~]$ sudo systemctl start httpd
  7. Use the systemctl command to configure the Apache web server to start at each system boot.
    [ec2-user ~]$ sudo systemctl enable httpd

    You can verify that httpd is on by running the following command:

    [ec2-user ~]$ sudo systemctl is-enabled httpd
  8. Add a security rule to allow inbound HTTP (port 80) connections to your instance if you have not already done so. By default, a launch-wizard-N security group was created for your instance during launch. If you did not add additional security group rules, this group contains only a single rule to allow SSH connections.
    1. Open the Amazon EC2 console at
    2. In the left navigator, choose Instances, and select your instance.
    3. On the Security tab, view the inbound rules. You should see the following rule:


  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, reconnect to your instance, and then run the following command:
      [ec2-user ~]$ groups
  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 (and any future members of the apache group) can add, delete, and edit files in the Apache document root, enabling you to add content, such as a static website or a PHP application.


  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.
      1. Type the current root password. PLEASE ENABLE ANS SELECT PASSWORD
      2. Type Y to set a password, and type a secure password twice. For more information about creating a secure password, see Make sure to store this password in a safe place.Setting a root password for MariaDB is only the most basic measure for securing your database. When you build or install a database-driven application, you typically create a database service user for that application and avoid using the root account for anything but database administration.
    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.
  3. (Optional) If you do not plan to use the MariaDB server right away, stop it. You can restart it when you need it again.
    [ec2-user ~]$ sudo systemctl stop mariadb
  4. (Optional) If you want the MariaDB server to start at every boot, type the following command.
    [ec2-user ~]$ sudo systemctl enable mariadb


  1. Install the required dependencies.
    [ec2-user ~]$ sudo dnf install php-mbstring php-xml -y
  2. Restart Apache.
    [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.
    [ec2-user ~]$ cd /var/www/html
  5. Select a source package for the latest phpMyAdmin release from To download the file directly to your instance, copy the link and paste it into a wget command, as in this example:
    [ec2-user html]$ wget
  6. Create a phpMyAdmin folder and extract the package into it with the following command.
    [ec2-user html]$ mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin --strip-components 1
  7. Delete the phpMyAdmin-latest-all-languages.tar.gz tarball.
    [ec2-user html]$ rm phpMyAdmin-latest-all-languages.tar.gz
  8. (Optional) If the MySQL server is not running, start it now.
    [ec2-user ~]$ sudo systemctl start mariadb

Further configuration for PhpMyAdmin

  1. Access the PhpMyAdmin Folder
    [ec2-user phpMyAdmin]$ sudo cp
  2. Edit the file by using the vi editor for the
  3. $cfg[‘blowfish_secret’] = ’32 byte string’  then save

Install Git

Simple installation of Git. You need to install git if you are planning to clone  your code from git hub repository

[ec2-user ~]$ sudo dnf install git