1、centos6中源码编译安装httpd-2.2.34
0 准备工作
查看相同的软件
rpm -qa "httpd*"
yum remove httpd
1 安装开发包组
yum groupinstall "Development tools"
2 下载源码并解包
tar xvf httpd-2.2.34.tar.bz2
cd /usr/local/src/httpd-2.2.34
3 看说明
cat README
cat INSTALL
4 生成Makefile
cd /usr/local/src/httpd-2.2.34
./configure --help
./configure --prefix=/app/httpd22/ --sysconfdir=/etc/httpd22/ --enable-ssl
echo $? ---判断上一条命令是否执行成功
yum install openssl-devel ---需要安装这个软件包
./configure --prefix=/app/httpd22/ --sysconfdir=/etc/httpd22/ --enable-ssl ---再执行一次。没有错误
5
make - j 4 && make install ---4颗cpu并行。让安装的速度快一点
6 软件配置
准备环境变量
echo 'export PATH=$PATH: /app/httpd22/bin'> /etc/profile.d/httpd22.sh ---此处需要注意,不能用双引号和不加符号,否则$PATH会展开
. /etc/profile.d/httpd22.sh ---让文件生效,也可以用source
echo $PATH
apachctl start ---这样在哪个目录下都可以运行apachectl,不用每次都得进入当前目录/app/httpd22/bin
ss -ntl 80端口打开即成功
http://本机IP/
vim /app/httpd22/htdocs/index.html
添加man帮助的路径到配置文件
vim /etc/man.config
加一行
MANPATH /app/httpd22/man
2、centos7中源码编译安装httpd-2.4.27
[root@centos7 test]#rpm -qa "httpd*" ---查看之前有没有安装过http,避免干扰
httpd-tools-2.4.6-45.el7.centos.x86_64
httpd-2.4.6-45.el7.centos.x86_64
[root@centos7 test]#yum remove httpd httpd-tools-2.4.6-45.el7.centos.x86_64
[root@centos7 test]#yum groupinstall " Development Tools" ---安装开发包组
Complete!
[root@centos7 test]#cd /usr/local/src/
[root@centos7 src]#ls
[root@centos7 src]#rz
[root@centos7 src]#ls
httpd-2.4.27.tar.bz2
[root@centos7 src]#tar -xvf httpd-2.4.27.tar.bz2 ---解压文件
[root@centos7 src]#ls
httpd-2.4.27 httpd-2.4.27.tar.bz2
[root@centos7 src]#cd httpd-2.4.27/
[root@centos7 httpd-2.4.27]#ls
ABOUT_APACHE CMakeLists.txt INSTALL NWGNUmakefile
acinclude.m4 config.layout InstallBin.dsp os
Apache-apr2.dsw configure LAYOUT README
Apache.dsw configure.in libhttpd.dep README.cmake
apache_probes.d docs libhttpd.dsp README.platforms
ap.d emacs-style libhttpd.mak ROADMAP
build httpd.dep LICENSE server
BuildAll.dsp httpd.dsp Makefile.in srclib
BuildBin.dsp httpd.mak Makefile.win support
buildconf httpd.spec modules test
CHANGES include NOTICE VERSIONING
[root@centos7 httpd-2.4.27]#cat README ---此文件介绍了apache http服务是干什么的
Apache HTTP Server
What is it?
-----------
[root@centos7 httpd-2.4.27]#cat INSTALL
APACHE INSTALLATION OVERVIEW
Quick Start - Unix
------------------
For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.4/install.html ---介绍了安装过程。可以分为四步
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
[root@centos7 httpd-2.4.27]#./configure --help ---运行configure脚本之前,先看一下帮助。里面告诉了一些用法,怎么制定路径,制定一些特性。哪些需要安装,哪些不需要安装
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/apache2]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24 ---运行configure脚本生成makefile文件,这里只规定安装目录就可以,不用指定其他的目录。这样不好管理,特性暂时也不加了,还没有学习到
[root@centos7 httpd-2.4.27]#yum install apr-devel.x86_64
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24
[root@centos7 httpd-2.4.27]#yum install apr-util-devel.x86_64
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24
[root@centos7 httpd-2.4.27]#yum install pcre-devel.x86_64
[root@centos7 httpd-2.4.27]#./configure --prefix=/app/httpd24 ---前面一直在排错的过程,运行脚本时发现有好多包都没有装。会提示错误,需要安装。一般都是与开发有关的包就可以
[root@centos7 httpd-2.4.27]#make -j 4 && make install&&echo -e '\a' ---制作和安装可以合成一步进行,最后加上打印声音,可以运行完之后发出声音,注意此步骤是在和configure脚本在同一目录下进行的
[root@centos7 httpd-2.4.27]#cd /app
[root@centos7 app]#ls
a.out hello hello.c Hello.class Hello.java httpd24 music music.sh test
[root@centos7 app]#cd httpd24/
[root@centos7 httpd24]#ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@centos7 httpd24]#cd bin
[root@centos7 bin]#ls
ab checkgid envvars-std htdbm httpd rotatelogs
apachectl dbmmanage fcgistarter htdigest httxt2dbm
apxs envvars htcacheclean htpasswd logresolve
[root@centos7 bin]#echo 'export PATH=/app/httpd24/bin:$PATH'>/etc/profile.d/httpd24.sh---设置变量,这样不用每次启动apachectl时进入该目录才能执行
[root@centos7 bin]#source /etc/profile.d/httpd24.sh
[root@centos7 bin]#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/app:/root/bin:/app:/app/test:/app/test/7.31:/root/bin:/app:/app/test:/app/httpd24/bin
[root@centos7 bin]#apachectl start
[root@centos7 bin]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::* ---对应的端口已经打开
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
[root@centos7 httpd24]#cd htdocs
[root@centos7 htdocs]#ls
index.html
[root@centos7 htdocs]#vim index.html ---修改一下网页的页面
1 <html><body><h1>welcome to magedu.com!</h1></body></html>
[root@centos7 man]#vim /etc/man_db.conf ---在man帮助的配置文件中增加次程序的路径。
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /app/httpd24/man
总结:需要注意的是:定义变量echo 'export PATH=/app/httpd24/bin:$PATH'>/etc/profile.d/httpd24.sh时一定要将/app/httpd24/bin写到前面,先生效,因为系统里自带一个apachectl,如果$PATH写到前面,会让/usr/sbin/apachectl这个路径先生效,这一样启动的时候就是系统自带的,而不是元码编译安装的。
3、在centos6和centos7上一键源码编译安装apache http服务的脚本
#!/bin/bash
yum -y -q remove httpd*&>/dev/null
echo "httpd* is removed"
yum -y -q groupinstall "Development Tools"&>/dev/null
echo "Development Tools is install"
release=`egrep -o " [0-9]" /etc/centos-release|tr -d " " `
[ "$release" -eq 6 ]&&{ cd httpd-2.2.34;./configure--prefix=/app/httpd22&>/dev/null;make && make install&>/dev/null; }
[ "$release" -eq 7 ]&&{ yum -y -q install "apr-devel.x86_64" "apr-util-devel.x86_64" "pcre-devel.x86_64"&>/dev/null;cd httpd-2.4.27;./configure --prefix=/app/httpd24&>/dev/null;make&>/dev/null && make install&>/dev/null; }
echo "apachectl is install"
unset release