1. 检查机器是否已经安装了apache(系统自带)Centos6.5
rpm -qa |grep httpd
rpm -qa |grep apache
并检查/etc/httpd/httpd.conf 配置文件是否存在
如果存在则先卸载,或者关闭centos自带的web服务,执行chkconfig httpd off
并修改httpd的服务端口80为其他端口
2. 在官网下载对应的release
http://httpd.apache.org/
选择现在当前最新版本: httpd-2.4.25.tar.gz
3.将安装包拷贝到VM上并解压
tar -zxvf httpd-2.4.25.tar.gz
4. 正常安装(另有安装一些相关插件会在后面补充)
进入httpd-2.4.25文件夹(cd httpd-2.4.25)
执行命令
./configure --prefix=/usr/local/apache2
然后报错:(找不到apr)
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation.
5. 处理apr问题
http://apr.apache.org/download.cgi 下载对应的安装包
以 apr-1.5.2.tar.gz 为例
和上段一致拷贝到文件夹下解压
tar -zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make
make install
成功后会出现很多文件安装 done 的字样
注意如果没有安装权限要sudo make/sudo make install
6. 处理apr-util问题
继续执行命令
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache2
出现以下报错
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... yes
setting CC to "gcc"
setting CPP to "gcc -E"
setting CFLAGS to " -g -O2 -pthread"
setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
继续安装apr-util依赖包 (参照apr下载地址)
命令和安装apr类似
tar -zxf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
make
make install
安装apr-util包编译时报错
fatal error: expat.h: No such file or directory
#include <expat.h>
^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1v
安装expat-deval 解决这个问题
7.继续编译安装apache
如果继续按照上文
./configure --prefix=/usr/local/apache2 可能仍然报错没安装apr-util
可是老娘刚才已经装了撒!
执行
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
即可
编译的时候没有将apr-util路径加上他不认得罢了
继续,
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... yes
setting CC to "gcc"
setting CPP to "gcc -E"
setting CFLAGS to " -g -O2 -pthread"
setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
在 http://pcre.org/ 安装pcre包
tar -zxf pcre-8.40.tar.gz
cd pcre-8.40
./configure --prefix=/usr/local/pcre
make
make install
8.继续编译安装apache
cd httpd-2.4.25
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make
make install
9.启动apache
/usr/local/apache2/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
vim /usr/local/apache2/conf/httpd.conf
添加
将
#ServerName www.examda.com:80
改为
ServerName localhost:80即可
保存退出
重新启动
/usr/local/apache2/bin/apachectl restart
还是不行(此时能ping通)
最终发现,将iptables(防火墙)关闭即可
service iptables stop
在浏览器输入VM的IP地址访问,It works!
以上。
除此以外,上述所提及的几个包是安装apache必须的依赖包,
另外还有可能linux没有安装gcc
以下是安装gcc的guideline
gcc较为麻烦,不能用tar安装包来装,因为gcc自己依赖自己
所以只能用已经编译好的rpm来安装
参考网址:http://www.rpmfind.net/linux/rpm2html/search.php
找到gcc包相对应的你的linux系统版本,下载相对应的gcc,
执行命令 rpm -ivh gcc-XXXXXXXX,然后报错如下:
依照提示下载,
cpp = 4.8.5-28.el7 is needed by gcc-4.8.5-28.el7.x86_64
glibc-devel >= 2.2.90-12 is needed by gcc-4.8.5-28.el7.x86_64
libgomp = 4.8.5-28.el7 is needed by gcc-4.8.5-28.el7.x86_64
libmpc.so.3()(64bit) is needed by gcc-4.8.5-28.el7.x86_64
libmpfr.so.4()(64bit) is needed by gcc-4.8.5-28.el7.x86_64
安装cpp报错:
cpp = 4.8.5-28.el7 is needed by gcc-4.8.5-28.el7.x86_64
glibc-devel >= 2.2.90-12 is needed by gcc-4.8.5-28.el7.x86_64
libgomp = 4.8.5-28.el7 is needed by gcc-4.8.5-28.el7.x86_64
libmpc.so.3()(64bit) is needed by gcc-4.8.5-28.el7.x86_64
libmpfr.so.4()(64bit) is needed by gcc-4.8.5-28.el7.x86_64
安装顺序为:
mpfr-> libmpc-> cpp->cpp->libgomp -> glibc-devel(此步报错)
差
glibc-headers is needed by glibc-headers-2.17-222.el7.x86_64
装glibc-headers时,报错差
kernel-headers is needed by glibc-headers-2.17-222.el7.x86_64
下载后安装 kernel-headers->glibc-headers->glibc-devel->gcc
弹出安装libgomp冲突
file /usr/lib64/libgomp.so.1.0.0 from install of libgomp-4.8.5-28.el7.x86_64 conflicts with file from package libgomp-4.8.5-28.el7_5.1.x86_64
此时安装libgomp命令变为
rpm -ivh libgompXXXX --force --nodepes
再安装gcc安装成功
安装prce报错
报错configure: error: Invalid C++ compiler or C++ compiler flags
则需要安装gcc-c++(C++编译器)
rpm安装包为:
gcc-c++ & libstdc++ & libstdc++-devel