LAMP之apache源码安装
1. 首先打开网址http://httpd.apache.org/,下载httpd主程序包httpd version:httpd-2.4.16,并且上传到对应的服务器,我用的是rehel7.2
2. 安装之前,确保系统的干净,不要和yum/rpm编译安装的软件冲突,编译之前,组安装开发包
‘DEVELOPMENT TOOL’和‘DELELOPMENT LIBRARIES’
#yum groupinstall –y "Development Tools" "DevelopmentLibraries"
安装gcc依赖
#yum install –y gcc gcc-c++ openssl-delvel
3. 安装apr和apr-util依赖(apache的依赖包http://apr.apache.org/,version:apr-1.5.2,apr-util-1.5.4)
#tar xvf apr-1.5.2.tar.gz –C /usr/local/src/&&tar xfapr-util-1.5.4.tar.bz2 -C /usr/local/src/
#cd/usr/local/src/apr-1.5.2/ && ./configure --prefix=/usr/local/apr&& make && make install
#cd../apr-util-1.5.4/ && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr&& make && make install
# cd && tar xf pcre-8.37.tar.bz2 -C /usr/local/src/
# cd /usr/local/src/pcre-8.37/ && ./configure--prefix=/usr/local/pcre && make && make install && cd
4. 开始编译安装apache,解压上传的版本包
#tar xvf httpd-2.4.16.tar.bz2 –C /usr/local/src/
#cd /usr/local/src/ httpd-2.4.16
#./configure --prefix=/usr/local/apache2.4 --enable-so --enable-rewrite--enable-ssl --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --enable-modules=most--enable-mpms-shared=all --with-mpm=event && make && makeinstall
各项参数说明:
--prefix=/usr/local/apache2.4 #安装路径
--enable-so #支持动态加载模块
--enable-rewrite #支持网站地址重写
--enable-ssl #支持SSL加密
--with-pcre=/usr/local/pcre #pcre路径
--with-apr=/usr/local/apr #apr路径
--with-apr-util=/usr/local/apr-util #apr-util路径
5. 配置apache启动脚本
# cp /usr/local/apache2.4/bin/apachectl /etc/init.d/apache2.4
检查是否启动了httpd服务,#netstat –tlunp|grep httpd
如果有检测到,则停掉httpd服务
#/etc/init.d/httpd stop
#chkconfig httpd off
编辑脚本文件#vim /etc/init.d/apache2.4
#!/bin/sh
# chkconfig: 2345 6436
#这个是启动级别的服务,2345是指那些级别启动,64是开启顺序,应该在network服务的后面,36是关闭顺序,应该在network的前面,这里并不是注释
#默认network的是:234510 90
# description: Apache2.4.16 start script #描述字段,有了这两个字段,就可以用chkconfig命令控制
:wq
启动服务#service apache2.4 start
添加至开机自启#chkconfig apache2.4 on
6. 修改运行用户
# ps -aux | grepapache //源码编译apache,运行用户为deamon
Warning: bad syntax,perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 43191 0.0 0.0 70632 2184? Ss 16:54 0:00/usr/local/apache2.4/bin/httpd -k start
daemon 43192 0.0 0.1663500 4820? Sl 16:54 0:00/usr/local/apache2.4/bin/httpd -k start
daemon 43193 0.0 0.1414892 4184? Sl 16:54 0:00/usr/local/apache2.4/bin/httpd -k start
daemon 43194 0.0 0.1414892 4188? Sl 16:54 0:00/usr/local/apache2.4/bin/httpd -k start
root 43344 0.0 0.0103244 864 pts/0 S+ 17:12 0:00 grep apache
# id daemon //编译安装运行用户身份是daemon
uid=2(daemon)gid=2(daemon) groups=2(daemon),1(bin),4(adm),7(lp)
# useradd -M -s/sbin/nologin apache //创建一个用户用来运apache
# vim/usr/local/apache2.4/conf/httpd.conf //修改配置文件改变apache运行身份
User apache #运行用户
Group apache #运行组,创建apache的时候已经即时创建了apache这个组
# id apache
uid=500(apache)gid=500(apache) groups=500(apache)
更改目录权限
# chown -R apache:apache /usr/local/apache2.4/ //默认是root,改为apache