Linux上安装Apache服务器(转)

安装httpd

http://httpd.apache.org/download.cgi
httpd-2.4.29.tar.gz
#创建httpd用户
groupadd httpd
useradd -g httpd -s /sbin/nologin -M httpd

tar zxvf httpd-2.4.29.tar.gz
cd httpd-2.4.29
./configure --prefix =/usr/local/apache
make && make install

编译apache时可能会出错:
#./configure --prefix……检查编辑环境时出现:
checking for APR… no
configure: error: APR not found . Please read the documentation
解决办法:

安装 apr apr-util pcre
https://apr.apache.org/download.cgi

apr-1.6.3.tar.gz

./configure --prefix=/usr/local/apr
make && make install

apr-util-1.6.1.tar.gz

./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

make && make install

编译apr-util时报错:make[1]: *** [xml/apr_xml.lo] Error 1

解决方法:yum -y install expat-devel

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

pcre-8.38.zip

./configure --prefix=/usr/local/pcre
make && make install

然后安装Apache:
./configure --prefix=/usr/local/apache/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/

make && make install

/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to XML_ParserCreate' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference toXML_GetErrorCode’
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to XML_SetUserData' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference toXML_ErrorString’
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to XML_SetEntityDeclHandler' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference toXML_ParserFree’
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to XML_SetElementHandler' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference toXML_StopParser’
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to XML_Parse' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference toXML_SetCharacterDataHandler’
collect2: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory /root/zhouw/package/httpd-2.4.29/support' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory/root/zhouw/package/httpd-2.4.29/support’
make: *** [all-recursive] Error 1

make 时上面报错,尝试用 apr-1.5.2 版本

下载地址: http://archive.apache.org/dist/apr/

wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz

wget http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

安装方法与上面 1.6版本一样,果然成功了。应该是 CentOS7 才支持 apr-1.6 版本。

安装完成后,切到安装目录,/usr/local/apache
#vim conf/httpd.conf
#配置 “Listen” 和“ServerName”属性

Listen 80
ServerName localhost

#./bin/apachectl configtest
Syntax OK

#启动httpd
/usr/local/apache/bin/apachectl start | stop | restart

或者:
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
/etc/init.d/httpd start

验证访问
http://“server ip”
It works!

报错总结及处理方法:

(1)configure: error: APR not found. Please read the documentation.

这是没有安装apr或者apr安装失败导致的,重新安装apr。

安装请查看第一步。

(2)configure: error: APR-util not found. Please read the documentation.

这是没有安装apr-util或者apr-util安装失败导致的,重新安装apr-util。

安装请查看第二步。

(3)configure: error: no acceptable C compiler found in $PATH

这是没有安装gcc编译器或者gcc编译器安装失败导致的,重新安装gcc。

yum install -y gcc

(4)xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录

这是没有安装expat-devel或者expat-devel安装失败导致的,重新安装expat-devel。

yum install -y expat-devel

(5)configure: error: Invalid C++ compiler or C++ compiler flags

这是没有安装gcc-c++或者gcc-c++安装失败导致的,重新安装gcc-c++。

yum install -y gcc-c++

(6)configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

这是没有安装pcre或者pcre安装失败导致的,重新安装pcre。

安装请查看第三步。

猜你喜欢

转载自blog.csdn.net/szuwangjl/article/details/86516800