1.下载httpd 2.4 源码
wget https://archive.apache.org/dist/httpd/httpd-2.4.54.tar.gz
2.解压下载压缩包
tar -zxvf httpd-2.4.54.tar.gz
cd httpd-2.4.54
3.安装httpd需要的依赖包
sudo yum groupinstall "Development Tools" -y
sudo yum install gcc glibc apr-devel apr-util-devel pcre-devel openssl-devel expat-devel make -y
4.配置http
./configure --prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
5.编译并安装httpd
make -j 4
sudo make install
6.创建Apache用户和组
sudo groupadd -r apache
sudo useradd -r -g apache -s /sbin/nologin apache
7.将 User daemon
改为 User apache
:
sed -r -i "s/^User [a-zA-Z]*/User apache/" /usr/local/httpd/conf/httpd.conf
8.将 Group daemon
改为 Group apache
:
sed -r -i "s/^Group [a-zA-Z]*/Group apache/" /usr/local/httpd/conf/httpd.conf
9.将 DocumentRoot "/usr/local/httpd/htdocs"
改为 DocumentRoot "/var/www"
:
sed -r -i "s%^DocumentRoot \".*\"%DocumentRoot \"/var/www\"%" /usr/local/httpd/conf/httpd.conf
10.将 <Directory "/usr/local/httpd/htdocs">
改为 <Directory "/var/www">
:
sed -r -i "s%^<Directory \".*htdocs\">%<Directory \"/var/www\">%" /usr/local/httpd/conf/httpd.conf
11.确保 /var/www
目录存在
sudo mkdir -p /var/www
6-11的图
12.创建一个系统服务管理脚本 /etc/init.d/httpd
:
sudo vi /etc/init.d/httpd
#!/bin/bash
. /etc/rc.d/init.d/functionsapachectl=/usr/local/httpd/bin/apachectl
httpd=/usr/local/httpd/bin/httpd
prog=httpd
start() {echo -n $"Starting $prog: "daemon $httpd $OPTIONSRETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/httpdreturn $RETVAL
}stop() {echo -n $"Stopping $prog: "killproc $httpdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpdreturn $RETVAL
}# See how we were called.
case "$1" instart)start;;stop)stop;;status)status $httpd;;restart)stopstart;;condrestart)if [ -f /var/lock/subsys/httpd ]; thenstopstartfi;;*)echo $"Usage: $0 {start|stop|restart|condrestart|status}"exit 1
esacexit $?
13.赋予执行权限
sudo chmod +x /etc/init.d/httpd
14.将 httpd
服务添加到系统服务管理中,并设置开机启动
sudo chkconfig --add httpd
sudo chkconfig httpd on
15.启动httpd服务
sudo service httpd start
16.检查服务状态
sudo service httpd status