29.4. 编译和优化

像我们安装的许多应用程序一样,Apache Web 服务器不能以 超级用户 root 身份运行。因此,我们必须创建一个特殊用户,该用户对系统的访问权限最小,但仍能充分运行 Apache Web 服务器。最好选择并创建一个新用户,专门用于运行 Web 服务器守护进程。

  1.           [root@deep ]/# useradd -c "Apache Server" -u 80 -s /bin/false -r -d /home/httpd www 2>/dev/null || :
            

  2. 如果要使用并在 Apache Web 服务器中包含 SSL 数据加密支持,则必须将 mod-ssl 应用于 Apache 源代码树,然后移动到新的 mod_ssl 源代码目录 cdmod_ssl-version-version/并在终端上键入以下命令
              CC="egcs" \
              CFLAGS="-O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions" \
              ./configure \
              --with-apache=../apache_1.3.12 \
              --with-crt=/etc/ssl/certs/server.crt \
              --with-key=/etc/ssl/private/server.key
            

    • 以下--with-apache选项指定 Apache 源代码目录的位置,重要的是要注意,在本示例中,我们假设您的 Apache 版本为 1.3.12,

    • 以下--with-crt选项指定 SSL 加密的现有公钥的位置

    • 以下--with-key选项指定 SSL 加密的现有私钥的位置。

    Important: OpenSSL 软件必须已安装在您的服务器上,并且您的公钥和私钥必须已存在或在您的服务器上创建,否则您将在 mod_ssl 的配置期间收到错误消息。有关更多信息,请参阅本书中的 软件 - 网络/加密

  3. 改进 Apache 的 MaxClients 参数,默认情况下在 Apache 配置文件中;httpd.conf,您可以为 MaxClients 参数设置的最大数量为 256。对于繁忙的站点,为了获得更好的性能,建议您增加此参数的限制。您可以通过编辑src/include/httpd.hApache 源代码目录中的文件并更改默认值。移动到新的 Apache 源代码目录,cd../apache_1.3.12/并编辑httpd.h文件
              #define HARD_SERVER_LIMIT 256
            
    要读取
              #define HARD_SERVER_LIMIT 1024
            

  4. 如果要使用并在 Apache Web 服务器中包含 PHP4 服务器端脚本语言支持,请为 PHP4 配置步骤预配置 Apache,然后移动到新的 Apache 源代码目录 cdapache_1.3.12/如果您尚未在其中,请在终端上键入以下命令
              CC="egcs" \
              OPTIM="-O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions" \
              CFLAGS="-DDYNAMIC_MODULE_LIMIT=0" \
              ./configure \
              --prefix=/home/httpd \
              --bindir=/usr/bin \
              --sbindir=/usr/sbin \
              --libexecdir=/usr/lib/apache \
              --includedir=/usr/include/apache \
              --sysconfdir=/etc/httpd/conf \
              --localstatedir=/var \
              --runtimedir=/var/run \
              --logfiledir=/var/log/httpd \
              --datadir=/home/httpd \
              --proxycachedir=/var/cache/httpd \
              --mandir=/usr/man
            

Tip: 只有当您想在 Apache 源代码中包含 PHP4 支持时,此步骤才是必要的,因为它将为下面的 PHP4 配置步骤预配置 Apache。请注意-DDYNAMIC_MODULE_LIMIT=0选项将禁用在我们编译 Apache 时使用动态加载模块,并提高其性能。