Lighttpd là một sự thay thế cho Apache. Nó là một máy chủ web mã nguồn mở. Lighttpd phù hợp cho bộ nhớ và CPU sử dụng thấp, Đây có thể là lựa chọn tốt nhất cho các trang web lưu lượng truy cập cao. PHP là một ngôn ngữ lập trình lập trình sử dụng server-side. MariaDB là một sự thay thế của MySQL với nhiều cải tiến.

1. Add các repo cần thiết

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

2. Cài đặt Lighttpd
2.1. Cài đặt
yum -y install lighttpd lighttpd-fastcgi




2.2 Cấu hình

- Mở file /etc/lighttpd/lighttpd.conf
Tìm
server.use-ipv6 = "enable"
Sửa thành
server.use-ipv6 = "disable"
- Tìm
#server.max-fds = 2048
Sửa thành
 server.max-fds = 2048

- Khởi động Lighttpd

service lighttpd start
chkconfig lighttpd on 
3. Cài đặt MariaDB
3.1. Add repo
Vào /etc/yum.repos.d/
Tạo file:  mariadb.repo với nội dung

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/rhel6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1


Chú ý: Ở thời điểm mình viết tut thì phiên bản MariDB mới nhất là 10.1 . Để kiểm tra phiên bản các bạn có thể truy cập http://yum.mariadb.org/ sau khi tìm được bản mới nhất thì thay link phiên bản đó vào đòng:

baseurl = http://yum.mariadb.org/10.1/rhel6-amd64

3.2. Cài đặt MariaDB

yum -y install MariaDB-server MariaDB-client
service mysql start
chkconfig mysql on




3.3. Cấu hình bảo mật và đặt mật khẩu cho mariadb

mysql_secure_installation

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): [Bấm Enter]
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] YNew password: [Nhập mật khẩu bạn muốn]
Re-enter new password: [Nhập lại mật khẩu]
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
4. Cài đặt php-fpm
4.1 Cài đặt
yum --enablerepo=remi,remi-php56 -y install php php-common php-fpm php-mysql php-gd php-xml php-mbstring php-mcrypt php-pdo php-soap

Chú ý: lệnh này sẽ cài đặt php 5.6

- Chạy tiếp các lệnh sau
service php-fpm start 
chkconfig php-fpm on 
service lighttpd restart
4.2. Cấu hình FASTCGI và PHP-FPM
Mở file  /etc/php.ini tìm
;cgi.fix_pathinfo=1
Sửa thành
cgi.fix_pathinfo=1
- Mở file /etc/lighttpd/modules.conf
Tìm
#include "conf.d/fastcgi.conf"
Sửa thành
include "conf.d/fastcgi.conf"
- Mở file  /etc/lighttpd/conf.d/fastcgi.conf
Thêm vào
fastcgi.server += ( ".php" =>
        ((
                "host" => "127.0.0.1",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

- Khởi động lại php-fpm và lighttpd
service lighttpd restart
service php-fpm restart

5. Tạo VirtualHosts (Vhost)
5.1. Tạo thư mục root
 Có thể tạo bằng lệnh trên putty hoặc dùng winscp để tạo
Ở đây mình ví dụ tạo thư mục như sau:
/home/quylevhb/public_html

quylevhb: là user các bạn thay bằng user của các bạn.
- Chạy tiếp lệnh

chown -R user:group /home/user

Trong đó:
 + user: là user của bạn
 + group: là nhóm của user đó
ví dụ:

chown -R quylevhb:quylevhb /home/quylevhb

5.2. Cấu hình

 - Mở file /etc/lighttpd/lighttpd.conf
Tìm
#include_shell "cat /etc/lighttpd/vhosts.d/*.conf"
Sửa thành
include_shell "cat /etc/lighttpd/vhosts.d/*.conf"

5.3. Tạo file vhost 
- Vào thư mục /etc/lighttpd/vhosts.d tạo 1 file có dạng:  abc.conf

Ví dụ mình tạo file:  quyle.us.conf với nội dung như sau

$HTTP["host"] == "quylevhb.us" {
        server.document-root = "/home/quylevhb/public_html"
        server.errorlog = "/home/quylevhb/logs/error.log"
        accesslog.filename = "/home/quylevhb/logs/access.log"
}

- Tạo thư mục logs trong /home/quylevhb
-  Tạo file access.log và error.log trong thư mục logs chmod 666 cho 2 file này
- Chạy lệnh
lighttpd -t -f /etc/lighttpd/lighttpd.conf
Nếu thấy bảo như trong hình là ok



- Khởi động lại lighttpd

service lighttpd restart

6. Test

Tạo file info.php trong thư mục public_html với nội dung sau

<?php
phpinfo();
?>

Chạy thử xem sao




End tut. Have fun


Tut by Quỷ lệ - Thánh nào lech vui lòng cho em xin cái nguồn


Đăng nhận xét Blogger

 
Top