设为首页 收藏本站
查看: 401|回复: 0

[经验分享] how to intall multiple apache in linux

[复制链接]

尚未签到

发表于 2016-2-24 09:04:59 | 显示全部楼层 |阅读模式
  I've seen a couple of posts asking about running multiple instances
of Apache in the past week or two so I thought I'd post my quick-fix
solution to the problem.

  This is a UNIX/Linux solution which requires building Apache httpd
from the source, but don't let that scare you.  Please don't ask me
for a binary distribution or RPM, it's really not that hard to do it
yourself.  I can't offer any advice on other operating systems.  I've
tested it with Apache 2.0.36.  It takes me about 15 minutes to set up
a new instance of Apache httpd, including compile time, and I'm
running Linux on a 4 year old laptop.

  This approach relies on installing multiple instances of the httpd
software.  I typically do this when I need to test a new version of
Apache without disturbing the existing instances, or run an old
version next to a new one, or run two versions with different build
configurations, etc.  By default, these instances all have their own
htdocs directories, but by editing httpd.conf, you can organise them
to share htdocs directories too.

  To ensure clean and systematic separation of all of the files making
up each instance, I followed the Filesystem Hierarchy Standard 2.2
(FHS).  It's a standard that specifies where the various files making
up a piece of software should be placed.  See
http://www.pathname.com/fhs/ for details.

  But first some standard legal responsibility ducking.  All the usual
disclaimers apply.  If you foolishly choose to follow my advice and
something awful happens, you're on your own.  Having said that, what I
describe works just fine for me though.  :-)

  OK, here we go (in 11 easy steps)...

0.  Download and unpack the Apache 2 *source* distribution.  "cd" into
    the top level of the directory hierarchy you unpacked.  If you're
    in the right place there should be a file named "config.layout".
    (If instead of unpacking the distribution you're working from an
    existing source distribution it's vital that you "make distclean"
    before continuing).

1.  Add the following lines (between the "---snip---" lines, but not
    including them) at the bottom of the "config.layout" file.  This
    defines a new layout telling the install process where to place
    the files that make up an Apache instance:

---snip---
#   According to the Linux Filesystem Hierarchy Standard 2.2 (FHS) with
#   the full product name and version in the directory names.  For more
#   information see the specification at http://www.pathname.com/fhs/.
#
<Layout LinuxFHSFullName>
    prefix:        /opt/apache-httpd-2_0_36
    exec_prefix:   ${prefix}
    bindir:        ${exec_prefix}/bin
    sbindir:       ${exec_prefix}/sbin
    libdir:        ${exec_prefix}/lib
    libexecdir:    ${exec_prefix}/libexec
    mandir:        ${prefix}/man
    sysconfdir:    /etc${prefix}
    datadir:       /var${prefix}/share
    installbuilddir: ${datadir}/build
    errordir:      ${datadir}/error
    iconsdir:      ${datadir}/icons
    htdocsdir:     ${datadir}/htdocs
    manualdir:     ${prefix}/manual
    cgidir:        ${datadir}/cgi-bin
    includedir:    ${prefix}/include
    localstatedir: /var${prefix}
    runtimedir:    /var/run/apache-httpd-2_0_36
    logfiledir:    /var/log/apache-httpd-2_0_36
    proxycachedir: /var/cache/www/apache-httpd-2_0_36/proxy
</Layout>
---snip---

    I've specified a full product name and version number in the
    directory names for this layout so that I can run multiple
    versions of Apache httpd at the same time.  I've put Apache and
    httpd into the name in case I have to install other Apache
    software or other httpd products in /opt at a later date.

    Replace every occurrence of "apache-httpd-2_0_36" in the layout
    you added with a unique instance name of your choice.  I usually
    append a hyphen and an instance name,
    e.g. "apache-httpd-2_0_36-test", or "apache-httpd-2_0_36-dev".

2.  Run the configure script to configure the build process.  Specify
    --enable-layout=LinuxFHSFullName as an argument along with any
    other options you need.  The configure script usually produces a
    few screens full of output.  In my case I use something like this:

    $ ./configure --enable-layout=LinuxFHSFullName \
      --enable-modules="rewrite auth-dbm so ssl"

    Don't assume my configure arguments are right for you.  Read the
    documentation in the "INSTALL" file if you want to know more.

3.  Build the software

    $ make >make.log 2>&1

    This takes a while to finish, but when it does, check "make.log"
    for any obvious errors.

4.  If you're not already doing this as root, now you'll need to
    become superuser to install, configure and start the freshly built
    software.  As root, make sure you're in the top level directory
    where you built the software and type:

    # make install >make-install.log 2>&1

    Then check the "make-install.log" file for any obvious errors.

5.  There's a bug in the Apache install procedure which means the
    "runtimedir" in your "config.layout" entry is not created.  You
    need to create the directory manually (usually as the superuser).
    Make sure you use exactly the same directory name as you have in
    "config.layout" or httpd won't start.  You should also check that
    the owner and permissions on the directory you create are
    appropriate.  (I've already reported the bug)

6.  Edit the configuration file for the new instance.  If you're
    running multiple Apache instances you'll probably need to have
    them listen on different ports or interfaces, etc.  As a starting
    point check the "ServerName" and "Listen" directives.  Refer to
    the Apache documentation in the "docs/manual" directory for more
    details.  My quick fix approach is to just use a different port
    for each instance, but that probably isn't suitable for globally
    visible servers.

7.  Start your new instance using the "apachectl" script in the
    "sbindir" from your "config.layout" entry.  For the sample layout
    above you'd type:

    # /opt/apache-httpd-2_0_36/sbin/apachectl start

    Common mistake: "apachectl" is in the "sbin" directory rather than
    the "bin" directory.  Doh!

8.  Check the "error_log" file in the "logfiledir" from your
    "config.layout" entry for any errors.  Remember to use the
    instance name you chose.

9.  You can stop being the superuser now.  Check that httpd is working
    by pointing a web browser at the index page at the top of your
    document root.  Before doing this you might want to make a change
    to the page to make sure you are actually using a separate httpd
    instance.  I usually go to the "htdocsdir" I specified in the
    "config.layout" and edit "index.html.en", inserting an extra
    paragraph at the end with the instance name in it.

    Remember to use a suitable URL for the port (or any other changes)
    you specified when you edited the "httpd.conf" file for this
    instance.  For example if you specified "Listen 8080" you need a
    URL like "http://yourhostname:8080/".

10. To install another instance of Apache httpd,

    $ make distclean

    in the top level directory (where "config.layout" resides").
    Without this your next install will simply use the previous
    layout you specified.

    Now edit the "config.layout" file entry you added in step 1 and
    substitute a new instance name for the old one.  Be very careful
    to change *all* of the instance names or you'll clobber your
    previous installation when you install the new one.

    As an alternative you may choose to keep a separate layout entry
    for each instance you create.  In that case you'll need a unique
    name for each <Layout> and you'll need to specify the correct name
    for the --enable-layout option when you run the configure script
    in step 2.

    Follow steps 2-9 above for the new instance.

  Finished!  I've glossed over a few configuration details, but the
people that need that kind of information aren't likely to be trying
this anyhow.  Failing that, the manual is in the "docs/manual"
directory.

  If you've got any comments or suggestions, please post them to the
mailing list rather than to me so everyone can share the knowledge.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-182050-1-1.html 上篇帖子: Linux软件安装之RPM(转) 下篇帖子: 运用rsync进行linux数据同步
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表