Monday 8 April 2019

How to Install a LAMP Web Server on Amazon Linux 2 by Raj Gupta

We can use LAMP(Linux, Apache, Mysql, and PHP) server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.



We are going to use:-

L  --> Amazon Linux 2
A --> Apache
M --> MariaDB (a community-developed fork of MySQL)
P --> PHP 7.2

We assumes that we have already launched a new instance using Amazon Linux 2, that is reachable from the internet. We must also have configured our security group to allow SSH (port 22), HTTP (port 80), and HTTPS (port 443) connect.



Now logging into our EC2 server and run the below command

1. Update of system.
[root@ip-172-31-95-205 ~]# yum update -y

2. Now install the required repositories for LAMP
[root@ip-172-31-95-205 ~]# sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2

3.Now install the Apache web server, MariaDB, and PHP software required for LAMP
[root@ip-172-31-95-205 ~]#  sudo yum install -y httpd mariadb-server

4.Start the Apache web server.
[root@ip-172-31-95-205 ~]# sudo systemctl start httpd

5.Use the systemctl command to configure the Apache web server to start at each system boot.
[root@ip-172-31-95-205 ~]# sudo systemctl enable httpd

6.We can verify that httpd is on by running the following command:
[root@ip-172-31-95-205 ~]# sudo systemctl is-enabled httpd

Now To test web server copy the public IP of EC2 and past in browser.



Now To test our LAMP server

Create a PHP file in the Apache document root
[root@ip-172-31-95-205 ~]# echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

Now in Browser past the below
http://100.26.104.220/phpinfo.php



Now our server is ready for host a static website or deploy a dynamic PHP application.

No comments:

Post a Comment