首頁 >後端開發 >php教程 >应用root执行php-fpm

应用root执行php-fpm

WBOY
WBOY原創
2016-06-13 10:38:22883瀏覽

使用root执行php-fpm
php-fpm能对php的进程进行平滑重启和停止、重新载入配置和二进制模块而不丢失请求,这些是我比较喜欢的。实在是厌恶了使用kill -9 来重启php进程,因为决定装上php-fpm先测试一下。
整个安装过程完毕后,发现了两个不太习惯的地方:
1、php-fpm.conf
2、不能使用root用户来执行

配置文件还好,大致看看就明白意思了。再就是不能在root下执行,就我自己而言非常的不习惯,讨厌用户切来切去的。那只能hack一把了
找到文件 $src_path/sapi/cgi/fpm/fpm_unix.c里边有段代码

#ifndef I_REALLY_WANT_ROOT_PHP
                if (wp->set_uid == 0 || wp->set_gid == 0) {
                        zlog(ZLOG_STUFF, ZLOG_ERROR, "please specify user and group other than root, pool ‘%s’", wp->config->name);
                        return -1;
                }      
#endif                         
        }              
        else { /* not root */
                if (wp->config->user && *wp->config->user) {
                        zlog(ZLOG_STUFF, ZLOG_WARNING, "’user’ directive is ignored, pool ‘%s’", wp->config->name);
                }              
                if (wp->config->group && *wp->config->group) {
                        zlog(ZLOG_STUFF, ZLOG_WARNING, "’group’ directive is ignored, pool ‘%s’", wp->config->name);
                }                      
                if (wp->config->chroot && *wp->config->chroot) {
                        zlog(ZLOG_STUFF, ZLOG_WARNING, "’chroot’ directive is ignored, pool ‘%s’", wp->config->name);
                }              

                { /* set up HOME and USER anyway */
                        struct passwd *pwd;

                        pwd = getpwuid(getuid());

                        if (pwd) {
                                wp->user = strdup(pwd->pw_name);
                                wp->home = strdup(pwd->pw_dir);
                        }
                }
        }

        return 0;
}
php-fpm的作者想得很周全,料到有人不用ROOT心里不爽!比如像我:) 我们要做的就是在此文件顶部加上:
#define I_REALLY_WANT_ROOT_PHP
之后重新编译即可~希望大家用的顺手!

/data1/qiao.wang/software/php-5.2.14/sapi/cgi/fpm
需要重新编译

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn