CentOS下apache 2.4.23 编译安装
与PHP、SVN等集成时最好用源安装,不然新手会出现很多文件位置问题。
一、系统软件版本
1、系统:CentOS Linux release 7.2.1511 (Core)
2、Apache:httpd-2.4.23 //下载地址:http://httpd.apache.org/download.cgi#apache24
3、OpenSSL:openssl-1.0.1e
4、Apr:apr-1.5.2 //下载地址:http://apr.apache.org/download.cgi
5、Apr-util:apr-util-1.5.4 //下载地址:http://apr.apache.org/download.cgi
6、Pcre:pcre-8.39 //下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
二、编译前准备工作
1、新建apache运行账户
groupadd apaches //创建apaches组 useradd -M -N -s /sbin/nologin -G apaches apache //创建apache用户并附加apaches组,-M不建立用户目录,-N不创建同名组,-s执行shell禁止登录
2、创建apache日志文件夹(非必须,只是为了方便维护,生产环境建议自定目录,以免日志增长导致系统盘爆满)
mkdir /data/http mkdir /data/http/logs mkdir /data/http/html
3、YUM安装所需依赖(也可用rpm包安装,但需要解决更多依赖)
yum install gcc gcc-c++ openssl openssl-devel zlib zlib-devel expat-devel //需要LDAP环境则需要安装openldap openldap-devel
三、编译安装Apache及组件
1、安装apr
tar -zxvf apr-1.5.2.tar.gz //解压 ./configure --prefix=/usr/local/apr //指定安装路径编译 make //安装 make install
2、安装apr-util
tar -zxvf apr-util-1.5.4.tar.gz //解压 ./configure --prefix=/usr/local/apr-util --with-ldap --with-apr=/usr/local/apr/bin/apr-1-config //指定安装路径编译,--witg-ldap编译LDAP支持,--with-apr指定apr-1-config的路径 make //安装 make install
注:如使用yum安装ldap组件还需要拷贝下so文件,不然会提示找不到so文件
cp /usr/lib64/libldap* /usr/lib/
3、安装Pcre
tar -zxvf pcre-8.39.tar.gz //解压 ./configure --prefix=/usr/local/pcre //指定安装路径编译 make //安装 make install
4、安装apache
tar -zxvf httpd-2.4.23.tar.gz //解压 ./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-http2 --enable-so --enable-dav --enable-ssl --enable-cgi --enable-rewrite --enable-ldap --enable-authnz-ldap --with-zlib --enable-modules=all --enable-mpms-shared=all --with-mpm=event make //安装 make install --prefix=/usr/local/apache:指定安装路径 --sysconfdir=/etc/httpd24:指定配置文件存放位置 --enable-so:允许运行时加载DSO模块 --enable-dav:启用davweb支持 --enable-ssl: 提供对安全套接字层(SSL)和传输层安全(TLS)协议实现高强度加密传输 --enable-cgi:提供对CGI脚本执行的支持 --enable-rewrite:支持重写 --with-zlib:是支持zlib库 --with-pcre:启用正则表达式 --with-apr=/usr/local/apr:Apache可移植运行时(APR)是httpd源码的一部分并会自动与httpd一起创建。如果你想使用一个已经存在的APR ,就必须在这里指定apr-config脚本的路径。 --with-apr-util=/usr/local/apr-util/:Apache可移植运行时工具包(APU)是httpd源码的一部分并会自动与httpd一起创建。如果你想使用一个已经存在的APU ,就必须在这里指定apu-config脚本的路径。 --enable-ldap:启用LDAP --enable-authnz-ldap:启用LDAP(需与--enable-ldap同时使用) --enable-modules=most:启用大多数常用模块。 --enable-mpms-shared=all:启用MPM支持的所有模式。 --with-mpm=event:设置默认MPM为event。
四、配置Apache
1、设置Apache开机自动启动
cp /usr/local/apache/bin/apachectl /etc/init.d/apached //拷贝脚本 vim /etc/init.d/apached //编辑脚本 再在第3行加入以下两行(注意:#号不能去掉) # chkconfig: 345 85 15 # description: This is Yeboyzq Web Server chmod +x /etc/init.d/apached //添加执行权限 chkconfig --add apached //添加到开机启动项
2、添加Apache环境变量
vim /etc/profile.d/apache.sh //新建脚本 在脚本中添加 export PATH=/usr/local/apache/bin/:$PATH //指定bin目录 . /etc/profile.d/apache.sh //执行脚本
3、修改配置文件
vim /etc/apache/httpd.conf (请按字段查找修改) LoadModule rewrite_module modules/mod_rewrite.so //开启功能 User apache //运行用户 Group apaches //运行用户所属组 ServerName localhost:80 //服务器名称及端口 DocumentRoot "/data/http/html" //网页目录 <Directory "/data/http/html"> //网页目录 ErrorLog "/data/http/logs/error_log" //错误日志存放路径 CustomLog "/data/http/logs/access_log" common //访问日志存放路径 Include /etc/apache/extra/httpd-vhosts.conf //开启虚拟目录配置文件 开启SSL则 LoadModule ssl_module modules/mod_ssl.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so Include /etc/apache/extra/httpd-ssl.conf
4、运行apache
firewall-cmd --permanent --zone=public --add-service=http //防火墙永久开放HTTP规则 firewall-cmd --reload //防火墙重新加载配置文件 service apached start //启动apache
发表评论