Linux under PHP-FPM start setting as root

Source: Internet
Author: User
Tags fpm

For security php-fpm, the default is initiated by the Apache user


[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


A bunch of articles on the web say that starting with root requires setting up a bunch of very complex programs, and some people say they can't start as root. Since it is the PHP-FPM program, so you should find the configuration file, so open the default configuration file, you need to see your default profile path where


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


This is on my machine.


Found it


; Rpm:apache choosed to is able to access some dir as httpd
user = Apache
Change into
; Rpm:apache choosed to is able to access some dir as httpd
user = root

Reboot PHP-FPM


[Root@chaoge ~]# Ps-le | grep php-fpm
1 S 0 4974 1 0 0-51388 Ep_pol? 00:00:00 PHP-FPM
5 S 4975 4974 0 0-51388 inet_c? 00:00:00 PHP-FPM
5 S 4976 4974 0 0-51388 inet_c? 00:00:00 PHP-FPM
5 S 4977 4974 0 0-51388 inet_c? 00:00:00 PHP-FPM
5 S 4978 4974 0 0-51388 inet_c? 00:00:00 PHP-FPM
5 S 5035 4974 0 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 the user and group other than root
[17-apr-2015 10:33:38] ERROR:FPM initialization failed
[Root@chaoge ~]#

Error, prompted to run PHP-FPM run users and groups can only select other than root, so view the PHP-FPM document, you will find one of the options:-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 &L T;file>] [d] [-f]
-C <path>|<file> Look for php.ini file in this directory
-N No php.ini file would 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)
So we try to start with this parameter and try it on.

[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


Successfully started, test, the root user wrote a shell script saved in the root host directory, the PHP exec written script works correctly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.