AWS: Setup LAMP environment on Amazon Linux2

So, you have created a server instance in AWS using their Amazon Linux 2 options. This OS feels like using centOS or fedora, but there are a few differences; you have to do things a little differently in some cases.

Let’s set up our LAMP environment.

Apache 2.4 (httpd) setup

To install Apache 2.4 (httpd), use the following command:

sudo yum install httpd

It should work simply, and apache is installed.

Now start the server using:

sudo systemctl start httpd

To enable Apache to start on system startup, use the following command:

sudo systemctl enable httpd

If you want to check server status, use:

sudo systemctl status httpd

The config file for apache will be in the path: /etc/httpd/conf.d/httpd.conf

Install PHP 7.2

To check the available PHP version, use the following command:

sudo yum list | grep php

When I checked, I got PHP5 in the list. So at this moment, if you use yum install php, then PHP 5 will be installed.

For the further installation process, we will need amazon-linux-extras. Use the following command to check if that is available or not, and check available packages.


It will show a list of available packages. PHP should also be there somewhere on the list.

To check the details of the packages, use the following command:

amazon-linux-extras info php7.2

Now use the following command to install PHP 7.2

sudo amazon-linux-extras install php7.2

Now, if you type amazon-linux-extras, it will show that PHP 7.2 is installed and enabled.

Now, let’s check the available PHP modules:

yum list php * | grep amzn2extra-php7.2

Check whatever module you need for your application and install those using the following command:

sudo yum install php-cli php-common php-devel php-pdo php-mbstring php-gd

If you want to change any configuration, then the PHP config file will be at /etc/php.ini

Now restart the apache server:

sudo service httpd restart

Install MySQL

To install MySQL 8.0, use the following commands:

sudo yum install


sudo yum install  --enablerepo = mysql80-community mysql-community-server

Mysql installation didn’t ask for a password as it has set a default password for you. Let’s retrieve that:

sudo cat /var/log/mysqld.log | grep  "temporary password"

In response to that command, you will find the temporary password. Now log in to MySQL using that password:

mysql -u root -p

Then enter the password:

Or you can use the mysql_secure_installation command for setting the initial configuration:


Check details at

Leave a Comment