Find us on facebook

May 31, 2015

Install and start the LAMP web server on Amazon Linux And Ubuntu

Linux

Install updates
[ec2-user ~]$ sudo yum update -y

you can install the Apache web server, MySQL, and PHP software packages. Use the yum install command to install multiple software packages and all related dependencies at the same time.
[ec2-user ~]$ sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd

Start Apache
[ec2-user ~]$ sudo service httpd start

Start apache at each system boot
[ec2-user ~]$ sudo chkconfig httpd on

Check httpd is on
[ec2-user ~]$ chkconfig --list httpd

Modify ownership and permissions for document root

Add a www group to your instance, and you give that group ownership of the /var/www directory and add write permissions for the group. Any members of that group will then be able to add, delete, and modify files for the web server.

[ec2-user ~]$ sudo groupadd www

[ec2-user ~]$ sudo usermod -a -G www ec2-user (Add user to www group)

[ec2-user ~]$ exit (logout)

[ec2-user ~]$ groups (Verify membership in www group)

[ec2-user ~]$ sudo chown -R root:www /var/www (Change the group ownership of /var/www and its contents to the www group.)

Change the directory permissions of /var/www and its subdirectories to add group write permissions and to set the group ID on future subdirectories.
[ec2-user ~]$ sudo chmod 2775 /var/www
[ec2-user ~]$ find /var/www -type d -exec sudo chmod 2775 {} +

Recursively change the file permissions of /var/www and its subdirectories to add group write permissions.
[ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} +

[ec2-user ~]$ sudo service mysqld start (Start mysql server)

[ec2-user ~]$ sudo mysql_secure_installation (Run mysql_secure_installation, here u can set password for mysql etc...)

[ec2-user ~]$ sudo chkconfig mysqld on (Start mysql at every boot)


Ubuntu

Install updates
$ sudo apt-get update

Install the LAMP stack:
$ sudo apt-get install lamp-server^

During installation this asks for mysql root password. Type it and press enter button. Then retype password will be asked. Type and hit enter.


Start Apache server
$ sudo service apache2 start

Go to your Domain name for your instance. You will see Apache2 Ubuntu default page.

Modify ownership and permissions for document root (Same steps should apply as linux)

That's all.

No comments:

Post a Comment