您好,登錄后才能下訂單哦!
一、什么是FastCGI FastCGI是一個可伸縮、高速在HTTP server和動態腳本語言之間的一個通信接口.大多數的HTTP server都支持FastCGI,比如:Nginx Aapache lighttpd等..FastCGI被很多語言所支持。其中就有PHP. 二、Nginx+FastCGI運行原理 (1)Nginx不支持對外程序的直接調用或者解析,所有的外包程序(包括PHP)都必須通過FastCGI來調用 (2)FastCGI接口在Linux下面可以(socket文件的方式存在,那么可以IP), (3)為了調用CGI程序,還需要一個FastCGI的wrapper,當Nginx發送CGI的請求給這個socket的時候。通過FastCGI接口wrapper接受到的請求,然后派生出一個新的線程,這個線程調用外部程序或者腳本讀卻返回數據. 最后wrapper在將返回的數據通過FastCGI接口,沿著固定的socket傳遞給Nginx,最后返回給數據發送的客戶端. Nginx-->發送一個CGI請求-->FastCGI(warpper)接收到這個請求--->派生出一個新的線程--->調用外部程序或者腳本返回數據--->wrapper將數據沿著固定的socket傳遞給Nginx-->由Nginx在把這個數據返回給用戶. 三、PHP與PHP-FPM的安裝與優化 PHP-FPM也是第三方的FastCGI的進程管理,它作為PHP補丁一起開發,編寫的時候跟著一起編譯到PHP內核當中,PHP-FPM在處理高并發的方面非常的優秀.它的一個有點呢:就是把動態語言和HTTP server分離開來(動靜分離),Http server主要處理靜態請求,PHP-FPM處理動態請求。 所有呢 PHP/PHP-FPM 和Nginx經常組合到一塊安裝到一臺機器上,以滿足業務需求. 四、首先安裝Mysql (1)首先安裝Mysql數據庫,PHP在編譯的時候需要mysql的一個配置 這樣PHP遠程鏈接Mysql才有用 # cd /data/soft/ # tar xf mysql-5.1.49.tar.gz -C tmp/ # cd tmp/mysql-5.1.49/ #CONFOPTS=" \ --with-charset=utf8 \ --with-plugins=partition,federated,innobase,myisam \ --enable-static \ --enable-assembler \ --enable-thread-safe-client \ --with-client-ldflags=-all-static-ltinfo \ --with-mysqld-ldflags=-all-static-ltinfo \ --with-big-tables \ --with-mysqld-user=mysql \ --without-debug \ --without-ndb-debug \ --localstatedir=/usr/local/services/mysql-5.1.49/var \ --prefix=/usr/local/services/mysql-5.1.49 \ " #./configure $CONFOPTS >/dev/null # make >/dev/null && make install >/dev/null 五、安裝PHP的依賴庫 ①libxml2-2.7.7.tar.gz # cd /data/soft/ #tar xf libxml2-2.7.7.tar.gz –C tmp/ # cd tmp/libxml2-2.7.7/ #./configure --prefix=/usr/local/services >/dev/null #make >/dev/null && make install >/dev/null ②curl-7.21.4.tar.gz # cd /data/soft/ # tar xf curl-7.21.4.tar.gz -C tmp/ # cd tmp/curl-7.21.4/ #./configure --prefix=/usr/local/services >/dev/null #make >/dev/null && make install >/dev/null ③jpegsrc.v8b.tar.gz # cd /data/soft/ #tar xf jpegsrc.v8b.tar.gz –C tmp/ #cd tmp/jpeg-8b/ #./configure --prefix=/usr/local/services >/dev/null #make >/dev/null && make install >/dev/null ④libpng-1.4.3.tar.gz # cd /data/soft/ # tar xf libpng-1.4.3.tar.gz -C tmp/ # cd tmp/libpng-1.4.3/ #./configure --prefix=/usr/local/services >/dev/null #make >/dev/null && make install >/dev/null ⑤freetype-2.4.1.tar.gz # cd /data/soft/ # tar xf freetype-2.4.1.tar.gz -C tmp/ # cd tmp/freetype-2.4.1/ #./configure --prefix=/usr/local/services >/dev/null #make >/dev/null && make install >/dev/null ⑥libevent-2.0.10-stable.tar.gz # cd /data/soft/ # tar xf libevent-2.0.10-stable.tar.gz –C tmp/ # cd tmp/libevent-2.0.10-stable/ #./configure --prefix=/usr/local/services --disable-debug-mode >/dev/null #make >/dev/null && make install >/dev/null ⑦re2c-0.13.5.tar.gz # cd /data/soft/ # tar xf re2c-0.13.5.tar.gz -C tmp/ # cd tmp/re2c-0.13.5/ #./configure --prefix=/usr/local/services >/dev/null #make >/dev/null && make install >/dev/null ⑧libmcrypt-2.5.8.tar.gz # cd /data/soft/ # tar xf libmcrypt-2.5.8.tar.bz2 -C tmp/ # cd tmp/libmcrypt-2.5.8/ #./configure --prefix=/usr/local/services >/dev/null #make >/dev/null && make install >/dev/null # cd libltdl/ # ./configure --prefix=/usr/local/services --enable-ltdl-install >/dev/null #make >/dev/null && make install >/dev/null 六、安裝PHP的依賴庫 wget http://php.net/distributions/php-5.3.13.tar.gz php-5.3.13.tar.gz # cd /data/soft/ # tar xf php-5.3.13.tar.gz -C tmp/ #cd tmp/php-5.3.13/ #CONFOPTS=" --enable-zend-multibyte \ --enable-mbstring \ --enable-sockets \ --enable-pdo \ --enable-zip \ --enable-fpm \ --with-gd \ --with-fpm-user=user_00 \ --with-fpm-group=user_00 \ --with-zlib \ --with-config-file-path=/usr/local/services/php-5.3.13/etc \ --with-libxml-dir=/usr/local/services \ --with-curl=/usr/local/services \ --with-png-dir=/usr/local/services \ --with-jpeg-dir=/usr/local/services \ --with-freetype-dir=/usr/local/services \ --with-mysql=/usr/local/services/mysql \ --with-pdo-mysql=/usr/local/services/mysql \ --with-mysqli=/usr/local/services/mysql/bin/mysql_config \ --prefix=/usr/local/services/php-5.3.13 \ " # ./configure $CONFOPTS # make >/dev/null && make install >/dev/null 編譯錯誤解決: /var/lib/mysql/mysql.sock configure: error: Cannot find libmysqlclient under /usr. Note that the MySQL client library is not bundled anymore! 解決方法: cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so 七、安裝PHP的擴展模塊 ①eaccelerator-0.9.6.1.tar.bz2 # cd /data/soft/ #tar xf eaccelerator-0.9.6.1.tar.bz2 -C tmp/ #cd tmp/eaccelerator-0.9.6.1/ #/usr/local/services/php-5.3.13/bin/phpize #./configure --prefix=/usr/local/services/eaccelerator-0.9.6.1 --enable-eaccelerator --with-php-config=/usr/local/services/php-5.3.13/bin/php-config > /dev/null #make >/dev/null && make install >/dev/null #mkdir /tmp/eaccelerator #chmod 777 /tmp/eaccelerator ②memcached-1.4.13.tar.gz (服務器端要前安裝,下面的編譯擴展模塊要用到) # cd /data/soft/ #tar xf memcached-1.4.13.tar.gz -C tmp/ # cd tmp/memcached-1.4.13/ #./configure --enable-64bit --with-libevent=/usr/local/services --prefix=/usr/local/services/memcached-1.4.13 >/dev/null # make >/dev/null && make install >/dev/null ③libmemcached-0.48.tar.gz # cd /data/soft/ #tar xf libmemcached-0.48.tar.gz -C tmp/ #cd tmp/libmemcached-0.48/ #CONFOPTS=" --disable-libinnodb --without-libinnodb-prefix --with-libevent-prefix=/usr/local/services --with-memcached=/usr/local/services/memcached-1.4.13/bin/memcached --prefix=/usr/local/services " #./configure $CONFOPTS >/dev/null #make >/dev/null && make install >/dev/null ④igbinary-1.0.2.tgz # cd /data/soft/ # tar xf igbinary-1.0.2.tar.gz -C tmp/ #cd tmp/igbinary-1.0.2/ #/usr/local/services/php-5.3.13/bin/phpize #./configure --enable-igbinary --with-php-config=/usr/local/services/php-5.3.13/bin/php-config >/dev/null #make >/dev/null && make install >/dev/null ⑤memcache-3.0.5.tgz # cd /data/soft/ # tar xf memcache-3.0.5.tgz -C tmp/ #cd tmp/memcache-3.0.5/ #/usr/local/services/php-5.3.13/bin/phpize #CONFOPTS=" \ --enable-memcache \ --with-php-config=/usr/local/services/php-5.3.13/bin/php-config \ " #./configure $CONFOPTS >/dev/null #make >/dev/null && make install >/dev/null ⑥memcached-1.0.2.tgz(注意安裝的順序,igbinary-1.1.1.tgz是依賴庫) # cd /data/soft/ # tar xf memcached-1.0.2.tgz -C tmp/ # cd tmp/memcached-1.0.2/ #/usr/local/services/php-5.3.13/bin/phpize #CONFOPTS=" \ --enable-memcached \ --enable-memcached-igbinary \ --enable-memcached-json \ --with-libmemcached-dir=/usr/local/services \ --with-php-config=/usr/local/services/php-5.3.13/bin/php-config \ --prefix=/usr/local/services \ " #./configure $CONFOPTS >/dev/null #make >/dev/null && make install >/dev/null ⑦owlient-phpredis-2.1.1-1-g90ecd17.tar.gz # cd /data/soft/ #tar xf owlient-phpredis-2.1.1-1-g90ecd17.tar.gz -C tmp/ # cd tmp/owlient-phpredis-90ecd17/ #/usr/local/services/php-5.3.13/bin/phpize #./configure --with-php-config=/usr/local/services/php-5.3.13/bin/php-config >/dev/null #make >/dev/null && make install >/dev/null 九、拷貝配置文件: # cd /usr/local/services/php-5.3.13/etc # cp php-fpm.conf.default php-fpm.conf # cp /soft/php/php-5.3.13/php.ini-production php.ini 1.PHP配置文件優化與調整 1.在php-fpm.conf 里面調整. ;listen = 127.0.0.1:9000 listen = /tmp/php-cgi.tuge.sock #以socke的方式訪問.注視掉.ip端口的方式. ; Default Value: log/php-fpm.log error_log = /data/php_log/tuge.php.error #根據不同的項目名.定義不同的.sock 和日志. # 調整進程數量 pm.max_children:靜態方式下開啟的php-fpm進程數量。 pm.start_servers:動態方式下的起始php-fpm進程數量。 pm.min_spare_servers:動態方式下的最小php-fpm進程數量。 pm.max_spare_servers:動態方式下的最大php-fpm進程數量。 2.在php.ini 加入擴展模塊. 在尾部添加: [eaccelerator] zend_extension="/usr/local/services/php-5.3.13/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so " eaccelerator.shm_size="16" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" 擴展模塊增加 extension = memcached.so extension = redis.so extension = memcache.so extension = igbinary.so 十、啟動PHP-FPM #cd ../sbin #./php-fpm 十一、Nginx配置文件調整 #vim /usr/local/services/nginx-0.8.55/conf/vhost/vhost.zhangyi.com #可以指定多個localtion進行不同的指令處理,這里是指定php的sock location ~ \.php$ { fastcgi_pass unix:/tmp/php-cgi.zhangyi.sock; #修改這里 fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SERVER_NAME $http_host; fastcgi_ignore_client_abort on; } 十二、重啟Nginux #cd /usr/local/services/nginx-0.8.55/sbin #./nginx -s reload 十三、測試 #cd /data/www #mv index.html index.php #vim index.php <?php phpinfo(); ?> 在firefox瀏覽器上登錄
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。