美文网首页
php开机启动

php开机启动

作者: kxmile | 来源:发表于2018-12-19 10:01 被阅读0次
    cd /usr/lib/systemd/system
    touch php-fpm.service
    

    输入以下内容到新建的文件

    [Unit]
    Description=The PHP FastCGI Process Manager
    After=syslog.target network.target
    
    [Service]
    Type=simple
    PIDFile=/usr/local/php/var/run/php-fpm.pid
    ExecStart=/usr/local/bin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf 
    ExecReload=/bin/kill -USR2 $MAINPID
    ExecStop=/bin/kill -SIGINT $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    
    #启动
    systemctl start php-fpm.service
    #查看状态
    systemctl status php-fpm.service
    #开机启动
    systemctl enable php-fpm.service
    
     systemctl daemon-reload
    
    [Unit]部分主要是对这个服务的说明,内容包括Description和After,Description用于描述服务,After用于描述服务类别
    
    [Service]部分是服务的关键,是服务的一些具体运行参数的设置,这里Type=forking是后台运行的形式,PIDFile为存放PID的文件路径,ExecStart为服务的具体运行命令,ExecReload为重启命令,ExecStop为停止命令,PrivateTmp=True表示给服务分配独立的临时空间,
    注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报错!
    
    [Install]部分是服务安装的相关设置,可设置为多用户的
    

    php-fpm的配置文件

    php-fpm.conf 的listen要跟nginx中的代理端口要一样的哦 也可以都改成sock地址
    nginx

    location ~ [^/]\.php(/|$)
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                #fastcgi_pass   127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
            }
    
    z@z-PC:/usr/local/php/etc$ cat /usr/local/php/etc/php-fpm.conf 
    [global]
    pid = /usr/local/php/var/run/php-fpm.pid
    error_log = /usr/local/php/var/log/php-fpm.log
    log_level = notice
    
    [www]
    listen = /tmp/php-cgi.sock
    #listen = 127.0.0.1:9000
    listen.backlog = -1
    listen.allowed_clients = 127.0.0.1
    listen.owner = www
    listen.group = www
    listen.mode = 0666
    user = www
    group = www
    pm = dynamic
    pm.max_children = 60
    pm.start_servers = 5
    pm.min_spare_servers = 5
    pm.max_spare_servers = 60
    request_terminate_timeout = 100
    request_slowlog_timeout = 0
    slowlog = var/log/slow.log
    

    php-fpm master进程控制

    INT, TERM 立刻终止 
    QUIT 平滑终止 
    USR1 重新打开日志文件 
    USR2 平滑重载所有worker进程并重新载入配置和二进制模块
    

    查看php-fpm进程

    ps aux|grep php-fpm 
    
    z@z-PC:/usr/local/php/etc$ ps aux|grep php-fpm 
    root      8848  0.0  0.2 177556 23060 ?        Ss   10:19   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
    www       8858  1.5  0.2 186188 22528 ?        S    10:19   0:00 php-fpm: pool www
    www       8860  1.6  0.2 186188 22532 ?        S    10:19   0:00 php-fpm: pool www
    www       8862  1.0  0.2 184140 20488 ?        S    10:19   0:00 php-fpm: pool www
    www       8865  1.1  0.2 184140 20488 ?        S    10:19   0:00 php-fpm: pool www
    www       8867  0.9  0.2 184140 20488 ?        S    10:19   0:00 php-fpm: pool www
    www       8870  1.1  0.2 184140 20488 ?        S    10:19   0:00 php-fpm: pool www
    z         8879  0.0  0.0  14664  1028 pts/1    S+   10:20   0:00 grep php-fpm
    

    查看php-fpm进程

    z@z-PC:/usr/local/php/etc$ systemctl status php-fpm.service 
    ● php-fpm.service - The PHP FastCGI Process Manager
       Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: enabled)
       Active: active (running) since Wed 2018-12-19 10:19:47 CST; 6min ago
      Process: 7971 ExecStop=/bin/kill -SIGINT $MAINPID (code=exited, status=0/SUCCESS)
     Main PID: 8848 (php-fpm)
        Tasks: 6 (limit: 4915)
       Memory: 66.5M
       CGroup: /system.slice/php-fpm.service
               ├─8848 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
               ├─9010 php-fpm: pool www
               ├─9011 php-fpm: pool www
               ├─9012 php-fpm: pool www
               ├─9013 php-fpm: pool www
               └─9014 php-fpm: pool www
    
    

    重启php-fpm方式

    #相当于重启master
    kill -USR2  8848
    #同样效果
    kill -USR2`cat /usr/local/php/var/run/php-fpm.pid`
    #关闭
    kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
    

    原文
    原文

    相关文章

      网友评论

          本文标题:php开机启动

          本文链接:https://www.haomeiwen.com/subject/buydkqtx.html