在Ubuntu上监控ThinkPHP应用的运行状态,可以通过以下几种方法:
Supervisor是一个进程控制系统,可以用来监控和管理多个进程。
sudo apt update
sudo apt install supervisor
创建一个新的配置文件来管理你的ThinkPHP应用。
sudo nano /etc/supervisor/conf.d/thinkphp.conf
在文件中添加以下内容:
[program:thinkphp]
command=/usr/bin/php /path/to/your/thinkphp/project run
directory=/path/to/your/thinkphp/project
autostart=true
autorestart=true
stderr_logfile=/var/log/thinkphp.err.log
stdout_logfile=/var/log/thinkphp.out.log
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start thinkphp
sudo supervisorctl status
Systemd是Linux系统的初始化系统和系统管理守护进程,可以用来管理后台服务和进程。
sudo nano /etc/systemd/system/thinkphp.service
在文件中添加以下内容:
[Unit]
Description=ThinkPHP Application
After=network.target
[Service]
User=your_user
Group=your_group
ExecStart=/usr/bin/php /path/to/your/thinkphp/project run
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable thinkphp
sudo systemctl start thinkphp
sudo systemctl status thinkphp
Monit是一个用于管理和监视Unix系统的工具,可以用来监控进程、文件、目录和设备。
sudo apt update
sudo apt install monit
编辑Monit配置文件:
sudo nano /etc/monit/monitrc
添加以下内容来监控你的ThinkPHP应用:
check process thinkphp with pidfile /path/to/your/thinkphp/project/runtime/pid
start program = "/usr/bin/php /path/to/your/thinkphp/project run"
stop program = "/usr/bin/php /path/to/your/thinkphp/project stop"
if failed host 127.0.0.1 port 80 protocol http then restart
if 5 restarts within 5 cycles then timeout
sudo monit reload
sudo systemctl start monit
sudo monit status
如果你使用Nginx和PHP-FPM来运行ThinkPHP应用,可以通过监控Nginx和PHP-FPM的状态来间接监控ThinkPHP应用。
sudo apt update
sudo apt install nginx php-fpm
编辑Nginx配置文件:
sudo nano /etc/nginx/sites-available/your_domain
添加以下内容:
server {
listen 80;
server_name your_domain;
root /path/to/your/thinkphp/project;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
sudo systemctl status nginx
sudo systemctl status php7.4-fpm
通过以上方法,你可以在Ubuntu上有效地监控ThinkPHP应用的运行状态。选择适合你项目需求的方法进行配置和监控。