dg / ftp-deployment
一款用于自动将Web应用程序部署到FTP服务器的工具。
Requires
- php: >=8.0
- ext-zlib: *
- phpseclib/phpseclib: ^3.0
Requires (Dev)
- nette/tester: ^2.0
- phpstan/phpstan: ^0.12
Suggests
- ext-ftp: to connect to ftp:// server
- ext-json: to preprocess CSS files via online service
- ext-openssl: to connect to ftps:// server and preprocess CSS files
- ext-ssh2: to connect to sftp:// server
This package is auto-updated.
Last update: 2024-09-09 03:03:01 UTC
README
FTP部署是一个用于自动将应用程序部署到FTP服务器的工具。
没有什么比手动上传Web应用程序到FTP服务器更糟糕的了,比如使用Total Commander这样的工具。(尽管,直接在服务器上编辑文件并尝试保持某种同步甚至更糟糕 ;-)
一旦过程自动化,你只需要很少的时间,并且最大限度地减少了错误的风险(我忘记上传某些文件了吗?)。现在有很多高级部署技术可用,但许多人仍在使用FTP。这个工具是为他们设计的。
支持我
你喜欢FTP部署吗?你在期待新功能吗?
谢谢!
它的工作原理
FTP部署是一个用PHP编写的脚本,将自动处理整个过程。只需指定要上传的本地文件夹和上传位置。这些信息存储在deployment.ini
文本文件中,您可以将其与deployment
脚本关联起来,这样部署就变成了一键操作。
php deployment deployment.ini
那么deployment.ini
文件包含什么呢?只需要remote
项,其他都是可选的
; log file (defaults to config file with .log extension) log = ... ; directory for temporary files (defaults to system's temporary directory) tempDir = /temp/deployment ; enable colored highlights? (defaults to autodetect) colors = yes [my site] ; Optional section (there may be more than one section). ; remote FTP server remote = ftp://user:secretpassword@ftp.example.com/directory ; you can use ftps://, sftp://, file:// or phpsec:// protocols (sftp requires SSH2 extension; phpsec uses phpseclib library) ; do not like to specify user & password in 'remote'? Use these options: user = ... password = ... ; FTP passive mode passiveMode = yes ; local path (optional) local = . ; run in test-mode? (can be enabled by option -t or --test) test = no ; files and directories to ignore ignore = " .git* project.pp[jx] /deployment.* /log temp/* !temp/.htaccess " ; explicit list of files and directories to include (by default includes all files and directories) include = " /app /app/* /index.php " ; is allowed to delete remote files? (defaults to yes) allowDelete = yes ; jobs to run before uploading ; local jobs are done even if there is no need for synchronization before[] = local: git diff-index --quiet HEAD ; ensures Git working directory is clean before[] = local: composer install --no-dev --classmap-authoritative ; installs production vendor before[] = local: lessc assets/combined.less assets/combined.css before[] = http://example.com/deployment.php?before ; jobs to run after uploading and before uploaded files are renamed afterUpload[] = http://example.com/deployment.php?afterUpload ; directories to purge after uploading purge[] = temp/cache ; jobs to run after everything (upload, rename, delete, purge) is done ; local jobs are done even if the synchronization did not take place after[] = remote: unzip api.zip after[] = remote: chmod 0777 temp/cache ; change permissions after[] = upload: config.server.neon app/config.local.neon after[] = http://example.com/deployment.php?after after[] = local: git reset HEAD --hard ; reverts all changes in working directory ; files to preprocess (defaults to none) preprocess = *.js *.css ; file which contains hashes of all uploaded files (defaults to .htdeployment) deploymentFile = .deployment ; default permissions for new files (defaults to none) filePermissions = 0644 ; default permissions for new directories (defaults to none) dirPermissions = 0755
在配置文件中,您可以创建多个部分(如[my site]
),这样您可以为数据和应用程序分别设置不同的规则。
配置还可以存储在一个PHP文件中。
在测试模式(带有-t
选项)中,上传或删除文件将被跳过,因此您可以使用它来验证您的设置。
项ignore
使用与.gitignore
类似的格式
log - ignore all 'log' files or directories in all subfolders
/log - ignore 'log' file or directory in the root
app/log - ignore 'log' file or directory in the 'app' in the root
data/* - ignore everything inside the 'data' folder, but the folder will be created on FTP
!data/db/file.sdb - make an exception for the previous rule and do not ignore file 'file.sdb'
project.pp[jx] - ignore files or folders 'project.ppj' and 'project.ppx'
在上传开始前、完成后以及所有任务完成后,您可以在服务器上执行命令或调用您的脚本(请参阅before
、afterUpload
、after
),例如,将服务器切换到维护模式。如果您使用PHP配置,则可以运行带有部署环境的lambda函数
<?php return [ 'remote' => 'ftp://user:secretpassword@ftp.example.com/directory', 'local' => '.', 'before' => [ function (Deployment\Server $server, Deployment\Logger $logger, Deployment\Deployer $deployer) { ... do something }, ], ... ];
同步大量文件尝试在(类似于)事务中运行:所有文件都以.deploytmp
扩展名上传,然后快速重命名。
将一个.htdeployment
文件上传到服务器,其中包含所有文件的MD5散列,用于同步。因此,下次您运行deployment
时,只有已修改的文件会被上传,而删除的文件将从服务器中删除(如果它不是由allowDelete
指令禁止的)。
上传的文件可以由预处理程序处理。这些规则是预定义的:.css
文件使用clean-css进行压缩,而.js
文件则通过Node.js工具使用UglifyJS或UglifyES进行压缩(两者均通过Node.js工具)。
还有一个用于展开mod_include Apache指令的规则。例如,您可以创建一个文件combined.js
<!--#include file="jquery.js" -->
<!--#include file="jquery.fancybox.js" -->
<!--#include file="main.js" -->
此工具将合并脚本并将它们与Closure Compiler一起压缩,以加快您的网站速度。
安装FTP部署
FTP Deployment 3.6需要PHP 8.0或更高版本。它还需要openssl扩展用于ftps://连接和SSH2扩展用于sftp://连接。
获取FTP Deployment的最简单方法是下载单个PHAR文件。
如果您想使用压缩功能,请安装Node.js、用于JavaScript压缩的UglifyJS 3以及用于CSS压缩的clean-css。
npm install uglify-js -g
npm install clean-css-cli -g
或者您可以使用Composer进行安装。
composer create-project dg/ftp-deployment
您在寻找php_ssh2.dll吗?
您需要使用公钥进行SSH认证吗?
publicKey = '/key/id_rsa.pub'
privateKey = '/key/id_rsa'
passPhrase = 'yourpass' #optional - If needed passphrase for privateKey