Step-by-Step Guide to LAMP Configuration on Amazon Linux Ec2

How to, Linux By Jul 03, 2023 No Comments

The LAMP stack, which stands for Linux, Apache, MySQL, and PHP, is also applicable to Amazon Linux. Here’s a basic guide on how to install and configure a LAMP stack on Amazon Linux:

  1. Update your system: Always start by updating your system to the latest packages. You can do this by running the following commad:
sudo yum update -y
  1. Install Apache: Apache is a popular open-source web server. Install it with the following command:
sudo yum install httpd -y

Start the Apache service with the following command:

sudo service httpd start

To ensure Apache starts at every system boot, type:

sudo chkconfig httpd on

Install MySQL (MariaDB): MariaDB is a community-developed fork of the MySQL relational database management system. To install MariaDB, run the following command:

sudo yum install mariadb-server mariadb -y

Start the MariaDB service with the following command:

sudo service mariadb start

To ensure MariaDB starts at every system boot, type:

sudo chkconfig mariadb on

Secure your MariaDB installation by running:

sudo mysql_secure_installation

You’ll be asked to set a root password and to answer a series of questions. You should respond “Y” (yes) to each of these questions.

  1. Install PHP: PHP is a popular server-side scripting language designed for web development. Install PHP along with a few common extensions with the following command:
sudo yum install php php-mysql -y

Restart the Apache web server to pick up the new PHP modules:

sudo service httpd restart

Test PHP Processing: To confirm that your server is configured correctly for PHP processing, create a very basic PHP script. Use nano or your favorite text editor to create the file:

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

This will open a blank file. Add the following text, which is valid PHP code, inside the file:


Save and close the file. Now you can test whether your web server is able to correctly display this page. If you go to http://your_server_ip/info.php, you should see a web page that has been generated by PHP with information about your server.

Remember to replace your_server_ip with your server’s public IP address. If you see this page, then your PHP is working as expected.

You might want to remove this file after this test because it could actually give information about your server to unauthorized users. To do this, you can type this command:

sudo rm /var/www/html/info.php

That’s it! You have now installed a LAMP stack on your Amazon Linux server.

Please note that this is a basic guide. Depending on your specific needs, you might need to configure your LAMP stack differently.


I'm Abhay Singh, an Architect with 9 Years of It experience. AWS Certified Solutions Architect.

No Comments

Leave a comment

Your email address will not be published. Required fields are marked *