以为很容易的事情,实际安装过程中,遇到的问题倒是不少,详细过程如下。
环境介绍
主机IP: 10.18.*.*
主机操作系统: Ubuntu Kylin 17.10 64bit
安装配置过程&问题解决办法
源码安装apache
在官网下载了最新版本的源码包:httpd-2.4.33.tar.gz
上传至目标主机,参考网上的安装过程进行操作:
rz httpd-2.4.33.tar.gz tar -zxvf httpd-2.4.33.tar.gz mv httpd-2.4.33 apache cd apache ./configure --prefix=/usr/local/apache2 --enable-module=so
结果出现错误提示:
configure: error: APR not found. Please read the documentation.
在网上找到了一个解决方案,如下:
安装提示所缺少的APR包,在官网下载最新的源码包:apr-1.6.3.tar.gz
安装步骤:
rz apr-1.6.3.tar.gz tar -zxvf apr-1.6.3.tar.gz cd apr-1.6.3 ./configure --prefix=/usr/local/apr make make install
注意:/usr/local/apr目录不用非得新建,会自动创建的,只要权限OK就没问题。
再次返回到apache目录,执行上个configure命令,依然还是会提示错误:
configure: error: APR-util not found. Please read the documentation.
好吧,看来还是缺东西,继续装缺少的包,在官网下载最新的源码包:apr-util-1.6.1.tar.gz
安装步骤:
rz apr-util-1.6.1.tar.gz tar -zxvf apr-util-1.6.1.tar.gz cd apr-util-1.6.1 ./configure –prefix=/usr/local/web/apr-util –with-apr=/usr/local/apr make make install
再次重复上面安装apache的过程,擦嘞,还是报错:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
服了,还缺东西,好吧,那继续,去官网下载最新的源码包:pcre-8.42.tar.gz
安装步骤:
rz pcre-8.42.tar.gz tar -zxvf pcre-8.42.tar.gz cd pcre-8.42 ./configure --prefix=/usr/local/pcre make make install
这回总算是不缺东西了吧,只不过得修改一下命令,将上面缺失后补充的内容添加到命令行上:
./configure --prefix=/usr/local/apache --enable-rewrite --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre make make install
至此,通过源码的方式,总算是安装成功了。
启动服务
首先要修改配置文件:
/usr/local/apache/conf/httpd.conf
由于我需要在远程访问这个主机,所以不能只是启动本地监听,我还希望可以通过10.18.*.*来访问,所以修改了配置文件中的配置项:
Listen 10.18.*.*:80
启动apache服务:
./apachectl start
通过我本地访问该站点,倒是可以访问,下面的问题就是按我希望的目录去展示了,于是继续修改配置文件,参考网上的例子,修改后遇到了很多问题,包括:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.18.214.89. Set the 'ServerName' directive globally to suppress this message
httpd: Syntax error on line 67 of /usr/local/apache/conf/httpd.conf: Cannot load modules/mod_authn_file.so into server: /root/apidoc/modules/mod_authn_file.so: cannot open shared object file: No such file or directory
访问的主页并非预期目录下的主页
没有权限访问指定的页面
最终这些问题全部修改好后的配置文件如下,我这里只列举了关键配置,一些默认配置没有列举:
ServerRoot "/usr/local/apache" Listen 80 ServerAdmin ****@****.com ServerName localhost:80 DocumentRoot "/home/test/apidoc" <Directory "/home/test/apidoc"> <IfModule dir_module> DirectoryIndex index.html </IfModule>
至此,就完成了指定目录的apache服务启动展示了。效果还不错,不过apache比较强大,很多配置和内容还需要深入研究,暂时先把今天遇到的问题和解决方法罗列给大家,后续还会继续补充学习。
Ps:很多地方的***,都是由于敏感信息,我屏蔽掉了,不影响阅读和理解。