天天看點

LAMP編譯實作

一、簡述LAMP:

二、HTTP2.4編譯安裝

三、源碼安裝MySQL5.6

四、源碼安裝php-5.6

五、配置http通路PHP

六、配置php通路mysql

實驗環境為:

    php-fpm和msyql編譯為同一台主機(CentOS6.9)

    httpd單獨一台主機(CentOS6.9)

client http(請求index.php或者index.html)

    --->apache(httpd web伺服器響應,如果是靜态檔案,則直接響應,如果是動态請求則轉向下一步) 

        --->php 接受請求(php解釋器通過fastcgi響應,如果需要查詢資料則轉向一下) 

            --->透過mysql用戶端查詢資料庫(mysql驅動)  

                --->mysql伺服器響應資料庫查詢(傳回查詢結果)

LAMP:其中apache、http、php都可以分别安裝到不同機器上

http與php結合的方式:

    module

    fcgi

    php-fpm

httpd依賴于反向代理子產品以及專用于fastcgi反向代理子產品

    httpd-2.2預設沒有附帶專用fastcgi反向代理子產品,是以需要獨立安裝;

    httpd-2.4已自帶fastcgi反向子產品,此子產品為mod_proxy_fcgi.so,它其實是作為mod_proxy.so子產品的擴充       

    httpd-2.4以前的版本中,要麼把PHP作為Apache的子產品運作,要麼添加一個第三方子產品支援PHP-FPM實作。 

由于php有相關依賴性是以建議:

    安裝次序為httpd或mysql,再裝php。

實驗環境:CenOS6.9 kernel-2.6

源碼編譯步驟:

    配置(configure),通常依賴gcc編譯器,binutils,glibc。配置軟體特性,檢查編譯環境,生成 Makefile檔案

    編譯(make)

    安裝(make install)

--prefix配置安裝路徑,如果不配置該選項,安裝後可執行檔案預設放在/usr/local/bin,

    庫檔案預設放在/usr/local/lib,配置檔案預設放在/usr/local/etc,其它的資源檔案放在/usr /local/share

    如果配置--prefix,如: ./configure --prefix=/usr/local/test

    用了—prefix選項的另一個好處是解除安裝軟體或移植軟體。

    當某個安裝的軟體不再需要時,隻須簡單的删除該安裝目錄,就可以把軟體解除安裝得幹幹淨淨;

    移植軟體隻需拷貝整個目錄到另外一個機器即可(相同的作業系統)。

    解除安裝程式,也可以在原來的make目錄下用一次make uninstall,但前提是make檔案指定過uninstall。

1.依賴關系解決

依賴到的:apr、apr-util、pcre-devel、openssl-devel

http://archive.apache.org/dist/apr/  下載下傳apr-1.5.0.tar.gz  apr-util-1.5.1.tar.gz  

httpd-2.4 依賴于1.4+及以上版本的apr

yum install pcre-devel openssl-devel gcc //這兩個依賴手動安裝

編譯步驟:

tar xvf apr-1.5.0.tar.gz

cd apr-1.5.0

./config --prefix=/usr/local/apr

make && make install 

tar xvf apr-util-1.5.1.tar.gz

cd apr-util-1.5.1

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

//編譯出問題。make clean清理重新編譯

2.編譯http2.4

tar xvf httpd-2.4.29.tar.gz

cd httpd-2.4.29

<code>.</code><code>/configure</code> <code>--with-apr=</code><code>/usr/local/apr</code> <code>--with-apr-util=</code><code>/usr/local/apr-util/</code> <code>--prefix=</code><code>/usr/local/http24</code> <code>--sysconfdir=</code><code>/etc/http24/</code> <code>--</code><code>enable</code><code>-so --</code><code>enable</code><code>-ssl --</code><code>enable</code><code>-rewrite --</code><code>enable</code><code>-zlib --</code><code>enable</code><code>-cgi --with-pcre --with-mpm=prefork --</code><code>enable</code><code>-modules=most --</code><code>enable</code><code>-mpms-shared=all</code>

    --sysconfdir=/etc/httpd24  指定配置檔案路徑

    --enable-so  啟動子產品動态裝解除安裝

    --enable-ssl 編譯ssl子產品

    --enable-cgi 支援cgi機制(能夠讓靜态web伺服器能夠解析動态請求的一個協定)

    --enable-rewrite  支援url重寫     --Author : Leshami

    --with-zlib  支援資料包壓縮       --Blog   : http://blog.csdn.net/leshami

    --with-pcre  支援正規表達式

    --with-apr=/usr/local/apr  指明依賴的apr所在目錄

    --with-apr-util=/usr/local/apr-util/  指明依賴的apr-util所在的目錄

    --enable-modules=most      啟用的子產品

    --enable-mpms-shared=all   以共享方式編譯的子產品

    --with-mpm=prefork         指明httpd的工作方式為prefork

執行make的是否發現錯誤:

<code>exports.c:1250: note: previous definition of </code><code>'ap_hack_apr_xml_insert_uri'</code> <code>was here</code>

<code>exports.c:1675: error: redefinition of </code><code>'ap_hack_apu_version'</code>

<code>exports.c:1259: note: previous definition of </code><code>'ap_hack_apu_version'</code> <code>was here</code>

<code>exports.c:1676: error: redefinition of </code><code>'ap_hack_apu_version_string'</code>

<code>exports.c:1260: note: previous definition of </code><code>'ap_hack_apu_version_string'</code> <code>was here</code>

<code>........</code>

[root@localhost httpd-2.4.29]# cat /tmp/http.bianyi |grep -v note  //http.bianyi是所有編譯提示"previos definition"的

[root@localhost httpd-2.4.29]# a=$(cat /tmp/http.bianyi |grep -v note  |sort -nr -k2 |cut -d':' -f2 )

[root@localhost httpd-2.4.29]# for i in $a; do sed -i "${i}d" ./server/exports.c ;done  //sed替換變量的時候用"${}"

[root@localhost httpd-2.4.29]# cat ./server/exports.c  |grep ap_hack_apu_version_string

const void *ap_hack_apu_version_string = (const void *)apu_version_string;

//發現重複定義了,注釋或者删除其中一個。

make clean &amp;&amp; make install 

3.後續步驟:

vim /etc/man.config  //配置man手冊

MANPATH /usr/local/httpd24/man

[root@localhost httpd-2.4.29]# echo "export PATH=$PATH:/usr/local/http24/bin" &gt; /etc/profile.d/httpd24.sh //指令手冊

[root@localhost httpd-2.4.29]# source /etc/profile

[root@localhost http24]# cd /usr/local/http24/

注:啟動檔案pid檔案位置要配置成與/usr/local/apache/bin/apachectl -V看到的pid位置一緻

[root@localhost http24]# ./bin/apachectl -V

<code>Server version: Apache</code><code>/2</code><code>.4.29 (Unix)</code>

<code>Server built:   Feb  4 2018 03:14:13</code>

<code>Server's Module Magic Number: 20120211:68</code>

<code>Server loaded:  APR 1.5.0, APR-UTIL 1.5.1</code>

<code>Compiled using: APR 1.5.0, APR-UTIL 1.5.1</code>

<code>Architecture:   64-bit</code>

<code>Server MPM:     prefork</code>

<code>  </code><code>threaded:     no</code>

<code>    </code><code>forked:     </code><code>yes</code> <code>(variable process count)</code>

<code>Server compiled with....</code>

<code> </code><code>-D APR_HAS_SENDFILE</code>

<code> </code><code>-D APR_HAS_MMAP</code>

<code> </code><code>-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)</code>

<code> </code><code>-D APR_USE_SYSVSEM_SERIALIZE</code>

<code> </code><code>-D APR_USE_PTHREAD_SERIALIZE</code>

<code> </code><code>-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT</code>

<code> </code><code>-D APR_HAS_OTHER_CHILD</code>

<code> </code><code>-D AP_HAVE_RELIABLE_PIPED_LOGS</code>

<code> </code><code>-D DYNAMIC_MODULE_LIMIT=256</code>

<code> </code><code>-D HTTPD_ROOT=</code><code>"/usr/local/http24"</code>

<code> </code><code>-D SUEXEC_BIN=</code><code>"/usr/local/http24/bin/suexec"</code>

<code> </code><code>-D DEFAULT_PIDLOG=</code><code>"logs/httpd.pid"</code>

<code> </code><code>-D DEFAULT_SCOREBOARD=</code><code>"logs/apache_runtime_status"</code>

<code> </code><code>-D DEFAULT_ERRORLOG=</code><code>"logs/error_log"</code>

<code> </code><code>-D AP_TYPES_CONFIG_FILE=</code><code>"/etc/http24//mime.types"</code>

<code> </code><code>-D SERVER_CONFIG_FILE=</code><code>"/etc/http24//httpd.conf"</code>

[root@localhost http24]# ./bin/apachectl -V |grep -i pid

 -D DEFAULT_PIDLOG="logs/httpd.pid"

啟動腳本:/etc/init.d/httpd24 

<code>[root@localhost init.d]</code><code># cat /etc/init.d/httpd |grep -v "^#"</code>

<code>. </code><code>/etc/rc</code><code>.d</code><code>/init</code><code>.d</code><code>/functions</code>

<code>if</code> <code>[ -f </code><code>/etc/http24</code> <code>]; </code><code>then</code>

<code>        </code><code>. </code><code>/etc/http24</code>

<code>fi</code>

<code>HTTPD_LANG=${HTTPD_LANG-</code><code>"C"</code><code>}</code>

<code>INITLOG_ARGS=</code><code>""</code>

<code>apachectl=</code><code>/usr/local/http24/bin/apachectl</code>

<code>httpd=${HTTPD-</code><code>/usr/local/http24/bin/httpd</code><code>}</code>

<code>prog=httpd</code>

<code>pidfile=${PIDFILE-</code><code>/usr/local/http24/logs/httpd</code><code>.pid}</code>

<code>lockfile=${LOCKFILE-</code><code>/var/lock/subsys/httpd24</code><code>}</code>

<code>RETVAL=0</code>

<code>STOP_TIMEOUT=${STOP_TIMEOUT-10}</code>

<code>start() {</code>

<code>        </code><code>echo</code> <code>-n $</code><code>"Starting $prog: "</code>

<code>        </code><code>LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS</code>

<code>        </code><code>RETVAL=$?</code>

<code>        </code><code>echo</code>

<code>        </code><code>[ $RETVAL = 0 ] &amp;&amp; </code><code>touch</code> <code>${lockfile}</code>

<code>        </code><code>return</code> <code>$RETVAL</code>

<code>}</code>

<code>stop() {</code>

<code>        </code><code>status -p ${pidfile} $httpd &gt; </code><code>/dev/null</code>

<code>        </code><code>if</code> <code>[[ $? = 0 ]]; </code><code>then</code>

<code>                </code><code>echo</code> <code>-n $</code><code>"Stopping $prog: "</code>

<code>                </code><code>killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd</code>

<code>        </code><code>else</code>

<code>                </code><code>success</code>

<code>        </code><code>fi</code>

<code>        </code><code>[ $RETVAL = 0 ] &amp;&amp; </code><code>rm</code> <code>-f ${lockfile} ${pidfile}</code>

<code>reload() {</code>

<code>    </code><code>echo</code> <code>-n $</code><code>"Reloading $prog: "</code>

<code>    </code><code>if</code> <code>! LANG=$HTTPD_LANG $httpd $OPTIONS -t &gt;&amp;</code><code>/dev/null</code><code>; </code><code>then</code>

<code>        </code><code>RETVAL=6</code>

<code>        </code><code>echo</code> <code>$</code><code>"not reloading due to configuration syntax error"</code>

<code>        </code><code>failure $</code><code>"not reloading $httpd due to configuration syntax error"</code>

<code>    </code><code>else</code>

<code>        </code><code># Force LSB behaviour from killproc</code>

<code>        </code><code>LSB=1 killproc -p ${pidfile} $httpd -HUP</code>

<code>        </code><code>if</code> <code>[ $RETVAL -</code><code>eq</code> <code>7 ]; </code><code>then</code>

<code>            </code><code>failure $</code><code>"httpd shutdown"</code>

<code>    </code><code>fi</code>

<code>    </code><code>echo</code>

<code>case</code> <code>"$1"</code> <code>in</code>

<code>  </code><code>start)</code>

<code>        </code><code>start</code>

<code>        </code><code>;;</code>

<code>  </code><code>stop)</code>

<code>        </code><code>stop</code>

<code>  </code><code>status)</code>

<code>        </code><code>status -p ${pidfile} $httpd</code>

<code>  </code><code>restart)</code>

<code>  </code><code>condrestart|try-restart)</code>

<code>        </code><code>if</code> <code>status -p ${pidfile} $httpd &gt;&amp;</code><code>/dev/null</code><code>; </code><code>then</code>

<code>                </code><code>stop</code>

<code>                </code><code>start</code>

<code>  </code><code>force-reload|reload)</code>

<code>        </code><code>reload</code>

<code>  </code><code>graceful|help|configtest|fullstatus)</code>

<code>        </code><code>$apachectl $@</code>

<code>  </code><code>*)</code>

<code>        </code><code>echo</code> <code>$</code><code>"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"</code>

<code>        </code><code>RETVAL=2</code>

<code>esac</code>

<code>exit</code> <code>$RETVAL</code>

[root@localhost init.d]# cat /etc/init.d/httpd |grep -v "^#"

[root@localhost init.d]# chkconfig --add httpd

[root@localhost init.d]# service httpd status

4.測試通路

vim /etc/http24/httpd.conf //尾部追加幾行

<code>&lt;Location </code><code>/server-status</code><code>&gt;</code>

<code>    </code><code>SetHandler server-status</code>

<code>    </code><code>Allow from 192.168.2.0</code>

<code>&lt;</code><code>/Location</code><code>&gt;</code>

[root@localhost http24]# cat ./htdocs/index.html &lt;&lt; EOF

<code>&gt; &lt;html&gt;</code>

<code>&gt;   &lt;body&gt; &lt;h1&gt; It works &lt;</code><code>/h1</code><code>&gt; &lt;</code><code>/body</code><code>&gt;</code>

<code>&gt; &lt;</code><code>/html</code><code>&gt;</code>

<code>&gt; EOF</code>

https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html //參數說明

1.依賴關系

有關MySQL編譯參數

<code>  </code><code>CMAKE_BUILD_TYPE            編譯的版本類型:RelWithDebInfo和Debug,不同之處是RelWithDebInfo會進行優化。</code>

<code>  </code><code>CMAKE_INSTALL_PREFIX        指定</code><code>make</code> <code>install</code><code>安裝的目标路徑。</code>

<code>  </code><code>SYSCONFDIR                  指定配置檔案的預設路徑。</code>

<code>  </code><code>MYSQL_DATADIR               指定data目錄的預設路徑。</code>

<code>  </code><code>WITH_DEBUG                  指定是否有debugging資訊,一般用于源碼調試時,打開WITH_DEBUG,生産環境關閉。</code>

<code>  </code><code>ENABLED_PROFILING           指定是否可以使用show profile顯示操作執行的詳細資訊。</code>

<code>  </code><code>DEFAULT_CHARSET             指定預設字元集,可以在啟動的配置檔案中指定。</code>

<code>  </code><code>DEFAULT_COLLATION           指定預設字元比較、排序的規則。</code>

<code>  </code><code>WITH_EXTRA_CHARSETS         指定其他可能使用的字元集。</code>

<code>  </code><code>WITH_SSL                    指定SSL的類型,從5.6.6開始預設bundled類型,此外也可以指定SSL庫的路徑位址。</code>

<code>  </code><code>WITH_ZLIB                   指定zlib的類型,用于壓縮功能。</code>

<code>  </code><code>ENABLED_LOCAL_INFILE        指定是否允許使用load data infile功能。</code>

<code>  </code><code>WITH_EMBEDDED_SERVER        指定是否編譯libmysqld嵌入式庫。</code>

<code>  </code><code>INSTALL_LAYOUT              指定安裝的布局類型。</code>

<code>  </code><code>WITH_storage_STORAGE_ENGINE 指定編譯支援的存儲引擎,預設支援MyISAM,MERGE,MEMORY,CSV存儲引擎。</code>

詳細參數可參考 http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html    

yum install gcc gcc+c++  cmake bison m4 ncurses-devel perl per-devel bison-devel autoconf -y  //MySQL5.5之後要用cmake編譯

==========================================//源碼安裝和下載下傳方式(可選)

# wget http://www.cmake.org/files/v2.8/cmake-2.8.11.1.tar.gz

# wget http://ftp.gnu.org/gnu/bison/bison-2.7.tar.gz

# wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.gz

========================================================

源碼包下載下傳方法:https://www.mysql.com/-&gt;DOWNLOADS-&gt;Archives-&gt;MySQL Community Server-&gt;Operating System:[Source Code]-&gt;OS Version:[Generic Linux]

https://downloads.mysql.com/archives/get/file/mysql-5.6.12.tar.gz

2.編譯安裝

[root@www mysql-5.6.12]# groupadd mysql

[root@www mysql-5.6.12]# useradd -g mysql mysql

[root@www mysql-5.6.12]# mkdir /usr/local/mysql

[root@www mysql-5.6.12]# chown mysql:mysql /data /usr/local/mysql

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  \

-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=utf8,gbk  \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/ -DSYSCONFDIR=/etc/mysql/ \

-DWITH_SSL=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1

預編譯出錯,删除下面檔案,重新編譯安裝。

#rm -f CMakeCache.txt     

make clean 清空make

make報錯:

初始化操作:

cd /usr/local/mysql

chmod +x scripts/mysql_install_db

scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

cp support-files/mysql.server /etc/init.d/mysqld

chmod +x /usr/init.d/mysqld

chkconfig mysqld on

echo "export PATH=$PATH:/usr/local/mysql/bin" &gt;&gt; /etc/profile

source /etc/profile

[root@localhost mysql]# mysql -uroot

mysql&gt; SET PASSWORD = PASSWORD('mysql5635');

注意:實驗環境是php和mysql一台機器,http獨立一台

1.依賴處理

[root@localhost yum.repos.d]# yum install libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel libxml2 libxml2-devel bzip2-devel libcurl-devel openssl-devel -y

mcrypt擴充庫可以實作加密解密功能,就是既能将明文加密,也可以密文還原。

mhash是基于離散數學原理的不可逆向的php加密方式擴充庫,其在預設情況下不開啟。

mhash的可以用于建立校驗數值,消息摘要,消息認證碼,以及無需原文的關鍵資訊儲存(如密碼)等。

libevent是一個異步事件通知庫檔案,其API提供了在某檔案描述上發生某事件時或其逾時時執行回調函數的機制

    它主要用來替換事件驅動的網絡伺服器上的event loop機制。

    目前來說, libevent支援/dev/poll、kqueue、select、poll、epoll及Solaris的event ports。

bzip2 是一個基于Burrows-Wheeler 變換的無損壓縮軟體能夠高效的完成檔案資料的壓縮

libcurl主要功能就是用不同的協定連接配接和溝通不同的伺服器,也就是相當封裝了的sockPHP,允許你用不同的協定連接配接和溝通不同的伺服器

圖形相關的rpm包 //對應的錯誤提示:JIS-mapped Japanese font support in GD

    # yum install libjpeg-devel libpng-devel freetype-devel

2.編譯安裝    

<code>.</code><code>/configure</code> <code>\ </code>

<code>--prefix=</code><code>/usr/local/php</code> <code>\</code>

<code>--with-config-</code><code>file</code><code>-path=</code><code>/etc/php</code> <code>\</code>

<code>--</code><code>enable</code><code>-inline-optimization \</code>

<code>--disable-debug \</code>

<code>--disable-rpath \</code>

<code>--</code><code>enable</code><code>-shared \</code>

<code>--</code><code>enable</code><code>-opcache \</code>

<code>--</code><code>enable</code><code>-fpm \</code>

<code>--with-mysql=</code><code>/usr/local/mysql</code> <code>\</code>

<code>--with-mysqli=</code><code>/usr/local/mysql/bin/mysql_config</code> <code>\</code>

<code>--with-pdo-mysql=</code><code>/usr/local/mysql</code> <code>\</code>

<code>--with-gettext \</code>

<code>--</code><code>enable</code><code>-mbstring \</code>

<code>--with-iconv \</code>

<code>--with-mcrypt \</code>

<code>--with-mhash \</code>

<code>--with-openssl \</code>

<code>--</code><code>enable</code><code>-bcmath \</code>

<code>--</code><code>enable</code><code>-soap \</code>

<code>--with-libxml-</code><code>dir</code> <code>\</code>

<code>--</code><code>enable</code><code>-pcntl \</code>

<code>--</code><code>enable</code><code>-shmop \</code>

<code>--</code><code>enable</code><code>-sysvmsg \</code>

<code>--</code><code>enable</code><code>-sysvsem \</code>

<code>--</code><code>enable</code><code>-sysvshm \</code>

<code>--</code><code>enable</code><code>-sockets \</code>

<code>--with-curl \</code>

<code>--with-zlib \</code>

<code>--</code><code>enable</code><code>-zip \</code>

<code>--with-bz2 \</code>

<code>--with-gd \</code>

<code>--with-freetype-</code><code>dir</code> <code>\</code>

<code>--with-jpeg-</code><code>dir</code> <code>\</code>

<code>--with-png-</code><code>dir</code>

報錯資訊:checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

[root@wolf php-5.6.33]# echo "/usr/local/mysql/lib" &gt;&gt; /etc/ld.so.conf.d/local.conf    //mysql的庫檔案路徑

注意:

<code>--with-mysql=</code><code>/usr/local/mysql</code> <code>//mysql</code><code>的安裝目錄</code>

<code>--with-mysqli=</code><code>/usr/local/mysql/bin/mysql_config</code> <code>\  </code><code>//mysqli</code><code>擴充技術不僅可以調用MySQL的存儲過程、處理MySQL事務,而且還可以使通路資料庫工作變得更加穩定。</code>

<code>--with-apxs2=</code><code>/usr/local/apache/bin/apxs</code> <code>//</code><code>整合 apache,apxs功能是使用mod_so中的LoadModule指令,加載指定子產品到 apache,要求 apache 要打開SO子產品</code>

<code>--prefix=</code><code>/usr/local/php</code> <code>//</code><code># 指定 php 安裝目錄</code>

<code>--with-config-</code><code>file</code><code>-path=</code><code>/usr/local/php/etc</code> <code>//</code><code># 指定php.ini位置</code>

<code># 選項指令 --with-iconv-dir 用于 PHP 編譯時指定 iconv 在系統裡的路徑,否則會掃描預設路徑。</code>

<code>--with-iconv-</code><code>dir</code><code>=</code><code>/usr/local</code> 

<code>--with-freetype-</code><code>dir</code>   <code>打開對freetype字型庫的支援 </code>

<code>--with-jpeg-</code><code>dir</code>   <code>打開對jpeg圖檔的支援 </code>

<code>--with-png-</code><code>dir</code>   <code>打開對png圖檔的支援 </code>

<code>--with-zlib-</code><code>dir</code>   <code>打開zlib庫的支援,用于http壓縮傳輸</code>

<code>--with-libxml-</code><code>dir</code>   <code>打開libxml2庫的支援</code>

<code>--disable-rpath    關閉額外的運作庫檔案 </code>

<code>--</code><code>enable</code><code>-bcmath    打開圖檔大小調整,用到zabbix監控的時候用到了這個子產品</code>

<code>--</code><code>enable</code><code>-shmop --</code><code>enable</code><code>-sysvsem  這樣就使得你的PHP系統可以處理相關的IPC函數了。</code>

<code>--</code><code>enable</code><code>-inline-optimization  優化線程</code>

<code>--with-curl    打開curl浏覽工具的支援 </code>

<code>--with-curlwrappers    運用curl工具打開url流 </code>

<code>--</code><code>enable</code><code>-mbregex</code>

<code>--</code><code>enable</code><code>-fpm 打上PHP-fpm 更新檔後才有這個參數,CGI方式安裝的啟動程式</code>

<code>--</code><code>enable</code><code>-mbstring    多位元組,字元串的支援 </code>

<code>--with-mcrypt                    mcrypt算法擴充</code>

<code>--with-mhash                     mhash算法擴充</code>

<code>--with-gd    打開gd庫的支援 </code>

<code>--</code><code>enable</code><code>-gd-native-ttf   支援TrueType字元串函數庫</code>

<code>--with-openssl      openssl的支援,加密傳輸https時用到的</code>

<code>--</code><code>enable</code><code>-pcntl   freeTDS需要用到的,可能是連結mssql 才用到</code>

<code>--</code><code>enable</code><code>-sockets     打開 sockets 支援</code>

<code>--with-xmlrpc    打開xml-rpc的c語言 </code>

<code>--</code><code>enable</code><code>-zip   打開對zip的支援 </code>

<code>--</code><code>enable</code><code>-</code><code>ftp</code>   <code>打開</code><code>ftp</code><code>的支援 </code>

<code>--with-bz2    打開對bz2檔案的支援        </code>

<code>--without-iconv   關閉iconv函數,字元集間的轉換 </code>

<code>--with-ttf     打開freetype1.*的支援,可以不加了 </code>

<code>--with-xsl     打開XSLT 檔案支援,擴充了libXML2庫 ,需要libxslt軟體 </code>

<code>--with-gettext     打開gnu 的gettext 支援,編碼庫用到 </code>

<code>--with-pear    打開pear指令的支援,PHP擴充用的 </code>

<code>--</code><code>enable</code><code>-calendar    打開月曆擴充功能</code>

<code>--</code><code>enable</code><code>-exif    圖檔的中繼資料支援 </code>

<code>--</code><code>enable</code><code>-magic-quotes    魔術引用的支援 </code>

<code>--disable-debug    關閉調試模式 </code>

<code>--with-mime-magic=</code><code>/usr/share/file/magic</code><code>.mime      魔術頭檔案位置</code>

<code>CGI方式安裝才用的參數</code>

<code>--</code><code>enable</code><code>-fastCGI            支援fastcgi方式啟動PHP</code>

<code>--</code><code>enable</code><code>-force-CGI-redirect        重定向方式啟動PHP</code>

<code>--with-ncurses         支援ncurses 螢幕繪制以及基于文本終端的圖形互動功能的動态庫</code>

<code>--with-gmp  應該是支援一種規範</code>

<code>--</code><code>enable</code><code>-dbase                     建立DBA 作為共享子產品</code>

<code>--with-pcre-</code><code>dir</code><code>=</code><code>/usr/local/bin/pcre-config</code>      <code>perl的正則庫案安裝位置</code>

<code>--</code><code>enable</code><code>-zend-multibyte         支援zend的多位元組</code>

3.後續處理

[root@wolf php]# echo "export PATH=$PATH:/usr/local/php/bin:/usr/loca/php/sin" &gt; /etc/profile.d/php.sh

[root@wolf php]# source /etc/profile

[root@wolf php-5.6.33]# cp php.ini-production /usr/local/php/etc/php.ini

[root@wolf php-5.6.33]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@wolf php-5.6.33]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@wolf php-5.6.33]# chmod +x /etc/init.d/php-fpm

[root@wolf php-5.6.33]# chkconfig --add php-fpm

[root@wolf php-5.6.33]# vim /etc/man.config //添加MANPATH /usr/local/php/php

[root@wolf php]# chkconfig mysqld on

[root@wolf php]# chkconfig php-fpm on

[root@wolf php]# service php-fpm start

[root@wolf php]# php-fpm -t  //測試文法

4.修改php-fpm監聽位址為非127.0.0.1

修改 /usr/local/php/etc/php-fpm.conf 

listen = 192.168.2.110:9000

原理:

1)、動态子產品方式:

  prefork模式使用libphp5子產品 

   worker和event模式則使用libphp5-zts子產品

2)、CGI方式:

CGI(Common Gateway Interface 簡稱通用網關接口)。

CGI是外部應用程式(CGI程式)與Web伺服器之間的接口标準,是在CGI程式和Web伺服器之間傳遞資訊的過程。

CGI規範允許Web伺服器執行外部程式,并将它們的輸出發送給Web浏覽器,

    CGI将Web的一組簡單的靜态超媒體文檔變成一個完整的新的互動式媒體。

其工作流程如下:

a、浏覽器通過HTML表單或超連結請求指向一個CGI應用程式的URL。

b、伺服器收發到請求。

c、伺服器執行指定CGI應用程式(開啟程序)

d、CGI應用程式執行所需要的操作,通常是基于浏覽者輸入的内容。

e、CGI應用程式把結果格式化為網絡伺服器和浏覽器能夠了解的文檔(通常是HTML網頁)。

f、網絡伺服器把結果傳回到浏覽器中(銷毀程序)

3)、FastCGI方式:

    FastCGI像是一個常駐(long-live)型的CGI,它可以一直執行着,隻要激活後,不會每次都要花費時間去fork一次。

    (這是CGI最為人诟病的fork-and-execute 模式)。

    它還支援分布式的運算, 即 FastCGI 程式可以在網站伺服器以外的主機上執行并且接受來自其它網站伺服器來的請求。

a、Web Server啟動時載入FastCGI程序管理器(IIS ISAPI或Apache Module)

b、FastCGI程序管理器自身初始化,啟動多個CGI解釋器程序(可見多個php-cgi)并等待來自Web Server的連接配接。

c、當用戶端請求到達Web Server時,FastCGI程序管理器選擇并連接配接到一個CGI解釋器。

    Web server将CGI環境變量和标準輸入發送到FastCGI子程序php-cgi。

e、FastCGI子程序完成處理後将标準輸出和錯誤資訊從同一連接配接傳回Web Server。

    當FastCGI子程序關閉連接配接時,請求便告處理完成。

   FastCGI子程序接着等待并處理來自FastCGI程序管理器(運作在Web Server中)的下一個連接配接。

   在CGI模式中,php-cgi在此便退出了。

4)、CGI與FastCGI兩者差異主要在于:

    CGI在處理任何一個請求需要開啟程序,銷毀程序,開銷較大

    FastCGI會在初始化的時候啟動多個cgi程序,監聽來自網絡的請求;

    當處理完畢任務後則由FastCGI程序管理器回收管理,省去反複建立回收的開銷。

1.單台機器上設定

# vim  /etc/httpd24/httpd.conf     ###注意此處,我這裡是單獨編譯安裝的httpd2.4版本,是以路徑有所不同

<code>    </code><code>LoadModule proxy_module  modeles</code><code>/mod_proxy</code><code>.so</code>

<code>    </code><code>LoadModule proxy_fcgi_module modules</code><code>/mod_proxy_fcgi</code><code>.so</code>

<code>    </code><code>AddType  application</code><code>/x-httpd-php</code>  <code>.php   </code>

<code>    </code><code>AddType  application</code><code>/x-httpd-php-source</code>  <code>.phps</code>

<code>    </code><code>ProxyRequests Off     </code><code>###關閉正向代理,開啟下行的反向代理</code>

<code>    </code><code>ProxyPassMatch ^/(.*\.php)$  fcgi:</code><code>//127</code><code>.0.0.1:9000</code><code>/usr/local/http24/htdocs/</code><code>$1</code>

# service httpd24 restart

    Stopping httpd24:             [  OK  ]

    Starting httpd24:             [  OK  ]

[root@localhost htdocs]# echo "

&lt;html&gt;

&lt;h1&gt; Test php page &lt;/h1&gt;

&lt;?php

phpinfo()

?&gt;

&lt;/html&gt;" &gt;&gt; /usr/local/http24/htdocs/test.php

2.分離式設定

# vim  /etc/httpd24/httpd.conf    

    LoadModule proxy_module  modeles/mod_proxy.so

    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

    AddType  application/x-httpd-php  .php   

    AddType  application/x-httpd-php-source  .phps

    ProxyRequests Off     

    ProxyPassMatch ^/(.*\.php)$  fcgi://192.168.2.110:9000/usr/local/http24/htdocs/$1

Aapache 在配置反向代理時,應指定PHP伺服器的IP位址及相應端口号,前後端路徑可以不一緻,後端應指定絕對路徑

    如前端為/var/www/html,後端為/website/www,則fcgi://127.0.0.1:9000/website/www/$1

php-fpm所在機器上建立測試頁:

[root@wolf htdocs]#

[root@wolf htdocs]# echo "

&lt;/html&gt;" &gt;&gt; /htdocs/index.php

3.假如不能看到info界面

iptables -F 

setenforce 0

檢查php-fpm.conf 位址和端口是否正确等

PHP與MySQL的連接配接有三種API接口分别是:

    PHP的MySQL擴充 

    PHP的mysqli擴充 

    PHP資料對象(PDO) 

這裡直接少mysql擴充的用法,其他用法請自行參考部落格:https://www.jianshu.com/p/0a79847c8151

1.PHP與Mysql擴充(本擴充自 PHP 5.5.0 起已廢棄,并在将來會被移除),PHP原生的方式去連接配接資料庫,是面向過程的

在php-fpm機器上

[root@wolf htdocs]# cat mysql.php

<code>&lt;?php</code>

<code>$mysql_conf = array(</code>

<code>    </code><code>'host'</code>    <code>=&gt; </code><code>'127.0.0.1:3306'</code><code>,</code>

<code>    </code><code>'db'</code>      <code>=&gt; </code><code>'mysql'</code><code>,</code>

<code>    </code><code>'db_user'</code> <code>=&gt; </code><code>'wolf'</code><code>,</code>

<code>    </code><code>'db_pwd'</code>  <code>=&gt; </code><code>'wolf'</code><code>,</code>

<code>    </code><code>);</code>

<code>$mysql_conn = @mysql_connect($mysql_conf[</code><code>'host'</code><code>], $mysql_conf[</code><code>'db_user'</code><code>], $mysql_conf[</code><code>'db_pwd'</code><code>]);</code>

<code>if</code> <code>(!$mysql_conn) {</code>

<code>    </code><code>die(</code><code>"could not connect to the database:\n"</code> <code>. mysql_error());</code><code>//</code><code>診斷連接配接錯誤</code>

<code>mysql_query(</code><code>"set names 'utf8'"</code><code>);</code><code>//</code><code>編碼轉化</code>

<code>$select_db = mysql_select_db($mysql_conf[</code><code>'db'</code><code>]);</code>

<code>if</code> <code>(!$select_db) {</code>

<code>    </code><code>die(</code><code>"could not connect to the db:\n"</code> <code>.  mysql_error());</code>

<code>else</code>

<code>    </code><code>echo</code> <code>"Succeed"</code><code>;</code>

<code>mysql_close($mysql_conn);</code>

<code>?&gt;</code>

不要忘了:vim /usr/local/mysql/my.cnf 在mysqld下添加skip_name_resolve=on

參考部落格:

http://php.net/manual/zh/

http://blog.csdn.net/leshami/article/details/51944920

https://www.cnblogs.com/joshua317/articles/5989781.html

本文轉自MT_IT51CTO部落格,原文連結:http://blog.51cto.com/hmtk520/2069993,如需轉載請自行聯系原作者