Home > Tiếng Việt > Hướng Dẫn (Tutorials) > Hướng dẫn cài đặt Lighttpd với PHP-FPM và MariaDB trên CentOS 7

Hướng dẫn cài đặt Lighttpd với PHP-FPM và MariaDB trên CentOS 7

An ninh, tốc độ, tuân thủ, và linh hoạt - Đó là tất cả các mô tả về lighttpd. Nhanh chóng xác định lại hiệu quả của một máy chủ web; vì nó được thiết kế và tối ưu hóa cho môi trường hiệu suất cao. Với một bộ nhớ nhỏ so với các web-server, quản lý hiệu quả của CPU-load, và bộ tính năng tiên tiến (FastCGI, SCGI, Auth, Output-nén, URL-Rewriting và nhiều hơn nữa) lighttpd là giải pháp hoàn hảo cho mọi máy chủ đau khổ vấn đề tải.

Tìm hiểu thêm ở trang web sau https://www.lighttpd.net/

I.Chuẩn bi 

Cài đặt kho epel và remi ,Tham khảo link sau Click Here

Cập nhật hệ thống 

# yum update -y

Trong CentOS 7.0 sử dụng Firewall-cmd, vì vậy ta sẽ tùy chỉnh nó bằng lệnh như sau.

Ví dụ ta mở công 80 và 3306

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

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

Khởi động lại filewall 

# firewall-cmd --reload 

II.Tiến hành 

1. Cài đặt lighttpd

Gõ lệnh sau để cài đặt lighttpd 

# yum -y install lighttpd

Khởi động dịch vụ và cho chạy cùng hệ thống

# systemctl enable  lighttpd.service
# systemctl start  lighttpd.service

Chạy lệnh sau để xem trạng thái của dịch vụ 

# systemctl status lighttpd.service

Nếu gặp dòng sau nó yêu cầu sử dụng ipv6

(network.c.272) warning: please use server.use-ipv6 only for hostnames, not without server.bind / empty address; your config will break if the kernel default...V6_V6ONLY changes

Bạn chỉ việc truy cập vào file cấu hình và tắt ip-v6 đi

# nano /etc/lighttpd/lighttpd.conf

##
## Use IPv6?
##
server.use-ipv6 =
"disable"

Và khởi động lại lighttpd

# systemctl restart  lighttpd.service

Bây giờ ta dùng trình duyệt truy cập vào địa chỉ ip để xem kết quả http://ip-vps/

2. Cài đặt php-fpm và cấu hình để làm việc với lighttpd

Chạy lệnh sau để cài đặt php

# yum -y install php-fpm lighttpd-fastcgi

Ta chỉnh sửa user và group thành lighttpd

# nano /etc/php-fpm.d/www.conf

; RPM: apache Choosed to be able to access some dir as httpd
user =
lighttpd
; RPM: Keep a group allowed to write in log dir.
group =
lighttpd

Truy cập vào file php.ini

# nano /etc/php.ini

Bỏ dấu ghi chú của dòng sau

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo

cgi.fix_pathinfo=1

Mở file  /etc/lighttpd/modules.conf

# nano /etc/lighttpd/modules.conf

Bỏ dấu ghi chú dòng sau để trỏ đường dẫn đến conf.d/fastcgi.conf

##
## FastCGI (mod_fastcgi)
##

include "conf.d/fastcgi.conf"

Mở file /etc/lighttpd/conf.d/fastcgi.conf

# nano /etc/lighttpd/conf.d/fastcgi.conf

Và thêm các dòng định nghĩa sau

## for the php-num-procs example it means you will get 17*5 = 85 php
## processes. you always should need this high number for your very
## busy sites. And if you have a lot of RAM. :)
##

fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

#fastcgi.server = ( ".php" =>
#                   ( "php-local" =>
#                     (
#                       "socket" => socket_dir + "/php-fastcgi-1.socket",
#                       "bin-path" => server_root + "/cgi-bin/php5",
#                       "max-procs" => 1,
#                       "broken-scriptfilename" => "enable",

 

Khởi động php và chạy cùng hệ thống

# systemctl enable  php-fpm.service
# systemctl start  php-fpm.service

Khởi động lại lighttpd

# systemctl restart  lighttpd.service

Kiểm tra 

Kiểm tra xem lighttpd và php đã làm việc với nhau chưa bằng cách tạo 1 file info.php

# nano /var/www/lighttpd/info.php

<?php
phpinfo();
?>

Truy cập vào Web địa chỉ http://ip-vps/info.php  để xem kết quả

Xem xong chúng ta xóa file này đi để bảo mật 

# rm -rf /var/www/lighttpd/info.php

3. Cài đặt một số module để php và maria làm việc với nhau 

Gõ các lệnh sau đây để cài một số module

# yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
# yum -y install php-pecl-apc

Khởi động lại php

# systemctl reload php-fpm.service

4.Cài đặt MariaDB

Thêm kho MariaDB repo

Nếu bạn dùng mariaDB 5 thì cứ cài như bình thường 

Để cài đặt MariaDB 10 ,bạn cần thêm một repository sau vào hệ thống bằng cách chạy lệnh sau 

# wget -O /etc/yum.repos.d/MariaDB.repo http://mariadb.if-not-true-then-false.com/centos/$(rpm -E %centos)/$(uname -i)/10

Sau đó hãy xóa cache của yum đi

# yum clean all

update lại hệ thống để yum để nó cập nhật package của MariaDB

# yum update -y

Nếu bạn không làm 2 bước trên nó sẽ báo lỗi như sau 

Transaction Check Error:

file /usr/share/mysql/ukrainian/errmsg.sys from install of MariaDB-server-10.0.25-1.el6.x86_64 conflicts with file from package mysql-libs-5.5.50-1.el6.remi.x86_64

Error Summary


Xem thêm link tham khao nâng cấp mariaDB từ 5. lên mariaDB 10. click here

Cài đặt MariaDB 5.5

# yum install -y MariaDB MariaDB-server

Khởi động MariaDB

# systemctl start mariadb

Cho MariaDB khởi động cùng hệ thống

# systemctl enable mariadb

Đặt mật khẩu cho tài khoản root MariaDB:

# mysql_secure_installation

Sẽ hiện ra các câu sau

câu 1 : Enter current password for root (enter for none)<Nhập mật khẩu hiện tại cho root (nhập cho không có)> : cứ enter là xong

câu 2 : Set root password? [Y/n]<Đặt mật khẩu gốc> chọn Y và nhập mật khẩu 

câu 3 : Remove anonymous users? [Y/n]<xóa người dùng vô danh> chọn Y

câu 4 : Disallow root login remotely? [Y/n]<Không cho phép đăng nhập root từ xa> chọn Y 

câu 5 : Remove test database and access to it? [Y/n]<xóa cơ sở dữ liệu kiểm tra và truy cập vào nó> chọn Y

câu 6 : Reload privilege tables now? [Y/n]<khởi động lại> Chọn Y

Để đăng nhập vào mariaDB

# mysql -u root -p

Một số câu lệnh của mariaDB

Hiển thị toàn bộ databases:

MariaDB [(none)]> SHOW DATABASES;

Tạo database:

MariaDB [(none)]> CREATE DATABASE tên cở sở dữu liệu;

Sử dụng một database:

MariaDB [(none)]> USE tên cở sở dữu liệu;

Xóa một database:

MariaDB [(none)]> DROP DATABASE tên cở sở dữu liệu;