laravel部署api项目遇到问题总结

一、Ubuntu远程Mysql 61“Connection refused”

Ubuntu 20.04.1线上数据库mysql连不上,有可能是线上mysql的配置为只本地访问到,我们需要修改线上mysql的配置,运行命令cd /etc/mysql/mysql.conf.d,然后运行命令sudo nano mysqld.cnf
找到:bind-address = 127.0.0.1
改为:bind-address = 0.0.0.0
在这里插入图片描述
control + x保存退出后,输入命令sudo systemctl restart mysql.service重启mysql
如果还是连接不上的话,就查看防火墙mysql的端口是否开放。

二、Ubuntu更新php8

运行命令sudo add-apt-repository ppa:ondrej/php && sudo apt-get update

Tips: 有报错请看,无报错忽略
报错sudo: add-apt-repository: command not found
解决:先运行命令 apt-get -y install software-properties-common,再执行命令sudo add-apt-repository ppa:ondrej/php && sudo apt-get update,提示按enter就按enter

接着运行sudo apt install php8.2.9具体看你安装哪个版本,接着安装相对应的扩展只需将版本号加上即可。例如:apt install php8.2.9-curl

三、线上部署Permission denied

3.1、部署完之后访问域名出现报错:

UnexpectedValueException
The stream or file "/var/www/furniture-maintenance-api/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 "/var/www/furniture-maintenance-
api/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 
/var/www/furniture-maintenance-api/bootstrap/cache directory must be present and 
writable. Context: {"exception":{}} Context: {"exception":{}}

权限不足,我们运行命令:chmod -R 777 storage

3.2、The /bootstrap/cache directory must be present and writable.

部署完之后报错The /bootstrap/cache directory must be present and writable.
运行命令php artisan cache:clea
在这里插入图片描述

四、图片访问404

如果发现部署线上图片访问404,那么我们运行命令php artisan storage:link,如果还是不行的话那么将/public下的storage删了,重新运行这个命令php artisan storage:link
如果还是404的话,请查看线上storage/app/public是否有文件。

五、git部署线上文件

先将本地代码进行git仓库连接(此步骤可以网上搜索)。
在终端进行ssh root@你的公网ip输入密码,进行连接线上服务器后,进入到目录/var/www后我们把刚刚本地代码克隆下来:
git clone 你本地代码的远程仓库连接,这样就完成了git部署线上文件。

在学习php的路上,如果你觉得本文对你有所帮助的话,那就请关注点赞评论三连吧,谢谢,你的肯定是我写博的另一个支持。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你华还是你华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值