背景
使用开源代码搭建学习论坛,目前只能通过 `php artisan serve` 方式启动,本地访问。这无疑有悖于创建论坛的初衷,遂将其部署到web上,供更多人学习交流。
环境
ubuntu1~22.04
code:git@github.com:h-hkai/embedded-ai-bbs.git
initialize:
// 更新依赖项
sudo composer update
// 数据库迁移
sudo php artisan migrate:refresh --seed
过程
按照文档配置,80端口无法访问。以下是解决该问题的主要思路:
1. 先不考虑 bbs,单独运行 nginx 服务器,看能不能正常访问。
按照[link1][link2]这两篇文章指导进行安装配置,可以通过公网 ip 进行访问。
2. 加入 bbs 后,运行 nginx 服务器。
修改 /etc/nginx/nginx.conf 文件:
server {
index index.php;
location / {
root /home/ubuntu/larabbs/public;
}
}
访问公网 ip 后显示 `403 Forbidden`,搜索后找到如下解释:
The 403 Forbidden error in NGINX indicates that the server understood the request but refuses to fulfill it because the user does not have permission to access the requested resource. This error can occur due to various reasons, such as incorrect file permissions, misconfigured server settings, or access restrictions.
错误日志:
/var/log/nginx/error.log
2024/06/04 12:16:29 [error] 424767#424767: *1 "/home/ubuntu/larabbs/public/index.php" is forbidden (13: Permission denied), client: 119.130.164.17, server: , request: "GET / HTTP/1.1", host: "122.51.101.83"
2024/06/04 12:16:31 [error] 424767#424767: *1 "/home/ubuntu/larabbs/public/index.php" is forbidden (13: Permission denied), client: 119.130.164.17, server: , request: "GET / HTTP/1.1", host: "122.51.101.83"
现在确定该问题是由用户权限导致。参考[link]做如下修改:
/etc/nginx/nginx.conf
user www-data;
另外也将当前用户划分到 `www-data` 用户组,至此,权限问题解决。刷新页面,出现 `500 服务器错误`。
开启debug模式:
.env
APP_DEBUG=true
刷新页面提示如下错误信息:
The stream or file "laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log
解决办法:给对应目录添加权限和分组。
刷新页面后可以正常访问!
3. 用户注册报错
Expected response code "250" but got code "550", with message "550 The recipient may contain a non-existent account, please check the recipient addres
解决方案:
修改 config/mail.php
'mailers' => [
'smtp' => [
'transport' => 'mail',
刷新页面:
Connection to "process /usr/sbin/sendmail -bs" has been closed unexpectedly.
在对应目录下没找到可执行文件`sendmail`。
sudo apt-get update
sudo apt-get install sendmail
安装后,该问题解决!
4. 文件上传后无法访问
原因:[LINK]
解决方案:php artisan storage:link