Modify the httpd service of apache to the root permission.

Source: Internet
Author: User
Tags fully qualified domain name

Modify the httpd service of apache to the root permission.
1. modify the configuration file

[Root @ localhost ~] # Cd/etc/httpd/conf [root @ localhost conf] # vim httpd. conf modify the configuration file
Change User and group to root:
[root@localhost conf]# service httpd restartStopping httpd:                                           [  OK  ]Starting httpd: Syntax error on line 244 of/etc/httpd/conf/httpd.conf: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                                                          <span style="color:#ff6666;">[FAILED]</span>[root@localhost conf]#

An error occurred while restarting the service.

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

The error message indicates that if you want to run the apache service as a root user, you must add "-DBIG_SECURITY_HOLE" to the CFLAGS environment variable and re-compile the source code.


2. Download the source code, modify it, and recompile it. 1. Clean up the environment.
[Root @ localhost software] # rpm-qa | grep aprapr-1.3.9-5.el6_2.x86_64apr-util-1.3.9-3.el6_0.1.x86_64apr-util-ldap-1.3.9-3.el6_0.1.x86_64 [root @ localhost software] # rpm-e aprerror: Failed dependencies: libapr-1.so.0 () (64bit) is needed by (installed) apr-util-1.3.9-3.el6_0.1.x86_64libapr-1.so.0 () (64bit) is needed by (installed) httpd-tools-2.2.15-39.el6.centos.x86_64libapr-1.so.0 () (64bit) is needed by (installed) httpd-2.2.15-39.el6.centos.x86_64 [root @ localhost software] # rpm-e -- nodeps apr [-- nodeps indicates not to do dependency check] [root @ localhost software] # rpm-e -- nodeps apr-util [root @ localhost software] # rpm-qa | grep aprapr-util-ldap-1.3.9-3.el6_0.1.x86_64 [root @ localhost software] #


2. Download the source code for compilation and Installation
[root@localhost software]# wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz [root@localhost software]# wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz  [root@localhost software]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip[root@localhost software]# lsapr-1.4.5.tar.gz  apr-util-1.3.12.tar.gz  pcre-8.10.zip[root@localhost apr-1.4.5]# ./configure --prefix=/usr/local/apr[root@localhost apr-1.4.5]# make && make install[root@localhost apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config[root@localhost apr-util-1.3.12]# make && make install[root@localhost pcre-8.10]# ./configure --prefix=/usr/local/pcre[root@localhost pcre-8.10]# make && make install

Download apache and modify the source code:
<p>[root@localhost software]# wgethttp://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.10.tar.gz</p><p>[root@localhost software]# tar -xvf httpd-2.4.10.tar.gz </p><span style="color: windowtext;">[root@localhost software]# cd httpd-2.4.10</span>

Modify the Code include/http_config.h and add it to the file header.

#ifndefBIG_SECURITY_HOLE#defineBIG_SECURITY_HOLE#endif
Re-compile:

[root@localhost httpd-2.4.10]# ./configure --prefix=/usr/local/httpd --enable-ssl --enable-cgi --enable-mods-shared=allable-ssl --enable-cgi --enable-mods-shared=all  --enable-track-vars --enable-rewrite <strong>--with-apr-util=/usr/local/apr-util/ --with-apr=/usr/local/apr --with-pcre=/usr/local/pcre</strong>[root@localhost httpd-2.4.10]# make && make install


3. modify the configuration file and restart the service.
If the service is started, the corresponding User is the default User in the configuration file: deamon or apache. Now modify the configuration file:
[root@localhost httpd-2.4.10]# vim /usr/local/httpd/conf/httpd.conf
Change User and Group to root.
Restart the service:
[Root @ localhost httpd-2.4.10] #/usr/local/httpd/bin/apachectl startAH00558: httpd: cocould not reliably determine the server's fully qualified domain name, using localhost. localdomain. set the 'servername' directive globally to suppress this message: Modify the ServerName in the configuration file

Modify ServerName in the configuration file to: ServerName localhost: 80. Restart the service:
[root@localhost httpd-2.4.10]# /usr/local/httpd/bin/apachectl start[root@localhost httpd-2.4.10]# ps -ef |grep httpdroot      9919     1  0 16:02 ?        00:00:00 /usr/local/httpd/bin/httpd -k startroot      9920  9919  0 16:02 ?        00:00:00 /usr/local/httpd/bin/httpd -k startroot      9921  9919  0 16:02 ?        00:00:00 /usr/local/httpd/bin/httpd -k startroot      9922  9919  0 16:02 ?        00:00:00 /usr/local/httpd/bin/httpd -k startroot     10005 12944  0 16:03 pts/2    00:00:00 grep httpd[root@localhost httpd-2.4.10]#
If an httpd: unrecognized service error occurs during service httpd restart, copy/usr/local/httpd/bin/apachectl to/etc/init. d/httpd.
So far, the permission is successfully modified. Applaud ^



Supplement (possible errors during pcre installation ):
  • ./Libtool: line 990: g ++: command not found

    Make [1]: *** [pcrecpp. lo] Error 1

    Make [1]: Leaving directory '/root/software/pcre-8.10'

    Make: *** [all] Error 2

    Solution: yum install gcc + gcc-c ++
  • Make & make install errors:

    Libtool: link: unsupported hardcode properties

    Libtool: link: See the libtool documentation for moreinformation.

    Libtool: link: Fatal configuration error.

    Solution: After yum install gcc + gcc-c ++, recompile./configure and then make.

Other links:
  • Httpd unrecognised: http://blog.sina.com.cn/s/blog_701300bc0100nzuu.html
  • Run apache as root: http://www.linuxidc.com/Linux/2013-02/78967.htm
  • Compile and install apache problems: http://xtony.blog.51cto.com/3964396/836508









Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.