指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

laravel10相关:

1.node升级(最好打开vpn,不然下载失败):
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  
# download and install Node.js (you may need to restart the terminal)
nvm install 20
  
# verifies the right Node.js version is in the environment
node -v # should print `v20.15.0`
  
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
  
官方链接:https://nodejs.org/zh-cn/download/package-manager
  
可以通过:$ nvm ls-remote 查看当前支持的node版本
不要使用网上其它方法,比如使用  n 升级,都是垃圾
  
2.composer install 报:
  
phpoffice/phpspreadsheet 1.29.0 requires ext-dom * -> it is missing from your system. Install or enable PHP's dom extension
requires ext-curl * -> it is missing from your system. Install or enable PHP's curl extension.
  
$ sudo apt-get install php8.3-curl
  
执行迁移文件的时候报:
$ php artisan migrate
  
Illuminate\Database\QueryException 
  
could not find driver (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'mmailer' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
  
原因:缺少mysql依赖驱动
$ sudo apt-get install php8.3-mysql
  
3.ubuntu22下有很多service,可以通过下面的命令找到指定的服务,比如php相关的
$ systemctl status php*
  
发现没有php8.3-fpm.servie, 但是执行php -v 却展示了,原因是我只安装了php8.3的cli,没有安装fpm
PHP 8.3.8 (cli) (built: Jun  8 2024 21:34:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies
  
手动改安装:    
sudo apt install php8.3-fpm
  
4.访问站点报 502, 查看error.log 如下:
2024/06/28 11:04:34 [crit] 55294#55294: *1 connect() to unix:/run/php/php8.3-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: www.mmail.test, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:", host: "www.mmail.test"
  
可以确定这是一个对 /run/php/php8.3-fpm.sock 访问权限的问题
1>cd /etc/php/8.3/fpm/pool.d
vim www.conf, 将里面的
  
user = www-data
group = www-data
改为(因为我的nginx 的 user 是 yizhi):
user = yizhi
group = yizhi
再访问,还是报错,那还需要修改 sock文件的 user:group信息
  
2>
$ cd /run/php
$ ll
total 16
drwxr-xr-x  2 www-data www-data  220  6月 28 11:12 ./
drwxr-xr-x 41 root     root     1120  6月 28 11:03 ../
-rw-r--r--  1 root     root        3  6月 28 08:37 php7.4-fpm.pid
srw-rw----  1 yizhi     yizhi        0  6月 28 08:37 php7.4-fpm.sock=
-rw-r--r--  1 root     root        3  6月 28 08:37 php8.1-fpm.pid
srw-rw----  1 yizhi     yizhi        0  6月 28 08:37 php8.1-fpm.sock=
-rw-r--r--  1 root     root        3  6月 28 08:37 php8.2-fpm.pid
srw-rw----  1 www-data www-data    0  6月 28 08:37 php8.2-fpm.sock=
-rw-r--r--  1 root     root        5  6月 28 11:12 php8.3-fpm.pid
srw-rw----  1 www-data www-data    0  6月 28 11:12 php8.3-fpm.sock=
lrwxrwxrwx  1 root     root       30  6月 28 08:37 php-fpm.sock -> /etc/alternatives/php-fpm.sock=
  
发现 php8.2-fpm.sock 的 user:group 都为www-data,修改为yizhi
sudo chown yizhi:yizhi php8.3-fpm.sock
  
3>重启php8.3-fpm(也可以不用重启)
$ sudo systemctl restart php8.3-fpm
  
4>再次访问,没有报错
  
相关命令:
sudo chown 新用户名:新用户组名 文件名
sudo chown -R 新用户名:新用户组名 目录名
  
5.查看 Laravel 项目的版本:
php artisan --version
  
6.迁移数据库之后,初始化一个用户的另一种方式(通过 factory,而不是直接run创建,但是还是run方式要好一些)
//factories/UserFactory
class UserFactory extends Factory
{
    protected $model = User::class;

    public function definition()
    {
        return [
            'id' => 1,
            'name' => $this->faker->name,
//            'email' => $this->faker->unique()->safeEmail,
            'email' => "shipeng.guo23@yizhi.com",
            'email_verified_at' => now(),
            'password' => bcrypt('Wuhan2019'), // password
            'remember_token' => Str::random(10),
            'role' => 'Publisher'
        ];
    }
}

//seeds下
class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        \App\User::factory()->create();
    }
}
  
执行:$ php artisan db:seed 即可新增一个用户