top of page

HƯỚNG DẪN CÀI ĐẶT LAMP (APACHE + MARIADB + PHP) TRÊN CENTOS 7

Writer's picture: Tuan NguyenTuan Nguyen

Updated: Jul 19, 2018

Các bước thực hiện:

  • Cài Apache

  • Cài MariaDB

  • Cài PHP7


1. Cài Apache


# yum install httpd -y

Khởi động dịch vụ Apache.

# systemctl start httpd

Bật dịch vụ Apache khởi động cùng hệ thống.

# systemctl enable httpd

Kiểm tra phiên bản Apache vừa cài

# httpd -v

Kiểm tra Apache đã lắng nghe trên port 80 hay chưa.

# netstat -natp | grep httpd

Cấu hình firewall rule cho phép các kết nối bên ngoài vào Web Server Apache (port 80/443 tcp).

- Nếu xài iptables

# iptables -A INPUT -p tcp --match multiport -dports 80,443 -j accept

- Nếu xài firewalld

# firewall-cmd --get-default-zone

Public

# firewall-cmd --zone=public --permanent --add-port=80/tcp
# firewall-cmd --zone=public --permanent --add-port=443/tcp

Success

# firewall-cmd --reload

success

Gõ địa chỉ IP server vào trình duyệt web

Nội dung file web mặc định nằm trong thư mục: /var/www/html/

Các file cấu hình Apache:

  • File cấu hình Apache: /etc/httpd/conf/httpd.conf

  • Thư mục chứa file cấu hình phụ Apache: /etc/httpd/conf.d/

  • Thư mục log Apache: /var/log/httpd

  • Thư mục web mặc định: /var/www/html/


2. Cài đặt MariaDB


# cd /etc/yum.repos.d

Tạo file MariaDB.repo

# vi MariaDB.repo

Thêm vào file MariDB.repo các dòng sau:

# MariaDB 10.2 CentOS repository list

# http://downloads.mariadb.org/mariadb/repositories/

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.2/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

Cập nhật thông tin về Repository MariaDB 10.2 mới cấu hình ở file MariaDB.repo

# yum repolist

Tiến hành cài các gói của dịch vụ MariaDB.

# yum install MariaDB-server MariaDB-client MariaDB-devel -y

Khởi động dịch vụ database MariaDB.

# systemctl start mysql.service

hoặc

# systemctl start mariadb
# systemctl enable mysql.service

hoặc

# systemctl enable mariadb

Thiết lập cấu hình an toàn thông tin cơ bản cho MariaDB, câu lệnh sau có mục đích:

  • Thay đổi mật khẩu root (mặc định mới cài MariaDB user root không có đặt mật khẩu).

  • Xóa bỏ user anonymous.

  • Tắt tính năng cho phép user root login từ ngoài hệ thống.

  • Xóa bỏ database “test” và quyền truy cập của nó.

  • Reload lại các table liên quan đến quyền hạn.

# mysql_secure_installation

Kiểm tra phiên bản MariaDB.

# mysql -V

Kiểm tra tiến trình MariaDB có đang chạy hay không. Tiến trình có tên là mysqld.

# ps aux | grep -v "grep" | grep "mysqld"

Kiểm tra database MariaDB có lắng nghe trên port 3306 hay chưa.

# netstat -lntp | grep "3306"



3. Cài PHP


Cài Repository của REMI.

# wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# rpm -Uvh remi-release-7*.rpm
# cd /etc/yum.repos.d/

Kích hoạt repo REMI sử dụng cho PHP 7.0. Kéo xuống phần nội dung file ở section [remi-php70], kích hoạt “enable=1”.

# vi remi-php70.repo

[remi-php70]

name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch

#baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/

#mirrorlist=https://rpms.remirepo.net/enterprise/7/php71/httpsmirror

mirrorlist=http://cdn.remirepo.net/enterprise/7/php71/mirror

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi


Cập nhật thông tin về Repository remi mới cấu hình ở file remi-php70.repo

# yum repolist

Cài PHP 7.0

# yum install --disablerepo=* --enablerepo=remi-php70 php php-mysql php-bcmath php-cli php-common php-devel php-embedded php-enchant php-mbstring php-mcrypt php-pdo php-xml -y

Restart lại Apache.

# systemctl restart httpd

Tạo 1 file php để xem Apache xử lý được code PHP hay chưa.

# cd /var/www/html

Tạo file php

# vi info.php

Thêm vào nội dung sau.

<?php

phpinfo();

?>

Truy cập lại đường dẫn: ipwebserver/info.php

Done !

22 views0 comments

Comments


 

© 2018 by Tuấn Nguyễn

 Liên hệ tôi
  • Facebook - Black Circle
  • Google+ - Black Circle
bottom of page