在 Debian 上“管 Laravel 服务”通常分几种场景,下面按最常见、最推荐的方式给你一套清晰做法。
cd /var/www/laravel
php artisan serve
http://127.0.0.1:8000sudo apt update
sudo apt install nginx php-fpm php-cli php-mysql php-mbstring php-xml php-curl
server {
listen 80;
server_name example.com;
root /var/www/laravel/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
}
sudo chown -R www-data:www-data /var/www/laravel
sudo chmod -R 755 /var/www/laravel/storage
sudo systemctl restart nginx
sudo systemctl restart php-fpm
✅ Laravel 本身不需要“启动”,由 Web 服务器调用
php artisan queue:work
创建:
sudo nano /etc/systemd/system/laravel-queue.service
内容:
[Unit]
Description=Laravel Queue Worker
After=network.target
[Service]
User=www-data
WorkingDirectory=/var/www/laravel
ExecStart=/usr/bin/php artisan queue:work --queue=default
Restart=always
[Install]
WantedBy=multi-user.target
启用:
sudo systemctl enable laravel-queue
sudo systemctl start laravel-queue
crontab -e
添加:
* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1
sudo apt install supervisor
配置:
sudo nano /etc/supervisor/conf.d/laravel.conf
[program:laravel]
command=php /var/www/laravel/artisan queue:work
autostart=true
autorestart=true
user=www-data
redirect_stderr=true
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel
# 查看服务
systemctl status nginx
systemctl status php-fpm
# 重启
systemctl restart nginx
# Laravel
php artisan config:clear
php artisan cache:clear
php artisan migrate
Debian
├─ Nginx
├─ PHP-FPM
├─ Laravel
├─ Supervisor / systemd(队列)
└─ Cron(调度)
如果你愿意,可以告诉我:
我可以直接给你一套完整配置。