一、编译环境安装
安装Apache之前,我们需要安装编译Apache和所依赖的一些软件包,其中有:gcc、gcc-c++、apr、apr-util、pcre等包。
① 安装gcc、gcc-c++编译环境
[root@localhost ~]# yum install gcc gcc-c++
② 安装apr-1.6.5依赖包
[root@localhost src]# wget https://downloads.apache.org/apr/apr-1.6.5.tar.gz //下载压缩包
[root@localhost src]# tar -zxvf apr-1.6.5.tar.gz //解压
[root@localhost src]# cd apr-1.6.5 //进入解压包目录下
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr-1.6.5 //配置
...
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands //配置过程报错
//解决方法:将configure文件中 RM='$RM' 修改为 RM='$RM -f';
[root@localhost apr-1.6.5]# make clean //清除之前产生配置文件
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr-1.6.5 //再次配置即可成功
[root@localhost apr-1.6.5]# make && make install //编译并安装
③ 安装apr-util-1.6.1依赖包
[root@localhost src]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz //下载压缩包
[root@localhost src]# tar -zxvf apr-util-1.6.1.tar.gz //解压
[root@localhost src]# cd apr-util-1.6.1 //进入解压包目录下
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.6.5/ //配置 apr-util需要和apr相关联
[root@localhost apr-util-1.6.1]# make && make install //编译并安装
...
xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录 //编译过程报错
//解决方法:缺少expat库,执行命令yum install expat-devel -y即可;
[root@localhost apr-util-1.6.1]# make && make install //再次编译并安装
④ 安装pcre-8.42依赖包
[root@localhost src]# wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz //下载压缩包
[root@localhost src]# tar -zxvf pcre-8.42.tar.gz //解压
[root@localhost src]# cd pcre-8.42 ////进入解压包目录下
[root@localhost pcre-8.42]# ./configure --prefix=/usr/local/pcre-8.42
[root@localhost pcre-8.42]# make && make install //编译并安装
二、安装Apache
[root@localhost src]# wget https://downloads.apache.org/httpd/httpd-2.4.41.tar.gz //下载httpd-2.4.41.tar.gz至/usr/local/src/目录下
[root@localhost src]# tar -zxvf httpd-2.4.41.tar.gz //解压
[root@localhost httpd-2.4.41]# ./configure --prefix=/usr/local/httpd-2.4.41 --with-apr=/usr/local/apr-1.6.5/ --with-apr-util=/usr/local/apr-util-1.6.1/ --with-pcre=/usr/local/pcre-8.42/ //配置 httpd需要和apr、apr-util、pcre相关联
[root@localhost httpd-2.4.41]# make && make install //编译并安装
三、启动httpd服务
[root@localhost local]# /usr/local/httpd-2.4.41/bin/apachectl start //启动服务
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message //启动报错
[root@localhost local]# vim httpd-2.4.41/conf/httpd.conf //解决方法:编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80;
...
#ServerName www.example.com:80
ServerName localhost:80
...
[root@localhost local]# /usr/local/httpd-2.4.41/bin/apachectl restart //重启服务
四、验证是否启动成功
- # netstat -tunl | grep 80 //查看80端口状态
tcp6 0 0 :::80 :::* LISTEN
- # ps -ef | grep httpd //查看httpd进程
root 118816 1 0 21:20 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
daemon 118938 118816 0 21:36 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
daemon 118939 118816 0 21:36 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
daemon 118940 118816 0 21:36 ? 00:00:00 /usr/local/httpd-2.4.41/bin/httpd -k start
root 119114 7439 0 21:45 pts/0 00:00:00 grep --color=auto httpd
- 通过浏览器访问本地ip