【环境】
查看当前版本:
/usr/local/apache2/bin/apachectl -v
卸载低版本:
如果有通过yum/rpm安装的Apache,需要先卸载:
rpm -e --nodeps httpd rpm -e --nodeps httpd-devel
【依赖】
编译安装 apr:
yum 安装 pcre:
【安装】
参考:http://www.linuxfromscratch.org/blfs/view/svn/server/apache.html
下载:http://httpd.apache.org/download.cgi
最新版本:httpd-2.4.46
wget http://www-us.apache.org/dist/httpd/httpd-2.4.46.tar.gz && tar -zxvf httpd-2.4.46.tar.gz && cd httpd-2.4.46 wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.46.tar.gz && tar -zxvf httpd-2.4.46.tar.gz && cd httpd-2.4.46 ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --with-crypto --enable-rewrite --enable-headers --enable-deflate --enable-socache-shmcb --enable-negotiation --enable-ssl --with-ssl=/usr/lib --with-apr=/usr/bin/apr-1-config --with-apr-util=/usr/bin/apu-1-config --enable-http2 --with-nghttp2=/usr/local/lib make && make install
输出:
... mkdir /usr/local/apache2/manual make[1]: Leaving directory `/root/apache/httpd-2.4.46'
查看版本:
/usr/local/apache2/bin/httpd -v
输出:
Server version: Apache/2.4.46 (Unix) Server built: Apr 12 2019 01:31:57
【CGI支持】
cd modules/generators
编译安装 cgi模块:
/usr/local/apache2/bin/apxs -i -a -c mod_cgi.c
编译安装 cgid模板:
/usr/local/apache2/bin/apxs -i -a -c mod_cgid.c
查看下配置文件 httpd.conf ,发现cgi与cgid模块已被加载:
... LoadModule cgi_module modules/mod_cgi.so LoadModule cgid_module modules/mod_cgid.so
【配置】
创建 apache 用户:
groupadd apache && useradd -g apache -s /sbin/nologin -M apache
设置启动命令:
将Apache设成系统服务:
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
编辑 /etc/init.d/httpd,在第二行加入:
# chkconfig: 2345 85 15 # description: httpd is web server
把Apache添加到系统的启动服务组里:
chkconfig --add httpd && chkconfig --level 35 httpd on
输入命令:
service httpd start
输出:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
没关系,这是因为没有在httpd.conf中设置主机名,在后面再处理。
设为开机启动:
chkconfig httpd on
查看Apache版本:
/usr/local/apache2/bin/apachectl -v
输出:
Server version: Apache/2.4.46 (Unix) Server built: Aug 9 2016 09:37:48
编译安装完成。
【排错】
报错:mod_proxy_balancer.c:25:24: fatal error: apr_escape.h: No such file or directory
开始没有编译安装apr和apr-util,会报这个错误。需要编译后指定路径。
或者编译参数可以去掉该模块,添加:–disable-proxy