dua situasi, guna php 7.4 atau php 8.1
Kalau guna php 7.4
kena pakai pakej Laravel Swoole
*INSTALL PAKEJ *
https://github.com/swooletw/laravel-swoole
Kalau guna php 8.1 ke atas
boleh guna pakej Laravel Octane
composer require laravel/octane
php artisan octane:install
Dalam nota ini, aku anggap dalam linux dah ada nginx , kalu tak dok , install guna arahan untuk debian.
apt install nginx
Kalau guna php 7.4, install laravel-swoole dan kalu nok adjust host dan port boleh publish vendor
php artisan vendor:publish --tag=laravel-swoole
edit file swoole_http.php
dalam folder /config
Kalau guna php 8.1 ke atas, boleh guna laravel octane, dia boleh set host dan port direct.
php artisan octane:start --host=0.0.0.0 --port=80
CONFIGURE NGINX
Buatkan satu vhost untuk reversed proxy
server {
listen 80;
root /path/to/laravel;
index index.php;
error_page 404 /index.php
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
CONFIGURE SUPERVISOR
Supervisor ni digunakan untuk run apa-apa program secara background, jika server restart, ia akan start program tersebut secara automatik.
sudo apt install supervisor
sudo nvim /etc/supervisor/conf.d/php-swoole.conf
[program:laravel-swoole-worker]
process_name=%(program_name)s_%(process_num)02d
command=php path_of_laravel_project/artisan swoole:http start
autostart=true
autorestart=true
user=namauser
redirect_stderr=true
stdout_logfile=any_existing_path/laravel-octane-worker.log
stopwaitsecs=3600
sudo supervisorctl reread
sudo supervisorctl reload
sudo supervisorctl restart-all
Top comments (0)