您现在的位置是:首页> 操作系统> Linux> apache

让APACHE以ROOT身份运行

  • 5342人已阅读
  • 时间:2019-10-31 20:04:22
  • 分类:apache
  • 作者:祥哥

因为祥哥自己写了个WEB程序来控制FTP用户及用户的下载、上传、新建、删除等权限,所以用到了ROOT权限来执行一些chgrp,chown等系统的命令,我的APACHE,打开配置文件看一下是以daemon用户运行,直接改成root运行,报以下错误

Error:\tApache has not been designed to serve pageswhile\n\trunning as root.  There areknown race conditions that\n\twill allow any local user to read any file on thesystem.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLEto
 the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is stronglysuggested that you instead modify the User\n\tdirective in your httpd.conf fileto list a non-root\n\tuser.\n

祥哥也不懂英文,英文烂的就会两个单词。但搜了一下大致意思是

如果要用root用户来跑apache服务,需要添加“-DBIG_SECURITY_HOLE”到CFLAGS环境变量中,然后在重新编译源代码。

正好我的也是编译安装的,我们来重新编译一下

第一步进入到apache的原安装文件夹下的include/http_config.h,在文件头添加上

#ifndef BIG_SECURITY_HOLE
#define BIG_SECURITY_HOLE
#endif

然后重新编译即可。

如果之前编译过清除后在编译

make clean

改完在编译的过程中,遇到了一个错误如下

make[4]: *** [mod_deflate.la] Error 1
make[4]: Leaving directory `/home/zfh/httpd-2.2.9/modules/filters'
make[3]: *** [shared-build-recursive] Error 1
make[3]: Leaving directory `/home/zfh/httpd-2.2.9/modules/filters'
make[2]: *** [shared-build-recursive] Error 1
make[2]: Leaving directory `/home/zfh/httpd-2.2.9/modules'
make[1]: *** [shared-build-recursive] Error 1
make[1]: Leaving directory `/home/zfh/httpd-2.2.9'
make: *** [all-recursive] Error 1
[root@localhost httpd-2.2.9]#

就大至这个意思,因为祥哥是用的2.4的,这个是网上找的。

最后是这样解决的,说起来也是很奇怪,祥哥这里也有zlib

下载zlib-1.2.3.tar.gz放在/usr/local目录下执行以下命令:
tar -zxvf zlib-1.2.3.tar.gz
 cd zlib-1.2.3
 ./configure
 vi Makefile
找到 CFLAGS=-O3 -DUSE_MMAP
在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC
 make && make install

然后在进入httpd的安装目录,重新编译,在编译的参数后面加上

 --with-zlib-1.2.3=/usr/local/zlib-1.2.3 --enable-so

搞定了。在进入配置文件把用户及组修改成root,以root运行成功。

Top