# laravel- lnmp **Repository Path**: wangxuancheng/laravel--lnmp ## Basic Information - **Project Name**: laravel- lnmp - **Description**: laravel lnmp环境部署脚本 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-05 - **Last Updated**: 2025-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Laravel 自动部署脚本 ## 功能 - 自动部署 Laravel 项目 - 配置 Nginx、MySQL、Redis、Supervisor - 虚拟主机管理 - 数据备份 - 数据库管理 --- ## 目录结构 ```bash deploy-laravel/ ├── config.sh # 变量配置脚本 ├── deploy.sh # 主部署脚本 ├── manage-db-users.sh # 数据库用户脚本 ├── manage-vhost.sh # 虚拟主机管理脚本 ├── deploy-laravel.sh # laravel部署脚本 ├── backup.sh # 备份脚本 ├── README.md # 文档说明 ``` ``` cd /opt && git clone https://gitee.com/wangxuancheng/laravel--lnmp.git mv laravel--lnmp deploy && cd deploy vim config.sh ``` 当前目录所有.sh转换为 Unix 格式 ```shell sudo apt-get update sudo apt-get install dos2unix find . -name "*.sh" -type f -exec dos2unix {} \; ``` 赋予脚本执行权限 ```bash chmod +x config.sh deploy.sh manage-db-users.sh manage-vhost.sh deploy-laravel.sh backup.sh ``` 运行部署脚本 ```bash sudo ./deploy.sh # 查看秘钥,并登录 GitHub,转到 设置 > SSH 和 GPG 密钥, 点击 新建 SSH 密钥,粘贴公钥并保存 cat ~/.ssh/id_rsa.pub # 如果没有SSH 密钥,生成 ssh-keygen -t rsa -b 4096 -C "你的邮箱@example.com" sudo ./deploy-laravel.sh ``` 添加虚拟主机: ```bash # 添加 Laravel 站点 sudo ./manage-vhost.sh add api.example.com /var/www/laravel-project laravel # 添加 Vue 站点 sudo ./manage-vhost.sh add admin.example.com /var/www/vue-project vue ``` 删除虚拟主机: ```bash sudo ./manage-vhost.sh delete example.com ``` 添加数据库用户 ```shell sudo ./manage-db-users.sh add new_user new_password laravel_db ``` 删除数据库用户 ```shell sudo ./manage-db-users.sh delete new_user ``` 修改数据库用户密码 ```shell sudo ./manage-db-users.sh change-password new_user new_password ``` 备份数据库 ```shell sudo ./backup.sh db ``` 备份项目文件 ```shell sudo ./backup.sh project ``` 备份数据库和项目文件 ```shell sudo ./backup.sh all ``` 定时任务自动备份 ```shell crontab -e ``` 添加以下内容(每天凌晨 2 点备份) ```shell 0 2 * * * /path/to/backup.sh all ``` LNMP 状态管理命令 启动命令 | 停止命令 | 重启命令 | 查看状态命令 ```bash # Nginx sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl status nginx sudo nginx -t # 检查配置 sudo systemctl reload nginx # 重载配置 # PHP-FPM sudo systemctl start php{version}-fpm sudo systemctl stop php{version}-fpm sudo systemctl restart php{version}-fpm sudo systemctl status php{version}-fpm # MySQL sudo systemctl start mysql sudo systemctl stop mysql sudo systemctl restart mysql sudo systemctl status mysql # Redis sudo systemctl start redis sudo systemctl stop redis sudo systemctl restart redis sudo systemctl status redis ``` ```bash # Supervisorctl sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start "laravel-worker:*" sudo supervisorctl status ``` 确保以下服务正常运行: ```shell laravel-worker:* laravel-reverb:* laravel-horizon:* ``` Horizon 仪表盘:http://your-domain/horizon Pulse 仪表盘:http://your-domain/pulse 清除缓存 ```shell php artisan optimize:clear ```