设为首页 收藏本站
查看: 960|回复: 0

LAMP-apache编译安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-30 09:13:00 | 显示全部楼层 |阅读模式
apache编译安装笔记
系统环境:Centos6.6  64位
apache版本2.4.23
下载apache文件http://httpd.apache.org/download.cgi#apache24

一、准备工作:
先安装依赖组件pcre和openssl-devel
yum -y install pcre-devel
yum -y install openssl-devel

下载、安装apr和apr-util组件
apr下载地址:http://apr.apache.org/download.cgi
1.安装apr
tar xf apr-1.5.2.tar.bz2
cd  apr-1.5.2   
./configure --prefix=/usr/local/apr   #指定安装路径为/usr/local/apr
make
make install           

2.安装apr-util
tar xf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
#指定安装路径:--prefix=/usr/local/apr-util
#告知软件所依赖的apr的安装路径:--with-apr=/usr/local/apr


二、安装httpd
#tar xf httpd-2.4.23.tar.bz2
#cd httpd-2.4.23
#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd  --enable-so --enable-rewirte --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  --with-mpm=event
#make
#make install
安装完成!

# 各编译参数详解
--prefix:#安装路径
--sysconfdir:#指定配置文件路径
--enable-so:#DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-ssl:#支持SSL/TLS,可以实现https访问
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite:#启用Rewrite功能
--enable-deflate:#支持压缩
--with-z:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找
--with-apr:#指定apr安装路径
--with-apr-util:#指定apr-util安装路径
--enable-modules:#支持动态启用的模块,可选参数有“all”,“most”,“few”,“reallyall”
--enable-mpms-shared:#支持动态加载的MPM模块,可选“all”
--with-mpm:#设置默认启用的MPM模式
httpd的MPM有:prefork,worker,event
httpd2.4编译安装的默认MPM为:event


三、启用之前需要配置:
启动httpd之前必须先关闭:selinux
使用:getenforce 查看状态
Enforcing
使用:setenforce 0 关闭
保持状态为Permissive即可:[iyunv@localhost httpd-2.4.23]# getenforce
Permissive
使用vim /etc/selinux/config
将  SELINUX=permissive

添加主机名称:
在配置文件:/etc/httpd/httpd.conf 里面添加
            ServerName localhost:80
在/usr/local/apache/目录下,使用bin/apachectl start启动
关闭防火墙:service iptables stort  即可访问。


更改pid文件目录:
修改vim /etc/httpd/httpd.conf
添加:#PidFile "/var/run/httpd.pid"   先用#注释这条命令
使用root@localhost apache]# bin/apachectl stop   #关闭apachectl
使用:[iyunv@localhost apache]# netstat -tnlp     #验证80端口是否关闭
成功关闭之后进入vim /etc/httpd/httpd.conf把之前注释的命令启用
查看ls /var/run/ 文件夹是否有httpd.pid文件


启动,停止设置:
创建编辑文件:vim /etc/init.d/httpd
写入内容:
#/etc/init.d/httpd  文件

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#               server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
#  implementing the current HTTP standards.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions   #读取函数

if [ -f /etc/sysconfig/httpd ]; then   #判断该目录下如有httpd文档(配置文件)
        . /etc/sysconfig/httpd          #读到该目录下
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}   #如果该变量有值HTTPD_LANG就用原来的值,没有就用"C"的值  

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""   #这个变量值为空

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl    #定义apachectl程序文件路径
httpd=${HTTPD-/usr/local/apache/bin/httpd}    #定义httpd程序文件路径
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}    #pid文件路径,也就是上一步定义的路径
lockfile=${LOCKFILE-/var/lock/subsys/httpd}   #锁文件
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
        status -p ${pidfile} $httpd > /dev/null
        if [[ $? = 0 ]]; then
                echo -n $"Stopping $prog: "
                killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
        else
                echo -n $"Stopping $prog: "
                success
        fi
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart|try-restart)
        if status -p ${pidfile} $httpd >&/dev/null; then
                stop
                start
        fi
        ;;
  force-reload|reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
        RETVAL=2
esac

exit $RETVAL


给该文件添加执行权限:chmod +x /etc/init.d/httpd
使用命令:service httpd restart  即可重启


开机自动启动:
chkconfig --add httpd   #加入服务列表
chkconfig --list httpd   #查看默认状态
chkconfig --httpd on     #更改状态

启用httpd自带命令:
新建文件: vim/etc/profile.d/httpd.sh
写入内容:export PATH=$PATH:/usr/local/apache/bin
使用命令验证:echo $PATH


更改MPM模块:
编辑:vim/etc/httpd/httpd.conf
默认使用的是event模块:LoadModule mpm_event_module modules/mod_mpm_event.so
使用httpd -M   #查看默认使用的模块

打开/etc/httpd/extra/httpd-mpm.conf可配置mpm


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-307491-1-1.html 上篇帖子: lnmp源码安装-脚本执行 下篇帖子: centos6 LNMP的搭建(linux+nginx+mysql+php)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表