環境 Centos-7.x86_64下。 apache 2.4.10, php 5.4.39。php
話說今天是頭一回這linux下安裝apache, 而且我一心要使用fast-cgi而不是module方式。 儘管沒配過fast cgi比較折騰,我仍然沒有放棄。谷百必用盡,寫完這篇文章,但願對看的人有所幫助。html
百度不行的一大證據不是它廣告多,而是左翻右翻一片抄,要麼陳舊。切入正題linux
【必要組件】, 編譯時可能提示:nginx
checking for APR... no
configure: error: APR not found. Please read the documentation.
checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
這兩個我用yum安裝後,仍然會提示找不到。 建議手動下載安裝aprapache
# wget -c http://www.eu.apache.org/dist//apr/apr-1.5.1.tar.gz
# tar -zxvf apr-1.5.1.tar.gz
# cd apr-1.5.1
# ./configure --prefix=/usr/lib/apr
# make && make install
apr-util:vim
# wget -c http://www.eu.apache.org/dist//apr/apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/lib/apr-util --with-apr=/usr/lib/apr
# make && make install
特別說明:apr-util若是安裝錯了刪除掉安裝目錄重裝的話,可能出現如下錯誤,只需在解壓目錄 make clean 一下再繼續 app
libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending in /usr/***ide
【安裝apache】 :svn
# ./configure --prefix=/usr/local/apache --enable-mods-shared=most --enable-mods-shared=all --enable-modules=so --enable-proxy=shared --enable-proxy_connect=shared --enable-headers=shared --with-apr=/usr/lib/apr --with-apr-util=/usr/lib/apr-util
# make && make install
個人PCRE爲shared。php-fpm
【安裝FastCGI模塊】
這個 mod_fcgid.so 並不是內建module, 須要 下載 並安裝。 附說明
# cd mod_fcgid-2.3.9 # APXS=/usr/local/apache/bin/apxs ./configure.apxs # make && make install
安裝完畢 apache/modules/mod_fcgid.so 有了。
【開機啓動】:
# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache // 此時直接chkconfig 加入會提示不支持
# vim /etc/init.d/apache
// 在 #!/bin/sh 下增長如下兩註釋行
# chkconfig: 2345 85 15
# description: Apache
# chkconfig --level 2345 apache on
# ldconfig
# chkconfig --list // 重載config就能看到了
配置apache
apache 2.4.x 的變化主要爲
* NameVirtualHost 已無效
* VirtualHost配置時, 使用 require xxx 代替原先的 allow / deny
而本處,配置爲支持php的fastcgi模式。
修改 apache/conf, 更改 :
user www group www
<IfModule dir_module> DirectoryIndex index.html index.php default.php index.shtm index.asp </IfModule>
# 在 <IfModule mime_module> 內加入(這步多是多餘的,未證明) AddType application/x-httpd-php .php AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps
去掉註釋:(用 /etc/init.d/apache -t 測試語法可能有報錯,和是否加載相應module有關,具體略過)
Include conf/extra/httpd-mpm.conf Include conf/extra/httpd-vhosts.conf Include conf/extra/httpd-dav.conf Include conf/extra/httpd-info.conf
我載入的 module 參考了 xampp, 實際上仍有多餘的能夠去掉
LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_core_module modules/mod_authn_core.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule authz_core_module modules/mod_authz_core.so LoadModule access_compat_module modules/mod_access_compat.so LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule file_cache_module modules/mod_file_cache.so LoadModule cache_module modules/mod_cache.so LoadModule watchdog_module modules/mod_watchdog.so LoadModule reqtimeout_module modules/mod_reqtimeout.so LoadModule include_module modules/mod_include.so LoadModule filter_module modules/mod_filter.so LoadModule deflate_module modules/mod_deflate.so LoadModule mime_module modules/mod_mime.so LoadModule log_config_module modules/mod_log_config.so LoadModule env_module modules/mod_env.so LoadModule headers_module modules/mod_headers.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule version_module modules/mod_version.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule ssl_module modules/mod_ssl.so LoadModule unixd_module modules/mod_unixd.so LoadModule status_module modules/mod_status.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule asis_module modules/mod_asis.so LoadModule info_module modules/mod_info.so LoadModule dir_module modules/mod_dir.so LoadModule actions_module modules/mod_actions.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so
# 加入
LoadModule fcgid_module modules/mod_fcgid.so
增長: (這個我使用8080端口暫未測試成功)
<IfModule mod_fastcgi.c> DirectoryIndex index.php index.html index.shtml default.php AddHandler php-fcgi .php Action php-fcgi /usr/local/php/sbin/php-fpm Alias /php-fcgi /usr/local/php/sbin/php-fpm FastCgiExternalServer /usr/local/php/sbin/php-fpm -host 127.0.0.1:9000 -pass-header Authorization -idle-timeout 300 <Directory /usr/local/php/sbin> Options +ExecCGI +FollowSymLinks AllowOverride All Require all granted </Directory> </IfModule>
配置 VirtualHost:
php-fpm部分見apache官方文檔:http://wiki.apache.org/httpd/PHP-FPM
<VirtualHost *:80> ServerName affiliate-program.xxx.com DocumentRoot /var/wwwroot/program/affiliate-program.xxx.com ErrorLog /var/log/apache/xxx_affilate_err.log <Directory /var/wwwroot/program/affiliate-program.xxx.com> Options +FollowSymLinks +Includes -Indexes DirectoryIndex index.html index.htm default.htm index.php default.php AllowOverride All Require all granted </Directory> </VirtualHost>
# /etc/init.d/apache -t 測試
要運行php+fastcgi, 配置apache比nginx真是麻煩得多!!