Linux下安装 laravel7与swooletw/laravel-swoole扩展

晋功
2023-12-01

1、安装 laravel7

1、composer拉取laravel7环境

cd /usr/local/nginx/html/
composer create-project --prefer-dist laravel/laravel blog "7.*"

2、设置nginx用户对laravel目录访问权限,可以通过设置ssh脚本加入到svn的钩子中对提交的文件和代码进行更新nginx用户对html目录下的访问权限

setfacl -m u:nginx:rwx -R /usr/local/nginx/html/
setfacl -m d:u:nginx:rwx -R /usr/local/nginx/html/

laravel7安装后运行问题解决

问题:

Fatal error: require(): Failed opening required '/usr/local/nginx/html/laravel/public/../vendor/autoload.php' (include_path='.:') in /usr/local/nginx/html/laravel/public/index.php on line 24

解决思路:
参考:
https://www.cnblogs.com/sgzn/p/12148396.html

  1. cd 到该引用的根目录,先删除 composer.lock 文件;

  2. 重新在根目录执行“composer install”,这样就能重新生成 composer.lock 文件了。

  3. 如果出现php版本不匹配,可用“composer install --ignore-platform-reqs”(忽略版本匹配)。

2、安装 swooletw/laravel-swoole扩展

cd /usr/local/nginx/html/laravel/
composer require swooletw/laravel-swoole
# 导出配置
php artisan vendor:publish --provider="SwooleTW\Http\LaravelServiceProvider"
#swoole命令
cd /usr/local/nginx/html/laravel/
php artisan swoole:http start #开启
php artisan swoole:http stop #关闭
php artisan swoole:http reload #平滑重启
php artisan swoole:http restart #重启
php artisan swoole:http infos #查看信息

查看运行swoole进程:ps aux |grep swoole
拥有一个主进程,一个管理进程,两个worker进程

[root@VM-0-6-centos ~]# ps aux |grep swoole
root      9423  0.1  1.6 361064 30912 pts/0    Sl+  00:01   0:00 swoole_http_server: master process for Laravel
root      9427  0.0  1.2 289388 23340 pts/0    S+   00:01   0:00 swoole_http_server: manager process for Laravel
root      9429  0.0  1.3 291588 25812 pts/0    S+   00:01   0:00 swoole_http_server: worker process for Laravel
root      9764  0.0  0.0 112816   972 pts/2    S+   00:03   0:00 grep --color=auto swoole

在config/app.php中的providers里面最后添加

SwooleTW\Http\LaravelServiceProvider::class

查看并关闭运行占用端口

[root@VM-0-6-centos laravel]# netstat -tunlp |grep 1215
tcp        0      0 127.0.0.1:1215          0.0.0.0:*               LISTEN      18642/swoole_http_s
[root@VM-0-6-centos laravel]# kill -9 18642
[root@VM-0-6-centos laravel]# netstat -tunlp |grep 1215
[root@VM-0-6-centos laravel]# php artisan swoole:http start

3、nginx配置proxy_pass代理转发1215端口

主要是proxy_pass http://127.0.0.1:1215;

user  nginx;
worker_processes  1;

error_log  logs/error.log;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  www.liuyuanshan.top;

        root   html;
        location / {
             index index.php index.html index.htm;
             #try_files $uri $uri/ /index.php?$query_string;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_index  index.php;
            #fastcgi_pass   127.0.0.1:9000;
            fastcgi_pass   unix:/usr/local/php/var/run/www.sock;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        location /status {
          auth_basic  "http://106.52.36.65";
          auth_basic_user_file    /usr/local/nginx/html/pass.db;
          stub_status;
        }
    }

server {
    listen       80;
    server_name  laravel.liuyuanshan.top;
    access_log logs/laravel.access.log main;

    root html/laravel/public;
    location / {
        index  index.php index.html index.htm;
        proxy_pass http://127.0.0.1:1215;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/usr/local/php/var/run/www.sock;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}


}
 类似资料: