linux基础(二)Apache和Nginx源码安装及报错处理

Apache安装步骤

1.下载所依赖文件

wget -c  http://archive.apache.org/dist/apr/apr-1.6.2.tar.gz
wget -c  http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
wget -c  https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
wget -c  http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.37.tar.gz

2.分别解压

tar -xf  apr-1.6.2.tar.gz 
tar -xf  apr-util-1.6.1.tar.gz 
tar -xf  pcre-8.41.tar.gz
tar -xf  httpd-2.4.37.tar.gz 

3.进行apr的安装

[root@myredhat Desktop]# cd apr-1.6.2
[root@myredhat apr-1.6.2]# ./configure --prefix=/usr/local/apr
此时若出现:
  configure: error: no acceptable C compiler found in $PATH
则:
  yum install gcc-c++

[root@myredhat apr-1.6.2]# make     #继续安装三步骤
[root@myredhat apr-1.6.2]# make install

4.apr-util的安装

[root@myredhat apr-util-1.6.1]./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@myredhat apr-util-1.6.1]# make
此时若出现:
xml/apr_xml.c:434: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:438: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp_err’
xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c: In function ‘apr_xml_parser_geterror’:
xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/root/Desktop/apr-util-1.6.1'
make: *** [all-recursive] Error 1
则执行:yum -y install expat-devel

[root@myredhat apr-util-1.6.1]# make  #继续三步骤
[root@myredhat apr-util-1.6.1]# make install
若在make中出现错误:则清除缓存:make clean后执行相对应的操作

5.pcre的安装

[root@myredhat Desktop]# cd pcre-8.41
[root@myredhat pcre-8.41]# ./configure --prefix=/usr/local/pcre
[root@myredhat pcre-8.41]# make
[root@myredhat pcre-8.41]# make install

6.apache的安装

[root@myredhat Desktop]# cd httpd-2.4.37
[root@myredhat httpd-2.4.37]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre

若出现:
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/)
则执行:yum –y install pcre-devel
后重新执行上一步
[root@myredhat httpd-2.4.37]# make 

在编译时:若出现:
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.28/support”
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.28/support”
make: *** [all-recursive] 错误 1

则:
安装yum install -y libxml2-devel
后执行:
[root@myredhat httpd-2.4.37]# rm -rf /usr/local/apr-util
[root@myredhat Desktop]# cd apr-util-1.6.1
# 这一步很重要,必须清除之前配置时的缓存
[root@myredhat apr-util-1.6.1]# make clean
[root@myredhat apr-util-1.6.1] ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@myredhat apr-util-1.6.1] make ;make install
然后进入:http目录
make clean  #清除缓存
重新./configure配置安装
make && make install
yum –y  install gcc-c++ expat-devel  pcre-devel

Nginx安装步骤

1.使用yum安装依赖文件

yum -y install openssl-devel pcre-devel
注:使用yum安装openssl-devel时,会自动安装openssl,依次只用安装openssl-devel就好

2.下载Nginx

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

3.解压安装

tar xf  nginx-1.6.3.tar.gz
cd  nginx-1.6.3
./configure --prefix=/application/nginx  --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
注:
--prefix=安装位置
--user=USER 进程用户权限
--group=GROUP进程用户组权限
--with-http_stub_status_module 激活状态信息
--with-http_ssl_module  激活ssl功能

4.启动Nginx

/application/nginx/sbin/nginx –t

若出现:

nginx: [emerg] getpwnam("nginx") failed

则需要建立对应用户
useradd nginx -s /sbin/nologin –M
注:-s指定默认的shell解释器 -M不创建家目录
启动Nginx:
/application/nginx/sbin/nginx
或者
/application/nginx/sbin/nginx -s reload
若第二种方式出现:
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

/application/nginx/sbin/nginx  -c  /application/nginx/conf/nginx.conf
注;此时就会平滑重启,但是stop后又无法平滑重启

关闭Nginx:
/application/nginx/sbin/nginx -s stop

    原文作者:一名IT小学生
    原文地址: https://www.jianshu.com/p/30bdba898bd5
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞