在Ubuntu上,您可以使用systemd来管理LNMP(Linux, Nginx, MySQL/MariaDB, PHP)服务的自动重启。以下是设置自动重启的步骤:
打开终端。
确保您已经安装了Nginx, MySQL/MariaDB和PHP。如果没有,请使用以下命令安装:
sudo apt update
sudo apt install nginx mysql-server php-fpm
启动Nginx, MySQL/MariaDB和PHP-FPM服务:
sudo systemctl start nginx
sudo systemctl start mysql
sudo systemctl start php7.4-fpm
注意:如果您使用的是PHP 7.2,请将php7.4-fpm替换为php7.2-fpm。
设置Nginx, MySQL/MariaDB和PHP-FPM服务开机自启:
sudo systemctl enable nginx
sudo systemctl enable mysql
sudo systemctl enable php7.4-fpm
同样,如果您使用的是PHP 7.2,请将php7.4-fpm替换为php7.2-fpm。
现在,您的LNMP服务已经设置为开机自启,当系统重启时,这些服务将自动启动。如果您需要手动重启这些服务,可以使用以下命令:
sudo systemctl restart nginx
sudo systemctl restart mysql
sudo systemctl restart php7.4-fpm
再次提醒,如果您使用的是PHP 7.2,请将php7.4-fpm替换为php7.2-fpm。