FreeBSD10.2安裝apache22

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?

apachelogo.gif

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 [email protected]

  • 這個地址是在服務器發生問題時應發送電子郵件的地址,      它會出現在服務器生成的頁面上, 例如錯誤頁面。

  • 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 #

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章