linux下php-fpm以root身份啟動設定

來源:互聯網
上載者:User

為了安全php-fpm預設是以apache使用者啟動的


[root@chaoge ~]# ps -aux | grep php-fpm
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      4539  0.0  0.0 205552  3716 ?        Ss   10:22   0:00 php-fpm: master process (/etc/php-fpm.conf)
apache    4540  0.0  0.0 205552  3332 ?        S    10:22   0:00 php-fpm: pool www
apache    4541  0.0  0.0 205552  3332 ?        S    10:22   0:00 php-fpm: pool www
apache    4542  0.0  0.0 205552  3332 ?        S    10:22   0:00 php-fpm: pool www
apache    4543  0.0  0.0 205552  3332 ?        S    10:22   0:00 php-fpm: pool www
apache    4544  0.0  0.0 205552  3332 ?        S    10:22   0:00 php-fpm: pool www
root      4556  0.0  0.0 103248   888 pts/1    S+   10:22   0:00 grep php-fpm


網上一堆文章說要以root身份啟動需要設定一堆非常複雜的程式,並且甚至有人說不能以root身份啟動。既然是php-fpm程式,所以應該先找設定檔,於是開啟預設的設定檔,具體你得看你的預設設定檔路徑在哪


/etc/php-fpm.d/www.conf


這是我機器上的


找到


; RPM: apache Choosed to be able to access some dir as httpd
user = apache
改成
; RPM: apache Choosed to be able to access some dir as httpd
user = root
 
重新啟動php-fpm


[root@chaoge ~]# ps -le | grep php-fpm
1 S     0  4974     1  0  80   0 - 51388 ep_pol ?        00:00:00 php-fpm
5 S    48  4975  4974  0  80   0 - 51388 inet_c ?        00:00:00 php-fpm
5 S    48  4976  4974  0  80   0 - 51388 inet_c ?        00:00:00 php-fpm
5 S    48  4977  4974  0  80   0 - 51388 inet_c ?        00:00:00 php-fpm
5 S    48  4978  4974  0  80   0 - 51388 inet_c ?        00:00:00 php-fpm
5 S    48  5035  4974  0  80   0 - 51388 inet_c ?        00:00:00 php-fpm
[root@chaoge ~]# kill -QUIT 5035
[root@chaoge ~]# php-fpm
[17-Apr-2015 10:33:38] ERROR: [pool www] please specify user and group other than root
[17-Apr-2015 10:33:38] ERROR: FPM initialization failed
[root@chaoge ~]#

報錯了,提示運行php-fpm運行使用者和組只能選擇其它的除了root以外,於是查看php-fpm文檔,會發現其中一個選項:-R


[root@chaoge ~]# php-fpm --help
Usage: php [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F]
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -h               This help
  -i               PHP information
  -m               Show compiled in modules
  -v               Version number
  -p, --prefix <dir>
                   Specify alternative prefix path to FastCGI process manager (default: /usr).
  -g, --pid <file>
                   Specify the PID file location.
  -y, --fpm-config <file>
                   Specify alternative path to FastCGI process manager config file.
  -t, --test       Test FPM configuration and exit
  -D, --daemonize  force to run in background, and ignore daemonize option from config file
  -F, --nodaemonize
                   force to stay in foreground, and ignore daemonize option from config file
  -R, --allow-to-run-as-root
                   Allow pool to run as root (disabled by default)
於是我們試著啟動的時候加上這個參數試一試
 
[root@chaoge ~]# php-fpm -R
[root@chaoge ~]# ps -aux | grep php-fpm
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      5497  0.0  0.0 205552  3712 ?        Ss   10:36   0:00 php-fpm: master process (/etc/php-fpm.conf)
root      5498  0.0  0.0 205552  3196 ?        S    10:36   0:00 php-fpm: pool www
root      5499  0.0  0.0 205552  3196 ?        S    10:36   0:00 php-fpm: pool www
root      5500  0.0  0.0 205552  3196 ?        S    10:36   0:00 php-fpm: pool www
root      5501  0.0  0.0 205552  3200 ?        S    10:36   0:00 php-fpm: pool www
root      5502  0.0  0.0 205552  3200 ?        S    10:36   0:00 php-fpm: pool www
root      5524  0.0  0.0 103252   888 pts/1    S+   10:36   0:00 grep php-fpm


成功啟動了,測試一下,以root使用者寫了一個shell指令碼儲存在root宿主目錄下,php裡exec寫好的指令碼正常運行。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.