linux下php-fpm以root身份启动设置
发布:smiling 来源: PHP粉丝网 添加日期:2015-04-29 13:56:28 浏览: 评论:0
php-fpm是php的一个加速 功能了,我们通常是以apache来启动php-fpm了,但今天小编来为各位介绍php-fpm使用root启动的教程,希望文章能够帮助到各位.
为了安全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 //phpfensi.com
- [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写好的脚本正常运行.
Tags: php-fpm linux启动设置
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)