apache

分类:software 日期:2021-02-12 作者:admin 浏览:102

包管理器

# ubuntu
sudo apt install apache2

# centos
sudo yum install httpd

编译安装

ubuntu 18.04
centos7
httpd-2.4.46

1.下载软件及相关包

2.安装依赖

#ubuntu
sudo apt install gcc zlib1g-dev build-essential openssl -y 

#centos
sudo yum install gcc gcc-c++ zlib-devel openssl libxml2-devel expat-devel -y 

#编译安装的依赖参数
# apr
./configure  --prefix=/usr/local/apr
make && make install

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

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

centos7报错参考

编译apr报错cannot remove 'libtoolT': No such file or directory参考

报错Another app is currently holding the yum lock; waiting for it to exit...执行
rm -rf /var/run/yum.pid

3.编译安装

tar -zxf httpd-2.4.46
cd httpd-2.4.46

./configure --prefix=/usr/local/apache2.4.46 \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--enable-rewrite \
--with-mpm=worker \
 --with-apr=/usr/local/apr \
 --with-apr-util=/usr/local/apr-util \
 --with-pcre=/usr/local/pcre
make && make install 

/usr/local/apach/bin/apachectl #检查启动服务

httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
最后出现以上警告信息即安装成功,
也可使用lsof -i :80 查看占用80端口的是不是httpd

centos7 编译失败

参考

错误信息如下

bapr-1.la -lrt -lcrypt -lpthread -ldl -lcrypt
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/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'

解决办法

  1. yum install libxml2-devel -y
  2. rm -rf /usr/local/apr-util #删除后重新编译安装
  3. 重新之前的两个步骤继续安装即可

编译安装 apr-utilhttpd 都要 make clean 已清除之前的安装信息

配置(未测试,经供参考)

  • 去除版本号

    1. 去除httpd.confInclude conf/extra/httpd-default.conf的注释
    2. apachectl graceful
    3. 修改httpd-default.conf的以下两项为:
# 第55,65行
ServerTokens Prod
ServerSignature Off
  • 开启防盗链

    1. 去除httpd.confLoadModule rewrite_module modules/mod_rewrite.so行的注释
    2. 添加如下内容
<IfModule rewrite_module >
    RewriteEngine On
    RewriteCond % {HTTP_REEERER} !^http://DomainName/.*$  [NC]
    RewriteCond % {HTTP_REEERER} !^http://DomainName $  [NC]
    RewriteCond % {HTTP_REEERER} !^http://DomainName / .*$  [NC]
</IfModule>
  • 增加对php支持
cp /usr/local/apache/conf/httpd.conf httpd.conf.bak
vi  /usr/local/apache/conf/httpd.conf

#在大概390行添加两行内容
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

参考

评论 (暂无评论)

发表评论

昵称:  
邮箱:  
网址: