Steps to Install a LAMP Web Server on Amazon Linux AMI

Steps to Install a LAMP(Linux,Apache,MySql,PHP) Web Server on Amazon Linux AMI


Step 1: First we need to update all the packages on the server and then install the LAMP packages. Then start and enable the httpd service . Below are the commands we need to execute

sudo yum update -y
sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd
sudo service httpd start
sudo chkconfig httpd on
chkconfig --list httpd  

Step 2: Open port 80 and 22 Inbound rules from security groups . Go to Network & Security click on Security group under that select your instance Group ID then go to actions to edit inbound rules and open port 80 . Similar way other required ports can be opened 



Step 3: Check the home directory details of apache
ls -l /var/www
[ec2-user ~]$ ls -l /var/www  this is by default owned by root
total 16
drwxr-xr-x 2 root root 4096 Jul 12 01:00 cgi-bin
drwxr-xr-x 3 root root 4096 Aug 7 00:02 error
drwxr-xr-x 2 root root 4096 Jan 6 2012 html
drwxr-xr-x 3 root root 4096 Aug 7 00:02 icons
drwxr-xr-x 2 root root 4096 Aug 7 21:17 noindex

Step 4:  To allow the ec2-user account to manipulate files in this directory, you must modify the ownership and permissions of the directory.

To set file permissions

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.
a. Log out (use the exit command or close the terminal window):
[ec2-user ~]$ exit
b. To verify your membership in the apache group, reconnect to your instance, and then run the
following command:
[ec2-user ~]$ groups
ec2-user wheel apache

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
[ec2-user ~]$ 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, the ec2-user user (and any future members of the apache group) can add, delete, and edit files
in the Apache document root. Now you are ready to add content, such as a static website or a PHP
application.

echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

Step 6: Browse the URL http://IPaddress/phpinfo.php we can see the webpage


Step 7: To check httpd service is running we ca use netstat command or check httpd status .


sudo netstat -ntpl | grep :80

sudo service httpd status

Step 8:  The configuration file location is /etc/httpd/conf/httpd.conf


Step 9: Secure the database server . Below is the steps




sudo service mysqld start
sudo mysql_secure_installation

When prompted, type a password for the root account.
i. Type the current root password. By default, the root account does not have a password set.
Press Enter.
ii. Type Y to set a password, and type a secure password twice. For more information about
creating a secure password, see http://www.pctools.com/guides/password/. Make sure to
store this password in a safe place.
Note
Setting a root password for MySQL 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.
b. Type Y to remove the anonymous user accounts.
c. Type Y to disable the remote root login.
d. Type Y to remove the test database.
e. Type Y to reload the privilege tables and save your changes


sudo chkconfig mysqld on

Step 10: Connect to mysql server

[ec2-user@ip-172-31-21-186 ~]$ mysql -u root -p

Step 10 : Configuration file location is  vi /etc/my.cnf




Comments