PHP5.6中php-fpm的配置、啟動、關閉和重啟

來源:互聯網
上載者:User

標籤:sap   使用   warning   服務   grep   blog   進程   top   tun   

轉:http://blog.csdn.net/field_yang/article/details/52401994

 

該文主要講述:如何配置PHP-fpm、常見報錯解決方案和php-fpm的啟動、關閉和重啟。

LNMP環境中的nginx是不支援php的,需要通過fastcgi外掛程式來處理有關php的請求。而php需要php-fpm這個組件提供該功能。在php5.3.3以前的版本php-fpm是以一個補丁包的形式存在的,而php5.3.3以後只需在編譯安裝時使用–enable-fpm載入該模組即可,無需另行安裝。

[[email protected] php-5.6.25]#/usr/local/php/sbin/php-fpm

[29-Aug-2016 17:36:05] ERROR: failed toopen configuration file ‘/usr/local/php/etc/php-fpm.conf‘: No such file ordirectory (2)

[29-Aug-2016 17:36:05] ERROR: failed toload configuration file ‘/usr/local/php/etc/php-fpm.conf‘

[29-Aug-2016 17:36:05] ERROR: FPMinitialization failed

 

啟動php-fpm發現缺乏設定檔/usr/local/php/etc/php-fpm.conf

此時只需複製php-fpm的設定檔在安裝php時提供的設定檔的模版/usr/local/php/etc/php-fpm.conf.default到相應目錄下即可,此處有兩種方法,均可提供設定檔,即分別將末班複製到/usr/local/php/etc/或者 /usr/local/etc/並重新命名為php-fpm.conf

①  

[[email protected] etc]# cd /usr/local/php/etc/

[[email protected] etc]# ls

pear.conf php-fpm.conf.default

[[email protected] etc]# cp/usr/local/php/etc/php-fpm.conf/usr/local/etc/php-fpm.conf

利用/usr/local/php/sbin/php-fpm啟動FPM

[[email protected] etc]# /usr/local/php/sbin/php-fpm

②  

[[email protected] etc]#cp php-fpm.conf.defaultphp-fpm.conf

[[email protected] etc]# /usr/local/php/sbin/php-fpm

 

至此php-fpm配置完成,鑒於fpm是置於PHP和Nginx之間的一層應用,所以配置成服務開機自啟。

下面配置php-fpm以服務形式啟動

[[email protected] etc]# cd /usr/local/php-5.6.25/

[[email protected] php-5.6.25]# cp./sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm

[[email protected] php-5.6.25]# ll /etc/init.d/php-fpm

-rw-r--r-- 1 root root 2354 8月  3115:54 /etc/init.d/php-fpm

[[email protected] php-5.6.25]# chmod a+x/etc/init.d/php-fpm

[[email protected] php-5.6.25]# ll /etc/init.d/php-fpm

-rwxr-xr-x 1 root root 2354 8月  3115:54 /etc/init.d/php-fpm

[[email protected] php-5.6.25]# /etc/init.d/php-fpmstart

Starting php-fpm [31-Aug-2016 15:56:00]ERROR: unable to bind listening socket for address ‘127.0.0.1:9000‘: Addressalready in use (98)

[31-Aug-2016 15:56:00] ERROR: FPMinitialization failed

Failed

 

[[email protected] php-5.6.25]# netstat -tunlp |grep9000

tcp       0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      4928/php-fpm        

 [[email protected] etc]# /etc/init.d/php-fpm stop

Gracefully shutting down php-fpm warning,no pid file found - php-fpm is not running ?

關閉php-fpm服務時發現報錯,缺乏pid檔案,解決方案為編輯設定檔,啟用pid檔案

[[email protected] etc]# vim php-fpm.conf

pid = run/php-fpm.pid

[[email protected] etc]# kill -INT `cat/usr/local/php/var/run/php-fpm.pid`

cat: /usr/local/php/var/run/php-fpm.pid: 沒有那個檔案或目錄

[[email protected] etc]# /etc/init.d/php-fpm stop

Gracefully shutting down php-fpm warning,no pid file found - php-fpm is not running ?

嘗試關閉服務時再次報錯,手動建立php-fpm.pid檔案即可

[[email protected] etc]# cd /usr/local/php/var/run/

[[email protected] run]# vim php-fpm.pid

[[email protected] run]# ls

php-fpm.pid

[[email protected] run]# service php-fpm stop

Gracefully shutting down php-fpm . done

[[email protected] run]# service php-fpm start

Starting php-fpm done

[[email protected] run]# netstat -tunlp |grep 9000

tcp       0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3008/php-fpm       

[[email protected] run]# kill -INT `cat /usr/local/php/var/run/php-fpm.pid`

[[email protected] run]# netstat -tunlp |grep 9000

[[email protected] run]#  /etc/init.d/php-fpm start

Startingphp-fpm  done          

將服務添加到chkconfig列表,設定開機啟動

[[email protected] run]# chkconfig --add php-fpm

[[email protected] run]# chkconfig php-fpm on

 

至此,php-fpm配置完成,下面提供兩種控制方式

① PHP-FPM使用訊號控制:

INT, TERM 立刻終止

QUIT 平滑終止

USR1 重新開啟記錄檔

USR2 平滑重載所有worker進程並重新載入配置和二進位模組

啟動

[[email protected] run]# /usr/local/php/sbin/php-fpm

關閉:

[[email protected] run]# kill -INT `cat/usr/local/php/var/run/php-fpm.pid`

重啟:

[[email protected] run]# kill -USR2 `cat/usr/local/php/var/run/php-fpm.pid`

②  

服務方式控制

Usage: /etc/init.d/php-fpm{start|stop|force-quit|restart|reload|status}

[[email protected] run]# service php-fpm start

Starting php-fpm done

[[email protected] run]# service php-fpm stop

Gracefully shutting down php-fpm . done

[[email protected] run]#  /etc/init.d/php-fpm restart

Gracefully shutting down php-fpm . done

Starting php-fpm done

[[email protected] run]#

 

PHP5.6中php-fpm的配置、啟動、關閉和重啟

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.