码迷,mamicode.com
首页 > Web开发 > 详细

FreeBSD10.2安装apache22

时间:2016-02-10 18:48:28      阅读:448      评论:0      收藏:0      [点我收藏+]

标签:freebsd apache 安装

mkdir -p /usr/local/apache22

./confingure  --prefix=/usr/local/apache22

make

make install


root@fb10:/var/tmp/httpd-2.2.31 # /usr/local/apache22/bin/apachectl -k start
httpd: Could not reliably (可靠的) determine(决定 ) the server‘s fully (充分)qualified(合格) domain name, using 218.205.57.154 for ServerName
[Wed Feb 10 22:36:37 2016] [warn] (2)No such file or directory: Failed to enable the ‘httpready‘ Accept Filter
[Wed Feb 10 22:36:37 2016] [warn] (2)No such file or directory: Failed to enable the ‘httpready‘ Accept Filter


[Wed Sep 17 22:01:58 2008] [warn] (2)No such file or directory: Failed to enable the ‘httpready‘ Accept Filter

How do I fix this error?

技术分享

A. FreeBSD has special driver called accf_http. It will buffer incoming connections until a certain complete HTTP requests arrive to speed up and optimize performance.

The utility of accf_http is such that a server will not have to context switch several times before performing the initial parsing of the request.  This effectively reduces the amount of required CPU utilization  to handle incoming requests by keeping active processes in preforking servers such as Apache low and reducing the size of the file descriptor set that needs to be managed by interfaces such as select(), poll() or kevent() based servers.

Just open shell prompt and type the following command to load accf_http under FreeBSD :
# kldload accf_http
Restart apache:
# /usr/local/etc/rc.d/apache22 restart

Update /boot/loader.conf file

Type the following command so that driver get loaded at the time of booting system:
# echo ‘accf_http_load="YES"‘ >> /boot/loader.conf


vi /usr/local/apache22/conf/httpd.conf

修改 ServerName 192.168.17.135:80



30.7.1. 纵览

FreeBSD 被用于运行许多全球最为繁忙的 web 站点。        大多数 Internet 上的 web 服务器,        都使用 Apache HTTP 服务器。        Apache 软件包可以在您的 FreeBSD        安装盘上找到。 如果没有在首次安装时附带安装        Apache, 则可以通过 www/apache13www/apache22 port 来安装。

一旦成功地安装了 Apache,        就必须对其进行配置。

注意:

这一节介绍了 1.3.X 版本的        Apache HTTP 服务器 的配置,        因为它是随 FreeBSD 一同使用的最多的版本。        Apache 2.X 引入了很多新技术,        但在此并不讨论。 要了解关于 Apache 2.X        的更多资料, 请参见 http://httpd.apache.org/

30.7.2. 配置

主要的 Apache HTTP Server 配置文件, 在 FreeBSD 上会安装为 /usr/local/etc/apache/httpd.conf。 这是一个典型的 UNIX 文本配置文件, 它使用 # 作为注释符。 关于全部配置选项的详尽介绍超出了本书的范围, 这里将只介绍最常被修改的那些。

  • ServerRoot "/usr/local"

  • 这指定了 Apache    安装的顶级目录。 执行文件被放到服务器根目录 (server root) 的    bin 和    sbin 子目录中,    而配置文件则位于    etc/apache

  • ServerAdmin you@your.address

  • 这个地址是在服务器发生问题时应发送电子邮件的地址,      它会出现在服务器生成的页面上, 例如错误页面。

  • ServerName www.example.com

  • ServerName 允许您配置发送回客户端的主机名,      如果您的服务器被用户以别的名字访问 (例如, 使用 www      而不是主机本身的真实名字)。

  • DocumentRoot "/usr/local/www/data" 或者是 /usr/local/apache22/htdocs

  • DocumentRoot: 这个目录是您的文档所在的目录。      默认情况下, 所有的请求都会从这个位置去获取,      但也可以通过符号连接和别名指定其它的位置。

在修改配置之前备份 Apache 的配置文件永远是一个好习惯。 一旦对初始配置满意了, 就可以开始运行 Apache 了。

30.7.3. 运行 Apache

与许多其它网络服务不同, Apache 并不依赖        inetd 超级服务器来运行。        一般情况下会把它配置为一个独立的服务器, 以期在客户的 web        浏览器连入 HTTP 请求时, 能够获得更好的性能。 它提供了一个 shell        脚本来使启动、 停止和重新启动服务器变得尽可能地简单。        首次启动 Apache,        只需执行:

# /usr/local/sbin/apachectl start

可以在任何时候使用下面的命令来停止服务:

# /usr/local/sbin/apachectl stop

当由于某种原因修改了配置文件之后, 需要重启服务器:

# /usr/local/sbin/apachectl restart

要在重启 Apache 服务器时不中断当前的连接, 则应运行:

# /usr/local/sbin/apachectl graceful

更多的信息, 可以在 apachectl(8) 联机手册中找到。

要在系统启动时启动 Apache, 则应在        /etc/rc.conf 中加入:

apache_enable="YES"

或者对于Apache 2.2:

apache22_enable="YES"

如果您希望在系统引导时启动 Apache httpd 程序并指定其它一些选项, 则可以把下面的行加到 rc.conf

apache_flags=""

现在 web 服务器就开始运行了, 您可以使用 web 浏览器打开        http://localhost/。 默认显示的 web 页面是        /usr/local/www/data/index.html

30.7.4. 虚拟主机

Apache 支持两种不同类型的虚拟主机。 第一种方法是基于名字的虚拟主机。 基于名字的虚拟主机使用客户机发来的 HTTP/1.1 头来辨别主机名。 这使得不同的域得以共享同一个 IP 地址。

要配置 Apache 来使用基于名字的虚拟主机,        需要把类似下面的项加到您的 httpd.conf 中:

NameVirtualHost *

如果您的 web 服务器的名字是 www.domain.tld,        而您希望建立一个        www.someotherdomain.tld 的虚拟域,        则应在        httpd.conf 中加入:

<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain.tld
</VirtualHost>

<VirtualHost *>
ServerName www.someotherdomain.tld
DocumentRoot /www/someotherdomain.tld
</VirtualHost>

您需要把上面的地址和文档路径改为所使用的那些。

要了解关于虚拟主机的更多信息,        请参考官方的 Apache 文档, 这些文档可以在 http://httpd.apache.org/docs/vhosts/ 找到。

30.7.5. Apache 模块

有许多不同的 Apache 模块,        它们可以在基本的服务器基础上提供许多附加的功能。 FreeBSD 的        Ports Collection 为安装        Apache        和常用的附加模块提供了非常方便的方法。

30.7.5.1. mod_ssl

mod_ssl 这个模块使用 OpenSSL 库,          来提供通过 安全套接字层 (SSL v2/v3) 和 传输层安全 (TLS v1)          协议的强加密能力。          这个模块提供了从某一受信的证书签署机构申请签名证书所需的所有工具,          您可以藉此在 FreeBSD 上运行安全的 web 服务器。

如果您未曾安装  Apache, 也可以直接安装一份包含了  mod_ssl 的版本的  Apache  1.3.X, 其方法是通过 www/apache13-modssl port 来进行。 SSL  支持已经作为 Apache 2.X 的一部分提供,  您可以通过  www/apache22 port 来安装后者。

30.7.5.2. 语言绑定

Apache对于一些主要的脚本语言都有相应的模块。  这些模块使得完全使用某种脚本语言来写  Apache 模块成为可能。  他们通常也被嵌入到服务器作为一个常驻内存的解释器,  以避免启动一个外部解释器对于下一节将描述的动态网站所需时间和资源上的开销。

30.7.6. 动态网站

在过去的十年里,越来越多的企业为了增加收益和暴光率而转向了互联网。 这也同时增进了对于互动网页内容的需求。有些公司,比如 Microsoft 推出了基于他们专有产品的解决方案,开源社区也做出了积极的回应。 比较时尚的选择包括 Django,Ruby on Rails,        mod_perl, and        mod_php.

30.7.6.1. Django

Django 是一个以 BSD 许可证发布的 framework,  能让开发者快速写出高性能高品质的 web 应用程序。  它提供给一个对象关系映射组件,数据类型可以被当 Python  中的对象,和一组丰富的动态数据库访问 API,  使开发者避免了写 SQL 语句。它同时还提供了可扩展的模板系统,  让应用程序的逻辑部分与 HTML 的表现层分离。

Django 依赖与 mod_python,  Apache, 和一个可选的 SQL  数据库引擎。 在设置了一些恰当的标志后,FreeBSD 的 Port  系统将会帮助你安装这些必需的依赖库。

例 30.3. 安装 Django,Apache2, mod_python3,和 PostgreSQL

# cd /usr/ports/www/py-django; make all install clean -DWITH_MOD_PYTHON3 -DWITH_POSTGRESQL


在安装了 Django 和那些依赖的软件之后,  你需要创建一个 Django 项目的目录,然后配置  Apache,当有对于你网站上应用程序的某些指定的 URL  时调用内嵌的 Python 解释器。

例 30.4. Django/mod_python 有关 Apache 部分的配置

你需要在 Apache 的配置文件    httpd.conf 加入以下这几行,    把对某些 URL 的请求传给你的 web 应用程序:

<Location "/">
    SetHandler python-program
    PythonPath "[‘/dir/to/your/django/packages/‘] + sys.path"
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonAutoReload On
    PythonDebug On
</Location>


30.7.6.2. Ruby on Rails

Ruby on Rails 是另外一个开源的 web framework,  提供了一个全面的开发框架,能帮助 web  开发者工作更有成效和快速写出强大的应用。  它能非常容易的从 posts 系统安装。

# cd /usr/ports/www/rubygem-rails; make all install clean

30.7.6.3. mod_perl

Apache/Perl 集成计划, 将 Perl  程序设计语言的强大功能, 与 Apache  HTTP 服务器 紧密地结合到了一起。  通过 mod_perl 模块,  可以完全使用 Perl 来撰写 Apache 模块。  此外, 服务器中嵌入的持久性解释器, 消除了由于启动外部的解释器为 Perl  脚本的启动所造成的性能损失。

mod_perl 通过多种方式提供。            要使用 mod_perl,            应该注意 mod_perl 1.0            只能配合 Apache 1.3 而            mod_perl 2.0 只能配合            Apache 2.X 使用。            mod_perl 1.0 可以通过            www/mod_perl 安装,            而以静态方式联编的版本, 则可以通过            www/apache13-modperl            来安装。            mod_perl 2.0 则可以通过            www/mod_perl2 安装。

30.7.6.4. mod_php

Written by Tom Rhodes.

PHP, 也称为 PHP:          Hypertext Preprocessor,          是一种特别适合于 Web 开发的通用脚本语言。  它能够很容易地嵌入到HTML之中,  其语法接近于  C、 Java, 以及 Perl, 以期让 web  开发人员的一迅速撰写动态生成的页面。

要获得用于  Apache web 服务器的  PHP5 支持, 可以从安装  lang/php5  port 开始。

在首次安装 lang/php5 port  的时候, 系统会自动显示可用的一系列  OPTIONS (配置选项)。 如果您没有看到菜单,  例如由于过去曾经安装过 lang/php5 port 等等,  可以用下面的命令再次显示配置菜单, 在 port 的目录中执行:

# make config

在配置选项对话框中, 选中  APACHE 这一项, 就可以联编出用于与  Apache web 服务器配合使用的可动态加载的  mod_php5 模块了。

注意:

由于各式各样的原因 (例如, 出于已经部署的 web 应用的兼容性考虑),    许多网站仍在使用PHP4。 如果您需要    mod_php4 而不是    mod_php5, 请使用    lang/php4 port。    lang/php4 port 也支持许多    lang/php5 port 提供的配置和编译时选项。

前面我们已经成功地安装并配置了用于支持动态PHP应用所需的模块。          请检查并确认您已将下述配置加入到了  /usr/local/etc/apache/httpd.conf 中:

LoadModule php5_module        libexec/apache/libphp5.so
AddModule mod_php5.c
    <IfModule mod_php5.c>
        DirectoryIndex index.php index.html
    </IfModule>
    <IfModule mod_php5.c>
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
    </IfModule>

这些工作完成之后, 还需要使用            apachectl 命令来完成一次 graceful            restart 以便加载PHP模块:

# apachectl graceful

在未来您升级PHP时,  make config 这步操作就不再是必需的了;  您所选择的 OPTIONS 会由 FreeBSD  的 Ports 框架自动保存。

在 FreeBSD 中的PHP支持是高度模块化的,            因此基本安装的功能十分有限。 增加其他功能的支持非常简单, 只需通过            lang/php5-extensions port            即可完成。 这个 port 提供了一个菜单驱动的界面来帮助完成PHP扩展的安装。 另外, 也可以通过对应的 port            来单独安装扩展。

例如, 要将对于  MySQL 数据库服务器的支持加入  PHP5, 只需简单地安装          databases/php5-mysql

安装完扩展之后, 必须重新启动            Apache 服务器,              来令其适应新的配置变更:

# apachectl graceful


PHP 安装

root@fb10:/usr/ports/lang/php5 # make install
===>  Installing for php5-5.4.43
===>   php5-5.4.43 depends on shared library: libpcre.so - found (/usr/local/lib/libpcre.so)
===>   php5-5.4.43 depends on shared library: libxml2.so - found (/usr/local/lib/libxml2.so)
===>  Checking if php5 already installed
===>   Registering installation for php5-5.4.43
Installing php5-5.4.43...
===> SECURITY REPORT:
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
/usr/local/bin/php
/usr/local/bin/php-cgi
/usr/local/sbin/php-fpm

      This port has installed the following startup scripts which may cause
      these network services to be started at boot time.
/usr/local/etc/rc.d/php-fpm

      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type ‘make deinstall‘
      to deinstall the port if this is a concern.

      For more information, and contact details about the security
      status of this software, see the following webpage:
http://www.php.net/
root@fb10:/usr/ports/lang/php5 #

FreeBSD10.2安装apache22

标签:freebsd apache 安装

原文地址:http://11193986.blog.51cto.com/11183986/1741470

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!