標籤:style http color 使用 io 資料 ar art
從 php 5.3.3 起,就可直接使用 PHP-FPM ,不再需要打補丁了。此前已寫過《Linux 從源碼編譯安裝 PHP 5》 見 http://www.linuxidc.com/Linux/2011-10/45743.htm,但是以 mod_php 模組方式,而非 FastCGI 模式運行 php ,並不適用於 Lighttpd、Nginx、LiteSpeed ,而且當時對所有模組都採用編譯安裝也顯得過於繁瑣。
一、什麼是 FastCGI、PHP-FPM、FastCGI ?
CGI是一種口;FastCGI 是 CGI 的擴充,讓 CGI 更高效;PHP-FPM 是一個 PHP FastCGI 管理器;同理 Spawn-FCGI 是一個通用的 FastCGI 管理器,它是 lighttpd 中的一部份。
因此,以 FastCGI 模式運行 php 5.3.4,主要有兩種方式,一是 PHP-FPM、二是 Spawn-FCGI ,本文要講的是以 PHP-FPM 方式運行管理 php。
參考資料:
1、《php-fpm文檔中文翻譯》 http://www.linuxidc.com/Linux/2011-10/45747.htm
2、《什麼是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?》 http://www.linuxidc.com/Linux/2011-07/38108.htm
二、準備工作
系統內容:Ubuntu-10.10-Server-I386
OpenSSL 版本:openssl-1.0.0c (安裝方法見 http://www.linuxidc.com/Linux/2011-10/45738.htm)
OpenSSH 版本:openssh-5.6p1 (安裝方法見 http://www.linuxidc.com/Linux/2011-10/45739.htm)
MySQL 5 版本:mysql-5.1.53-linux-i686-glibc23 (安裝方法見 http://www.linuxidc.com/Linux/2011-10/45742.htm)
三、編譯安裝 php5-gd3.1、安裝基礎編譯環境
1 |
apt-get install build-essential -y |
3.2、安裝 libpng、 libjpeg、 libfreetype
1 |
apt-get install libpng12-dev libjpeg62-dev libfreetype6-dev -y |
3.3、源碼編譯安裝 Libiconv
12345 |
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gztar -zxf libiconv-1.13.1.tar.gz cd libiconv-1.13.1/./configure --prefix=/usr/localmake && make install |
3.4、源碼編譯安裝 gd-2.0.35
12345 |
wget http://www.libgd.org/releases/gd-2.0.35.tar.gztar -zxf gd-2.0.35.tar.gzcd gd-2.0.35/./configure --prefix=/usr/local --with-libiconv-prefix=/usr/local --with-png --with-freetype --with-jpegmake && make install |
四、編譯安裝 php5 擴充庫4.1、libxml、libmhash、libmcrypt、mcrypt、libldap、libsasl
1 |
apt-get install libxml2-dev libmhash-dev libmcrypt-dev mcrypt libldap2-dev libsasl2-dev libssh2-1-dev |
4.2、編譯安裝 curl-7.21.3
12345 |
wget http://curl.haxx.se/download/curl-7.21.3.tar.gztar -zxf curl-7.21.3.tar.gzcd curl-7.21.3/./configure --prefix=/usr/localmake && make install |
五、編譯安裝 php5.3.4 (FastCGI)
12345678910111213141516171819202122232425262728293031323334353637383940 |
wget http://cn.php.net/distributions/php-5.3.4.tar.gztar -zxf php-5.3.4.tar.gzcd php-5.3.4/ ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl=/usr --with-png-dir --with-jpeg-dir --with-freetype-dir --with-iconv-dir=/usr/local --with-gd=/usr/local --enable-gd-native-ttf --with-libxml-dir --with-zlib --with-mhash --with-mcrypt --with-ldap --with-ldap-sasl --with-curl=/usr/local --with-curlwrappers --enable-bcmath --enable-calendar --enable-mbstring --enable-ftp --enable-zip --enable-sockets --enable-exif --enable-zend-multibyte --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data make && make installcp php.ini-production /usr/local/php/lib/php.ini<code> --prefix #指定php5安裝目錄--with-mysql #指定mysql安裝目錄--with-mysqli #添加mysqli擴充支援--with-openssl #指定openssl安裝目錄--with-png-dir #GD所需的png庫--with-jpeg-dir #GD所需的jpeg庫--with-freetype-dir #指定freetype字型庫--with-iconv-dir #指定iconv函數庫,用於字元集轉換--with-gd #指定GD庫目錄--enable-gd-native-ttf #添加TrueType字串函數庫--with-libxml-dir #指定libxml2庫目錄--with-zlib #壓縮庫目錄--with-mhash #指定雜湊函數庫目錄--with-mcrypt #指定mcrypt加密函數庫--with-ldap #指定ldap庫--with-curl #指定cURL庫--with-curlwrappers #運用curl工具開啟url流--enable-bcmath #高精度數學函數支援--enable-calendar #開啟對日曆的支援--enable-mbstring #多位元組、字串支援--enable-ftp #開啟對ftp的支援--enable-zip #開啟對zip的支援--enable-sockets #開啟sockets支援--enable-exif #圖片中繼資料支援--enable-zend-multibyte #zend多位元組的支援--enable-fpm #開啟FastCGI的進程管理支援--with-fpm-user #運行fpm的使用者--with-fpm-user #運行fpm的組 <h3>六、配置 php-fpm</h3> <code lang=‘bash‘>cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confvim /usr/local/php/etc/php-fpm.conf |
尋找下面語句,並將前面"#"號去掉。
123456 |
pid = run/php-fpm.piderror_log = log/php-fpm.loglog_level = noticepm.start_serverspm.min_spare_serverspm.max_spare_servers |
6.2、開機自動重啟 php-fpm
123 |
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod 755 /etc/init.d/php-fpmupdate-rc.d php-fpm defaults |