tags: [技术博文]
1.安装平台环境要求:
Ubuntu:
You will need to ensure that you have either libtool 1.5.6or 2.2.6b, or later. Expat 2.0.1 and PCRE 8.02 are alsorecommended to be installed. If building PCRE from source,you'll also need g++.
没有libtool和PCRE时,需要先安装libtool和PCRE
- 下载解压apache2.4.38
$ cd /usr/local$ wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.38.tar.gz$ tar zxvf httpd-2.4.38.tar.gz
- 进入httpd-2.4.38目录,执行命令安装apache2
$ ./configure --prefix=/usr/local/apache2
报错: configure: error: APR not found. Please read the documentation.
通过INSTALL文件了解到需要安装APR and APR-Util
- 安装APR and APR-Util到srclib目录下
进入httpd-2.4.38下的srclib目录,执行命令下载并解压APR and APR-Util
$ wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.5.tar.gz$ wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz$ tar zxvf apr-1.6.5.tar.gz$ tar zxvf apr-util-1.6.1.tar.gz
注意: 解压后的文件名不能带版本号,将apr-1.6.5改名为apr,apr-util-1.6.1改名为apr-util
$ mv apr-1.6.5 apr$ mv apr-util-1.6.1 apr-util$ rm apr-1.6.5.tar.gz apr-util-1.6.1.tar.gz
- 回到httpd-2.4.38根目录,再次执行./configure —prefix=/usr/local/apache2, 无报错后继续执行以下命令
$ make$ make install
成功执行后在/usr/local目录下会发现apache2已经存在
6.将原apache版本中定义的环境变量加到新的apache bin目录下的envvars文件中
$ cd /usr/local/apache2/bin$ cat /etc/apache2/envvars >> envvars
7.修改httpd.conf, 注释掉listen 80和ServerAdmin,在文件尾添加
ServerTokens OS# These need to be set in /usr/local/apache2/bin/envvarsUser ${APACHE_RUN_USER}Group ${APACHE_RUN_GROUP}IncludeOptional conf/sites-enabled/*.conf
并将日志文件的路径替换为
ErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${APACHE_LOG_DIR}/access.log combined
将“User daemon Group daemon” 改为
User ${APACHE_RUN_USER}Group ${APACHE_RUN_GROUP}
8.将旧版本apache下的 sites-enabled复制到/usr/local/apache2/conf
$ cp -r /etc/apache2/sites-enabled/ /usr/local/apache2/conf/
9.停止旧的服务(或者开放新的端口进行测试),启动新版apache进行测试
$ cd /usr/local/apache2/bin$ ./apachectl start
报错:Invalid command ‘XSendFile’, perhaps misspelled or defined by a module not included in the server configuration
这种报错是因为有些模块没有加载造成的,进入旧版apache的模块目录,将缺少的模块复制到新版中,并在httpd.conf中加载即可(也可以自己下载)
测试发现缺少mod_xsendfile.so和mod_wsgi.so
$ cp /usr/lib/apache2/modules/mod_xsendfile.so /usr/local/apache2/modules$ cp /usr/lib/apache2/modules/mod_wsgi.so /usr/local/apache2/modules$ cd /usr/local/apache2/modules$ sudo chmod +x mod_xsendfile.so mod_wsgi.so
在新版本的httpd.conf中加载
LoadModule wsgi_module modules/mod_wsgi.soLoadModule xsendfile_module modules/mod_xsendfile.so
重启新版apache
$ cd /usr/local/apache2/bin$ ./apachectl restart
