阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下Apache的安装与配置

140次阅读
没有评论

共计 4609 个字符,预计需要花费 12 分钟才能阅读完成。

本文安装的 httpd 版本为 httpd 2.4.4
安装之前确保 Development Libraries 与 Development tools 安装上。安装方法参考:http://www.linuxidc.com/Linux/2016-04/130080.htm 与 http://www.linuxidc.com/Linux/2016-04/130081.htm

一、编译安装
1、解决依赖关系

安装 httpd 2.4.4 时首先需要解决依赖关系,httpd 2.4.4 需要较新版本的 apr 和 apr-util。升级方式有两种,一种是通过源代码编译安装,一种是直接升级 rpm 包。本文选择第一种方法来进行升级。在这里我们下载 apr-1.4.6.tar.bz2 与 apr-util-1.5.2.tar.bz2 版本。为了以后不必要的麻烦,在这里一定要保证系统时间正确,不正确的 (data 自行修改)。
apr 和 apr-util 的下载路径为:http://archive.apache.org/dist/apr/ 
(1) 首先根据惯例剪切 apr 与 apr-util 到 /usr/local/src 下,然后进行解压操作
mv  apr-1.4.6.tar.bz2  /usr/local/src
mv  apr-util-1.5.2.tar.bz2  /usr/local/src
tar -xjvf apr-1.4.6.tar.bz2
tar -xjvf apr-util-1.5.2.tar.bz2
(2) 编译安装 apr
cd apr-1.4.6
./configure –prefix=/usr/local/apr      #安装在 /usr/local/ 下 命名为 apr
make
make install
(3)编译安装 apr-util
cd apr-util-1.5.2
 ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
make
make install
(4) httpd-2.4.4 编译过程也要依赖于 pcre-devel 软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可。
yum -y install pcre-devel
到此为止基本上解决了依赖关系。
2、编译安装 httpd-2.4.4
下载 httpd-2.4.4.tar.bz2 下载地址为 https://archive.apache.org/dist/httpd/
(1)首先根据惯例剪切 httpd-2.4.4.tar.bz2 到 /usr/local/src 下,然后进行解压操作
mv httpd-2.4.4.tar.bz2  /usr/local/src
tar -xjvf  httpd-2.4.4.tar.bz2
(2) 编译安装 httpd
cd httpd-2.4.4
./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
解释:
–enable-so:支持动态共享模块,如果支持 php 将不能与 apache 一起工作。必须要有
–enable-ssl:启用 ssl 功能,如果不启用将无法使用 https
–enable-mpms-shared=all:prefork、worker、event
–with-mpm=event:event 为默认
 –enable-rewrite:支持 URL 重写
–enable-cgi : 支持 cgi
–enable-cgid:httpd 使用 event 或者 worker 得启用被线程方式访问
–enable-modules=most : 启用大多数模块
–enable-mods-shared=most: 启用大多数共享模块
(3)setenforce 0 关掉 selinux。(临时关闭)
永久关闭 vim /etc/selinux/config

二、后续操作
1、启动 httpd
两种方法:第一种、/usr/local/apache/bin/apachectl start
第二种方法:先修改 http.pid 文件位置打开配置文件增加一行
vim /etc/httpd/httpd.conf    增加 PidFile“/var/run/httpd.pid”

Linux 下 Apache 的安装与配置

为了启动 httpd 更加方便,
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: – 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#      HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

if [-f /etc/sysconfig/httpd]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${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
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

start() {
        echo -n $”Starting $prog: “
        LANG=$HTTPD_LANG daemon –pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [$RETVAL = 0] && touch ${lockfile}
        return $RETVAL
}

stop() {
echo -n $”Stopping $prog: “
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[$RETVAL = 0] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $”Reloading $prog: “
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $”not reloading due to configuration syntax error”
        failure $”not reloading $httpd due to configuration syntax error”
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}

# See how we were called.
case “$1” in
  start)
start
;;
  stop)
stop
;;
  status)
        status -p ${pidfile} $httpd
RETVAL=$?
;;
  restart)
stop
start
;;
  condrestart)
if [-f ${pidfile} ] ; then
stop
start
fi
;;
  reload)
        reload
;;
  graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
  *)
echo $”Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}”
exit 1
esac

exit $RETVAL
将以上代码加入到 vim /etc/init.d/httpd 中
而后为此脚本赋予执行权限:
 chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
 chkconfig –add httpd
给 3,5 启动
chkconfig –level  3,5 httpd on
最后加路径
将 export PATH=$PATH:/usr/local/apache/bin
vim /etc/profile.d/httpd.sh 完成后重新登录就可以了。推荐使用第二种方法

三、验证

Linux 下 Apache 的安装与配置

安装成功!

Ubuntu Server 14.04 安装 Web 服务器(Linux+Apache+MySQL+PHP)  http://www.linuxidc.com/Linux/2015-06/119061.htm

Linux 下安装配置 PHP 环境(Apache2)  http://www.linuxidc.com/Linux/2015-05/118062.htm

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

Apache 的详细介绍:请点这里
Apache 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-04/130079.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4609字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中