jsefton / laravel-remote-deploy
直接从 Artisan 将 Laravel 网站部署到远程服务器
dev-master
2019-02-14 20:25 UTC
Requires
- laravel/framework: 5.3.* | 5.4.* | 5.5.* | 5.6.* | 5.7.*
- laravelcollective/remote: ^5.4
This package is auto-updated.
Last update: 2024-09-18 01:16:20 UTC
README
此包允许您定义远程服务器和目录,然后可以通过简单的命令直接从本地推送更改。
它允许您将命令分组到任务中,以便可以在远程服务器上轻松运行。这可以用于部署、配置、健康检查等等。
安装
您需要 composer 来安装此包(获取 composer)。然后运行
composer require jsefton/laravel-remote-deploy
注册服务提供者
将以下内容添加到您的 config/app.php
文件中的 providers
数组
Jsefton\LaravelRemoteDeploy\LaravelRemoteDeployProvider::class
安装后,您需要发布配置文件,这将允许您指定自己的环境列表。为此,请运行
php artisan vendor:publish --tag=laravel-remote-deploy
这将创建一个 config/laravel-remote-deploy.php
文件,您可以在此配置您的环境列表。
配置
在 config/laravel-remote-deploy.php
中,您将拥有两组配置。
这包括 servers
,这是一个您想要创建和连接的所有可能的连接数组。
这还包括一组 tasks
,您可以从中选择运行。它可以包含多个命令和文件上传功能。以下是一个设置和部署的示例配置
'setup' => [ 'directory' => '/', 'commands' => [ "ssh-keygen -f ~/.ssh/id_rsa -t rsa -N '' " => [ 'confirm' => 'Do you want to create an ssh key' ], 'cat ~/.ssh/id_rsa.pub', 'cd /var/www/html', 'git clone' => [ 'confirm' => 'Have you installed your ssh key with the repository yet?', 'prompt' => 'Please enter a url for the git repository' ] ] ], 'deploy' => [ 'directory' => '/var/www/html', 'commands' => [ 'cd' => [ 'prompt' => 'Please enter a folder name of the site' ], 'git pull origin master' ] ]
用法
在 CLI 中运行以下命令以执行命令并开始提示
php artisan remote:tasks
要清除临时文件中的任何存储凭证,请运行
php artisan remote:clear
TODO
- 包含 Migrate Environments 包以允许在部署时轻松更新数据库
- 添加在多台服务器上运行相同任务的能力
配置任务
此功能目前正在开发中
通过在您的任务配置中添加以下内容,它将允许您配置基本的 LEMP 栈
'reboot' => [ 'directory' => '/', 'commands' => [ 'reboot' ] ], 'provision' => [ 'directory' => '/', 'commands' => [ 'sudo apt-get update', 'sudo apt-get install nginx -y', 'sudo apt-get install mysql-server -y', 'sudo apt-get install php-fpm php-mysql -y' ], 'files' => [ [ 'path' => '/etc/nginx/sites-available/default', 'content' => 'server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; server_name server_domain_or_IP; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }', 'after' => [ 'sudo nginx -t', 'sudo systemctl reload nginx' ] ] ] ]