Configuring LAMP (Linux, Apache, MySQL, PHP) web server on an Amazon EC2 Linux instance

Sumit
Tensult Blogs
Published in
4 min readFeb 20, 2019
Reference: https://bit.ly/2BLDSD8

In this blog, I am going to share my experience and the steps followed by me to configure a LAMP web server on an Amazon EC2 Linux instance. A LAMP server is probably one of the most important servers that you will configure. It can serve dynamic, database-driven websites without needing constant monitoring.

We will be starting with an Ubuntu instance on AWS. So we already have Linux. Now we require Apache, MySQL, and PHP for our LAMP server stack to be complete. Let’s start with Apache.

Apache

Apache is the web server piece of the LAMP stack. Run the below command to update the system with the latest security updates and patches. I am assuming that you have the root access to your server and if not, you would need to start the commands with ‘sudo’ for them to work.

apt-get update

Once the system has updated, use the below command to install Apache.

apt-get install apache2

If everything has worked fine, you will see the below Apache start page when you access the public IP address of the EC2 instance from a local browser.

Apache Ubuntu start page

Now let’s move on to configuring PHP.

PHP

Hypertext Preprocessor, also known as PHP, is a server-side scripting language designed for web development. Installing PHP on an Ubuntu server can be done easily using the below command:

apt-get install php7.2 libapache2-mod-php7.2

Once the installation is done, you can check the PHP version using the command

php -v

It should give the version of PHP installed and look similar to the below snippet

php version 7.2.15

To check whether the installing PHP is working as it should, let’s create a sample php file and save it in /var/www/html folder. Name the file as test.php and include the below code snippet in that

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo ‘<p>Hello Mumbai</p>’; ?>
</body>
</html>

Next, go to your local browser and in the address bar, give http://server_IP_address/test.php, where server_IP_address is the public IP address of the instance that you are working on. Hit enter and you should get a page similar to this:

Sample php page

Now we are left with MySQL for installation, which is going to take a few more steps compared to what we have installed till now.

MySQL

MySQL is an open-source relational database management system and it is one of the components of LAMP web application software stack. We can install MySQL on our instance using the below steps:

a. The first step is to install MySQL which can be accomplished by running the below command:

apt-get install mysql-server

b. Next, we need to log in to MySQL prompt and configure a password for an administrative user. To do that, start with the below command

mysql_secure_installation

The above command gives an interactive form to set a strong password for MySQL. That’s it. Since it’s a locally installed MySQL, you will not be prompted for a password when you try to log in.

Give the command ‘mysql -u root mysql’ and press enter. You will be taken to MySQL prompt. Your LAMP server is ready for you. Of course, now all you have is a bare-bones LAMP server. Since this article does not dive deep into the trenches of any of the packages, you would want to familiarize yourself with these tools before you start playing around with them.

And remember, before deciding to go live with your server, make sure you have all security features configured so that the server is protected from any malicious activities. Kindly share your thoughts about this blog in the below comments section.

--

--