Bạn cần cập nhật Apache lên phiên bản 2.4.27 nhưng nếu cài từ RPM thì chỉ ở 2.4.6. Hay cần kích hoạt http2 nhưng mặc định không được hỗ trợ?
Nếu như vậy, thì hãy tự compile apache 2.4 – cài đặt apache 2.4 từ source code , và điều chỉnh sao cho thiết lập và vị trí cài giống y như cài với RPM (quen thuộc hơn).
Chuẩn bị
Đầu tiên cần chuẩn bị một số thứ trước khi bắt đầu Compile được:
# mkdir -p /root/build && cd /root/build
# yum -y install epel-release # yum -y groupinstall "Developer Tools" # yum -y install pcre-devel expat-devel
Các gói phụ trợ khác:
Apache httpd - http://httpd.apache.org/download.cgi#apache24 APR + APR-Util - https://apr.apache.org/download.cgi
Ở đây là httpd 2.4.27, APR 1.6.2, APR-Util 1.6.0
# wget http://www-us.apache.org/dist//httpd/httpd-2.4.27.tar.gz http://www-us.apache.org/dist//apr/apr-1.6.2.tar.gz http://www-us.apache.org/dist//apr/apr-util-1.6.0.tar.gz https://www.openssl.org/source/openssl-1.1.0f.tar.gz https://github.com/nghttp2/nghttp2/releases/download/v1.25.0/nghttp2-1.25.0.tar.gz
Giải nén tất cả.
# tar xf apr-1.6.2.tar.gz && tar xf apr-util-1.6.0.tar.gz && tar xf httpd-2.4.27.tar.gz && tar xf openssl-1.1.0f.tar.gz nghttp2-1.25.0.tar.gz
Xong bước chuẩn bị
Compile Apache 2.4 và kích hoạt http2
OpenSSL và nghttp2
Trước hết, hãy Compile OpenSSL bản mới nhất.
# cd /root/build/openssl-1.1.0f # ./config # make # cp libssl.so.1.1 libcrypto.so.1.1 /usr/lib64
Tương tự với nghttp2
# /root/build/nghttp2-1.25.0 # ./configure --enable-lib-only # make
APR và APR-UTIL
Mục đích chính vẫn là Compile sao cho giống gói RPM. Ngoài ra, điều chỉnh suEXEC về /home (Sau này sẽ hổ trợ tốt cho Virtualmin – Webmin) hoặc cái gì gì đó cần dùng suEXEC
# cp -r /root/build/apr-1.6.2 /root/build/httpd-2.4.27/srclib/apr # cp -r /root/build/apr-util-1.6.0 /root/build/httpd-2.4.27/srclib/apr-util
Thay vì phải tự compile apr và apr-util thì hãy để httpd tự làm
HTTPD 2.4
Bắt đầu Compile Apache 2.4 nào
# cd /root/build/httpd-2.4.27
./configure --prefix=/etc/httpd --with-included-apr --exec-prefix=/etc/httpd --sysconfdir=/etc/httpd/conf --sbindir=/etc/httpd/bin --bindir=/etc/httpd/bin --datadir=/var/www --mandir=/etc/httpd/man --libdir=/etc/httpd/lib --libexecdir=/etc/httpd/modules --includedir=/etc/httpd/include --with-mpm=prefork --with-ssl=/root/build/openssl-1.1.0f --with-nghttp2=/root/build/nghttp2-1.25.0 --enable-suexec --enable-so --enable-ssl --with-suexec --with-suexec-caller=apache --with-suexec-docroot=/home --without-suexec-logfile --with-suexec-syslog --with-suexec-bin=/etc/httpd/bin/suexec --with-pcre=/usr/lib/bin/pcre-config --enable-suexec-capabilitie --enable-http2 --enable-ssl-staticlib-dep --enable-mods-static=ssl
--enable-ssl
Kích hoạt SSL, để có thể dùng HTTPS và http2
--enable-so
Các module có thể kích hoạt/tắt mà không cần compile lại httpd
--with-mpm
Lựa chọn 3 dạng MPM, mặc định là prefork
, có thể dùng worker
hoặc event
--with-included-apr
APR đã nằm ở srclib
rồi
--prefix
vị trí cài đặt, ở đây là /etc/httpd
như cài từ RPM/Yum
--enable-http2
Kích hoạt hỗ trợ http2
Nếu không có lỗi gì xảy ra, trên SSH sẽ hiện như sau:
Tiếp tục compile với lệnh
make
và cài đặt httpd luôn
# make # make install
Quá trình compile diễn ra nhanh hay chậm là tùy thuộc cấu hình của VPS, hãy kiên nhẫn chờ
Nếu không gặp lỗi, sau khi make nó sẽ hiện như vậy
Kiểm tra lại httpd: /etc/httpd/bin/httpd -V
Chúc mừng bạn httpd đã được cài đặt thành công.
Thêm lệnh httpd và apachectl
# ln -sf /etc/httpd/bin/httpd /usr/bin/httpd # ln -sf /etc/httpd/bin/apachectl /usr/bin/apachectl
Tạo httpd.service
Mặc định sau khi cài đặt từ source code, không có service nào được tạo, nên không thể dùng lệnh để khởi động, kích hoạt chạy như bình thường được.
Ta sử dụng
apachectl start/stop/graceful
cho việc này, nhưng tiện hơn, hãy tạo cho nó một service
# vi /usr/lib/systemd/system/httpd.service
Dán các dòng lệnh này vào:
[Unit] Description=The Apache HTTP Server [Service] Type=forking #EnvironmentFile=/etc/httpd/bin/envvars PIDFile=/etc/httpd/logs/httpd.pid ExecStart=/etc/httpd/bin/apachectl start ExecReload=/etc/httpd/bin/apachectl graceful ExecStop=/etc/httpd/bin/apachectl stop KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target
Khởi động httpd, nếu hiện như vậy nghĩa là thành công rồi:
# systemctl daemon-reload # systemctl start httpd
PrivateTmp=true dùng để làm gì vậy bạn ?
Đoạn này có nghĩa nó sẽ dùng một thư mục tmp riêng chứ không dùng chung /tmp của root nữa