您首选的 php 部署策略是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/425692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is your preferred php deployment strategy?
提问by GloryFish
I'm beginning a new project in PHP and I'd love to get some feedback from other developers on their preferred strategy for PHP deployment. I'd love to automate things a bit so that once changes are committed they can be quickly migrated to a development or production server.
我正在开始一个 PHP 新项目,我很想从其他开发人员那里得到一些关于他们首选的 PHP 部署策略的反馈。我很想将事情自动化一点,这样一旦提交更改,它们就可以快速迁移到开发或生产服务器。
I have experience with deployments using Capistrano with Ruby as well as some basic shell scripting.
我有使用 Capistrano 和 Ruby 进行部署的经验以及一些基本的 shell 脚本。
Before I dive head first on my own it would be great to hear how others have approached this in their projects.
在我自己第一次潜水之前,很高兴听到其他人如何在他们的项目中解决这个问题。
Further information
更多信息
Currently developers work on local installations of the site and commit changes to a subversion repository. Initial deployments are made by exporting a tagged release from svn and uploading that to the server.
目前,开发人员致力于站点的本地安装并将更改提交到 subversion 存储库。初始部署是通过从 svn 导出标记版本并将其上传到服务器来进行的。
Additional changes are typically made piecemeal by manually uploading changed files.
其他更改通常是通过手动上传更改的文件来逐步完成的。
采纳答案by Eran Galperin
For PHP, SVN with Phingbuild scripts are the way to go. Phing is similar to ANTbut is written in PHP, which makes it much easier for PHP developers to modify for their needs.
对于 PHP,带有Phing构建脚本的SVN 是可行的方法。Phing 类似于ANT,但它是用 PHP 编写的,这使得 PHP 开发人员可以更轻松地根据需要进行修改。
Our deployment routine is as follows:
我们的部署例程如下:
- Everyone develops on the same local server at work, every developer has a checkout on his machine back home as well.
- Commits trigger a post-commit hook which updates a staging server.
- Tests are ran on staging server, if they pass - continue.
- Phing build script is ran:
- Takes down production server, switching the domain to an "Under construction" page
- Runs SVN update on production checkout
- Runs schema deltas script
- Runs tests
- If tests fail - run rollback script
- If tests pass, server routes back to production checkout
- 每个人在工作时都在同一个本地服务器上开发,每个开发人员在他家的机器上也有一个结账。
- 提交触发一个 post-commit 钩子,它更新一个临时服务器。
- 测试在登台服务器上运行,如果它们通过 - 继续。
- 运行 Phing 构建脚本:
- 关闭生产服务器,将域切换到“正在建设中”页面
- 在生产结账时运行 SVN 更新
- 运行模式增量脚本
- 运行测试
- 如果测试失败 - 运行回滚脚本
- 如果测试通过,服务器路由回生产结帐
There's also phpUnderControl, which is a Continuous Integration server. I didn't find it very useful for web projects to be honest.
还有phpUnderControl,它是一个持续集成服务器。老实说,我没有发现它对网络项目很有用。
回答by Kyle Cronin
I'm currently deploying PHP using Git. A simple git push production is all that's needed to update my production server with the latest copy from Git. It's easy and fast because Git's smart enough to only send the diffs and not the whole project over again. It also helps keep a redundant copy of the repository on the web server in case of hardware failure on my end (though I also push to GitHub to be safe).
我目前正在使用 Git部署 PHP 。使用来自 Git 的最新副本更新我的生产服务器只需要一个简单的 git push 生产。这既简单又快速,因为 Git 足够聪明,可以只发送差异,而不是再次发送整个项目。它还有助于在 Web 服务器上保留存储库的冗余副本,以防万一我这边出现硬件故障(尽管我也推送到 GitHub 以确保安全)。
回答by Martijn Heemels
We use Webistrano, a web frontend for Capistrano, and are very happy with it.
我们使用Webistrano,这是 Capistrano 的网络前端,并且对它非常满意。
Webistrano allows multi-stage, multi-environment deployments from SVN, GIT and others. It has built-in rollback support, support for separate server roles such as web, db, app, etc., and deploys in parallel. It allows you to override config parameters on multiple levels, such as per stage, and logs the results of every deploy, optionally mailing it.
Webistrano 允许来自 SVN、GIT 等的多阶段、多环境部署。内置回滚支持,支持web、db、app等独立服务器角色,并行部署。它允许您在多个级别(例如每个阶段)覆盖配置参数,并记录每个部署的结果,并可选择将其邮寄。
Even though Capistrano and Webistrano are Ruby applications, the syntax of the deployment 'recipes' is easy and powerful enough to understand for any PHP programmer. Originally Capistrano was built for Ruby on Rails projects, but easily accommodates PHP projects.
尽管 Capistrano 和 Webistrano 是 Ruby 应用程序,部署“食谱”的语法对于任何 PHP 程序员来说都足够简单且强大,足以理解。最初 Capistrano 是为 Ruby on Rails 项目构建的,但很容易适应 PHP 项目。
Once configured it is even easy enough to be used by non-programmers, such as testers deploying a staging version.
一旦配置完成,它甚至可以很容易地被非程序员使用,例如部署临时版本的测试人员。
To provide the fastest deploy possible we installed the fast_remote_cachemethod, which updates a svn working-copy cache on the remote server, and then hardlinks the result.
为了提供最快的部署,我们安装了fast_remote_cache方法,它更新远程服务器上的 svn 工作副本缓存,然后硬链接结果。
回答by notneilcasey
I use Apache Antto deploy to different targets (dev, QA and live). Ant is designed to work for Java deployment, but it provides a pretty useful general case solution for deploying arbitrary files.
我使用Apache Ant部署到不同的目标(开发、QA 和实时)。Ant 旨在用于 Java 部署,但它为部署任意文件提供了非常有用的通用案例解决方案。
The syntax of the build.xml file is pretty easy to learn - you define different targets and their dependencies which run when you call the ant program on the command line.
build.xml 文件的语法非常容易学习 - 您可以定义不同的目标及其依赖项,当您在命令行上调用 ant 程序时,它们会运行。
For example, I have targets for dev, QA and live, each of which depends on the cvsbuild target which checks out the latest head revision from our CVS server, copies the appropriate files to the build directory (using the fileset tag), and then rsyncs the build directory to the appropriate server. There are a few quirks to learn, and the learning curve is not totally flat, but I've been doing it this way for years with no trouble so I'd recommend it for your situation, though I'm curious what other answers I'll see on this thread.
例如,我有 dev、QA 和 live 的目标,每个目标都依赖于 cvsbuild 目标,它从我们的 CVS 服务器中检出最新的头版修订,将适当的文件复制到构建目录(使用文件集标签),然后将构建目录同步到适当的服务器。有一些怪癖需要学习,学习曲线并不完全平坦,但我多年来一直这样做,没有遇到任何问题,所以我会根据您的情况推荐它,尽管我很好奇我还有什么其他答案会在这个线程上看到。
回答by notneilcasey
I do stuff manually using Git. One repository for development, which gets git push --mirror'ed to a public repo, and the live server is a third repo pulled from that. This part I suppose is the same as your own setup.
我使用 Git 手动操作。一个用于开发的存储库,它被git push --mirror转到公共存储库,而实时服务器是从中提取的第三个存储库。我想这部分与您自己的设置相同。
The big difference is that I use branches for nearly every change I'm working on (I've got about 5 right now), and tend to flip back and forth between them. The master branch doesn't get changed directly except for merging other branches.
最大的不同是我几乎对我正在处理的每个更改都使用分支(我现在大约有 5 个),并且倾向于在它们之间来回切换。除了合并其他分支外,主分支不会直接更改。
I run the live server direct from the master branch, and when I'm finished with another branch and ready to merge it, flip the server to that branch for a while. If it breaks, putting it back to master takes seconds. If it works, it gets merged into master and the live code gets updated. I suppose an analogy of this in SVN would be having two working copies and pointing to the live one via a symlink.
我直接从主分支运行实时服务器,当我完成另一个分支并准备合并它时,将服务器翻转到该分支一段时间。如果它坏了,把它放回 master 需要几秒钟。如果它有效,它就会合并到 master 中,并且实时代码得到更新。我想在 SVN 中的类比是有两个工作副本并通过符号链接指向实时副本。
回答by dragonmantank
I know Phinghas been mentioned a few times now, but I've had great luck with phpUnderControl. For us we
我知道Phing现在已经被提到过几次了,但是我在phpUnderControl 上很幸运。对于我们我们
- Check out individual copies of branches to local machines
- Branches are tested and then merged into Trunk
- Commits to Trunk are automatically built by phpUnderControl, runs tests and builds all documentation, applies database deltas
- Trunk gets run through quality testing and then merged into our Stable branch
- Again, phpUnderControl automatically builds Stable, runs tests, and generates documenation and updates database
- When we're ready to push to production we run a rsync script that backs up Production, updates the database, and then pushes the files up. The rsync command is invoked by hand so that we make sure someone is watching the promotion.
- 将分支的各个副本检出到本地机器
- 测试分支,然后合并到 Trunk
- Commits to Trunk 由 phpUnderControl 自动构建,运行测试并构建所有文档,应用数据库增量
- Trunk 通过质量测试,然后合并到我们的稳定分支
- 同样,phpUnderControl 自动构建稳定版,运行测试,并生成文档和更新数据库
- 当我们准备好推送到生产时,我们运行一个 rsync 脚本来备份生产,更新数据库,然后推送文件。rsync 命令是手动调用的,以便我们确保有人正在观看促销活动。
回答by Solomon Hykes
an alternative to home-made deployment scripts is to deploy to a platform-as-a-service which abstracts away a lot of that work for you. A PaaS will typically offer its own code deployment tool, as well as scaling, fault-tolerance (eg. not going down when hardware fails), and usually a great toolkit for monitoring, log checking etc. There's also the benefit of deploying to a known good configuration which will be kept up-to-date over time (one less headache for you).
自制部署脚本的替代方案是部署到平台即服务,它为您提取了大量工作。PaaS 通常会提供自己的代码部署工具,以及可伸缩性、容错性(例如,当硬件出现故障时不会停机),并且通常是用于监控、日志检查等的出色工具包。已知的良好配置将随着时间的推移保持最新(让您少一些头痛)。
The PaaS I would recommend is dotCloud, in addition to PHP (see their PHP quickstart) it can also deploy MySQL, MongoDB and a whole bunch of additional services. It also has nice goodies like zero-downtime deployment, instant rollback, full support for SSL and websocket, etc. And there's a free tier which is always nice :)
我推荐的 PaaS 是dotCloud,除了 PHP(请参阅他们的 PHP 快速入门)之外,它还可以部署 MySQL、MongoDB 和一大堆附加服务。它还具有很好的优点,例如零停机部署、即时回滚、对 SSL 和 websocket 的完全支持等。还有一个总是很好的免费层:)
Of course I'm slightly biased since I work there! Other options worth checking out in addition to dotCloud are Pagodabox and Orchestra (now part of Engine Yard).
当然,因为我在那里工作,所以我有点偏见!除了 dotCloud 之外,其他值得一试的选项是 Pagodabox 和 Orchestra(现在是 Engine Yard 的一部分)。
Hope this helps!
希望这可以帮助!
Solomon
所罗门
回答by Clint
I am way late to the party, but I thought I would share our methods. We use Phing with Phingistrano, which provides Capistrano-like functionality to Phing via pre-built build files. It is very cool, but only works if you use Git at the moment.
我参加聚会很晚,但我想我会分享我们的方法。我们将 Phing 与Phingistrano一起使用,它通过预构建的构建文件为 Phing 提供类似 Capistrano 的功能。它非常酷,但只有在您目前使用 Git 时才有效。
回答by Henrik Paul
That you automatically and blindly take changes from a repository to production servers sounds dangerous. What if your committed code contains a regression bug, so your production application gets glitchy?
您自动且盲目地将更改从存储库更改为生产服务器听起来很危险。如果您提交的代码包含回归错误,那么您的生产应用程序会出现故障怎么办?
But, if you want a Continuous Integration system for PHP, I guess Phingis the best choice for PHP. I haven't tested it myself, though, as I do stuff the manual way of e.g. scp.
但是,如果你想要一个 PHP 的持续集成系统,我猜Phing是 PHP 的最佳选择。不过,我自己还没有测试过,因为我使用手动方式(例如 scp)进行填充。
回答by Henrik Paul
I have a working copy of an SVN release branch on the server. Updating the site (when there aren't schema changes) is as easy as issuing an SVN update command. I don't even have to take the site offline.
我在服务器上有一个 SVN 发布分支的工作副本。更新站点(当没有架构更改时)就像发出 SVN 更新命令一样简单。我什至不必让网站脱机。

