LAMP 組件皆為開源,手動編譯可精確控制版本、啟用模組、優化參數,適合生產環境定製化部署。
/usr/local/apr/ # APR 庫
/usr/local/apr-util/ # APR-Util
/usr/local/apache/ # Apache HTTPD
/usr/local/mysql/ # MySQL
/usr/local/php/ # PHP
環境變數統一管理:
PATH、LD_LIBRARY_PATH、MANPATH 加入上述 bin、lib、share/man。
yum groupinstall "Development Tools"
yum install pcre-devel openssl-devel libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel
# APR
tar xf apr-1.4.6.tar.bz2 && cd apr-1.4.6
./configure --prefix=/usr/local/apr
make && make install
# APR-Util (指定 APR 路徑)
tar xf apr-util-1.5.2.tar.bz2 && cd apr-util-1.5.2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

tar xf httpd-2.4.4.tar.bz2 && cd httpd-2.4.4
yum -y install pcre-devel
./configure \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-rewrite \
--enable-ssl \
--enable-cgi \
--enable-cgid \
--enable-modules=most \
--enable-mods-shared=most \
--enable-mpms-shared=all \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util
make && make install

--enable-mpms-shared=all 編譯 prefork、worker、event 三種 MPM 為動態模組。--with-mpm=prefork 指定預設 (PHP 模組模式需 prefork)。
# 暫時
setenforce 0
# 永久
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
# 重開機生效


# 啟動
/usr/local/apache/bin/apachectl start
# 修改 httpd.conf 將 PID 檔導向標準位置
echo 'PidFile "/var/run/httpd.pid"' >> /etc/httpd/httpd.conf





cat > /etc/init.d/httpd <<'EOF'
#!/bin/bash
# chkconfig: - 85 15
# description: Apache HTTP Server
apachectl=/usr/local/apache/bin/apachectl
case $1 in
start) $apachectl start ;;
stop) $apachectl stop ;;
restart) $apachectl restart ;;
status) $apachectl status ;;
*) echo "Usage: $0 {start|stop|restart|status}"; exit 1 ;;
esac
EOF
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
MySQL 使用 cmake 配置,PHP 依需求啟用 --with-apxs2=/usr/local/apache/bin/apxs (模組模式) 或 --enable-fpm (PHP-FPM)。編譯參數極多,建議參考官方文件依專案需求裁剪。