部署LaraBBS出现500错误

这近刷LaraBBS后,发现都忘光了,唉,看来得经常刷一刷才行啊,发现里面好多内容好难啊,都感觉之前没弄懂过。看来得把所有的教程都学一遍才行。不管学什么,做网站总得熟练的掌握一个,那laravel就真的要掌握好了才行啊。也要多做点小项目,多练练手。

部署到腾讯服务器上,发现出现500错误,百度了一番,才搞清楚。

先配置好env,

#运行环境 local(本地开发环境)、production(生产环境)
APP_ENV=production
APP_DEBUG=false

这时发现打开500错误:
部署LaraBBS出现500错误

那就先把调试模式打开:

APP_DEBUG=true

部署LaraBBS出现500错误

出现表不存在,那就是需要migrate数据库了。在网站根目录打开终端。第一次打开终端需要输入密码,密码可以到腾讯云里进行修改。

部署LaraBBS出现500错误

注意腾讯云里安装Ubuntu的默认用户名是ubuntu,如果是centos,用户名就是root。需要点击两次确认!!因为第一次会弹出错误,再点一次就好了。

 php artisan migrate --seed

出现权限错误:

The stream or file "/www/wwwroot/8002/larabbs/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
The exception occurred while attempting to log: The stream or file "/www/wwwroot/8002/larabbs/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
The exception occurred while attempting to log: file_put_contents(/www/wwwroot/8002/larabbs/storage/framework/cache/data/85/5f/855f92484c8c414d36c1b25cb24876e30229cbbf): Failed to open stream: Permission denied
Context: {"exception":{}}
Context: {"exception":{}}

需要给storage目录赋予777权限

sudo chmod 777 -R storage/

部署LaraBBS出现500错误

再刷新网站,就可以打开了!😊😊😊😊😊

部署LaraBBS出现500错误

但是发现用户图像都是403错误,就是防盗链问题,加上反防盗链代码:

views/layouts/app.blade.php
<!-- 解决图片403防盗链问题 -->
<meta name="referrer" content="no-referrer" />

不能访问其他页面,或者不能访问jQuery等,网站配置里加上

   location / {
        index  index.htm index.html index.php;

        if (!-e $request_filename) {
           rewrite  ^/(.*)$  /index.php/$1  last;
           break;
        }
    }

部署LaraBBS出现500错误



laravel9需要php的版本是8.0及以上,所以要用最新的php版本才行。这里我我使用php8.1。有的出错说需要php7.2,执行宝塔php里composer出错时,需要使用root用户。

使用宝塔php里的composer时,报错:

Dependency resolution completed in 0.023 seconds
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires intervention/image ^2.7 -> satisfiable by intervention/image[2.7.0, 2.7.1, 2.7.2].
    - intervention/image[2.7.0, 2.7.1, 2.7.2] require ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
  Problem 2
    - mews/captcha[3.2.5, 3.2.6, 3.2.7, 3.2.8, v3.2.9, 3.2.10, 3.3.0] require intervention/image ~2.5 -> satisfiable by intervention/image[2.7.0, 2.7.1, 2.7.2].
    - mews/captcha[3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1, 3.2.0, 3.2.1, 3.2.2, 3.2.3, 3.2.4] require php ^7.2 -> your php version (8.0.26) does not satisfy that requirement.
    - intervention/image[2.7.0, 2.7.1, 2.7.2] require ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
    - Root composer.json requires mews/captcha ~3.0

然后安装了fileinfo,在配置里把fileinfo扩展打开,就是去掉前面的分号,也还是不行,最后百度到,使用宝塔php里的composer,需要使用root用户,而不是www用户,不然就出现上面的错误。

安装两个php扩展:

fileinfo
redis

在网址根目录,使用终端时,发现会出现fileinfo重复加载错误,那就是php配置里,fileinfo扩展前面的分号要加上,因为最下面已经有引用加载的代码了,这里不需要打开。

需要删除两个php禁止的函数,

 putenv
 proc_open

宝塔里建立网站,先不要使用域名,如果使用域名建立网站,就不能使用这个域名的其他端口再建立网站了。可以使用0.0.0.1等建立网站,然后再修改,可以使用不同的端口建立多个网站了。

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

phpenv 给出的 url 重写:


location / {  
    try_files $uri $uri/ /index.php$is_args$query_string;  
}  
10个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!