Cài đặt LAMP Web Server trên Amazon Ec2

1) Update hệ điều hành với dòng lệnh

sudo yum update -y

2) Cài đặt webserver, MySQL, PHP với dòng lệnh cài đặt nhóm phần mềm

sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd

3) Start Apache Web Server

sudo service httpd start

4) Cấu hình Apache web server sẻ khỏi động theo hệ điều hành

sudo chkconfig httpd on

Xem httpd có khỏi động chưa

chkconfig --list httpd

5) Root của Apache tại đường dẫn

/var/www/html

6) Chỉnh lại quyền cho file và thư mục

6.1) Thêm group vào máy

sudo groupadd www

6.2) Thêm user vào group

sudo usermod -a -G www ec2-user

6.3) Logout

exit

6.4) Đăng nhập lại và check quyền

[ec2-user ~]$ groups
ec2-user wheel www

6.5) Thay đổi quyền sở hữu

sudo chown -R root:www /var/www

6.6) Thay đổi quyền truy cập của thư mục www và thư mục con  và thêm group vào quyền viết

[ec2-user ~]$ sudo chmod 2775 /var/www
[ec2-user ~]$ find /var/www -type d -exec sudo chmod 2775 {} +

6.7) Đệ quy các và thay đổi quyền thư mục con

[ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} +

 Test  Web Server

Tạo file PHP và test

[ec2-user ~]$ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

Test

http://my.public.dns.amazonaws.com/phpinfo.php

 Bảo mật My SQL

1) Khỏi động MySQL  và chạy mysql_secure_installation

[ec2-user ~]$ sudo service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
...

Starting mysqld:                                           [  OK  ]

Chạy mysql_secure_installation.

sudo mysql_secure_installation

2) Câu hình để MySQL luôn chạy khi hệ điều hành khỏi động

sudo chkconfig mysqld on

 Cấu hình mode rewrite

sudo nano /etc/httpd/conf/httpd.conf

Sửa lại dòng thành AllowOverride All trong khoảng

<Directory "/var/www/html">

Not:

<Directory />

 sudo service httpd restart

short_open_tag = off/On

Cài đặt phpMyAdmin

1) Bật các gói mở rộng trên Linux

sudo yum-config-manager --enable epel

 2) Cài đặt phpMyAdmin

sudo yum install -y phpMyAdmin

 3) Cập nhật lại file config

 sudo sed -i -e 's/127.0.0.1/your_ip_address/g' /etc/httpd/conf.d/phpMyAdmin.conf

 4) Khởi động lại

sudo service httpd restart

 

 

Leave a Reply