您的位置:首页 > 运维架构 > Apache

手工编译安装apache

2018-07-03 16:01 369 查看
实验环境
RHEL6.5版本
IP地址:192.168.1.63 255.255.255.0
安装好yum仓库并安装 gcc 、 gcc-c++  、 make  、 pcre、pcre-devel 四个包(pcre : 一个Perl库,支持正则表达式)(系统自带)
实验用到的软件包:http-2.4.2.tar.gz,apr-1.4.6.tar.gz,apr-util-1.4.1.tar.gz。
-------------------------------------------------------------操作步骤------------------------------------------------------------------------------------
一,首先挂载下好包的文件夹到linux系统中。
mount.cifs //主机地址/包文件夹 /opt/lamp



 
二,解压上述三个包到/opt下。
tar xzvf http-2.4.2.tar.gz -C /opt/
tar xzvf apr-1.4.6.tar.gz -C /opt/  (支持Apache上层应用跨平台,提供底层接口库)
tar xzvf apr-util-1.4.1.tar.gz -C /opt/



依次解压三个包后,ls查看/opt.



 
四,把解压好的包放入httpd文件夹里。
cp -R  apr(解压后的文件夹) /opt/httpd-2.4.2/srclib/apr
cp -R  apr-util(解压后的文件夹) /opt/httpd-2.4.2/srclib/apr-util




五,源码编译安装Apache。
在[root@localhost httpd-2.4.2]# 下输入
./configure \
--prefix=/usr/local/apache \
--enable-so \
--enable-rewrite \
--enable-mods-shared=most \
--with-mpm=worker \
--disable-cgid \
--disable-cgi



上述参数解释:
--prefix=   //来指定安装路径
--enable-so  //该参数表示支持用mod_so模块提供的功能,用LoadModule在httpd.conf文件或包含的conf文件中动态加载某个模块。让 Apache 可以支持DSO模式
--enable-rewrite  //支持 URL 重写
--enable-mods-shared=most  //选项:告诉编译器将所有标准模块都动态编译为DSO模块。
--with-mpm=worker // 让apache以worker方式运行
--with-mpm=worker   //该参数是配置apache将以何种模式编译的。Apache网站文档指出不同操作系统下的不同的默认模式.
--disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
--disable-cgi //禁止编译 CGI 版本的 PHP
接着:
make   #编译
make install    #安装



 
六,优化路径,将/usr/local/apache/bin/下的所有命令内容链接到PATH变量中的路径下。
只有将命令链接到PATH变量的路径中,命令才可以被使用。
grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd
vi /etc/init.d/httpd   # 在文件最前面插入下面的行
#!/bin/sh
    # chkconfig:2345 85 15
    # description:Apache is a World Wide Web server.



七,使程序可以使用service 管理。
chmod +x /etc/init.d/httpd  #添加写的权限给httpd
chkconfig --add httpd       #开机自动加载
chkconfig --list httpd
chkconfig --level 35 httpd on    #打开3.5模式



八,建立软连接便于管理
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf (注意:软连接使用绝对路径)
[root@localhost httpd-2.4.2]# vim /etc/httpd.conf     #编辑apache配置文件

Listen:IPV4 #去掉#号




ServerName:主机名.域名       (写自己的)
 



九,关闭防火墙,开启服务。
service iptables stop #关闭防火墙
service httpd stop#关闭服务
service httpd start#启动服务
[root@localhost httpd-2.4.2]# netstat -ntap | grep 80    #监听http服务
tcp        0      0 192.168.78.130:80           0.0.0.0:*                   LISTEN      88630/httpd        




 
十,物理机验证http服务。
 



成功
 
注释:在/usr/local/apache/htdocs/下存放着apache服务自带的index。Html网页,用于验证,次服务是否启动成功,在此目录下,可以创建更多的网页文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  云计算 其他