设置PHP Web项目,基础设施 [英] Setting up a PHP web project, the infrastructure

查看:82
本文介绍了设置PHP Web项目,基础设施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何最好地设置我的PHP(LAMP)开发环境,以便我有开发,分期和生产服务器。单击点击部署到任何一个,以及一键回滚到任何修订版本。回滚应该还可以将数据库模式和数据回滚到当前源代码的时候。



现在我完成了所有这些(除了数据库回滚能力)为一个应用程序使用shell脚本。我很好奇地知道别人的环境是如何设置的,如果有任何通用的工具或最佳做法就可以在布局方面进行跟踪。





谢谢!



更新:只是为了澄清,因为有一些



我真的希望人们知道他们的环境如何设置。



如果您运行一个PHP项目,并且您的DB模式在版本控制中,那么您如何做?你使用什么工具?他们在内部还是我们都可以在某个地方找到他们?



如果您运行一个PHP项目,并且自动测试提交(和/或夜间) , 你怎么做呢?你使用什么源版本控制系统?您是否使用SVN并在后提交钩子中运行测试?



如果您使用多个dev服务器,分段服务器和生产服务器运行PHP项目,你如何组织他们,如何部署?



我希望得到的是一个好主意,他们如何将所有东西都粘在一起。

解决方案

我们的生产环境包括以下内容:




  • 3前台服务我们的网站

  • 2数据库后端(主从,复制)

  • 1混合运行httpd和数据库以进行服务



我们的开发环境是一个运行数据库和httpd的单一服务器,配置方面我们为每个人设置不同的工作空间,我们的VC是颠覆。



数据库更改



最初,我们花费了大量的时间在数据库设计上,似乎真的有所回报。我们五个月以来没有任何改变。我们部署的大部分更改都在前端。现在,到目前为止,我手动对数据库进行了全部的修改,我总是写一个小的脚本来恢复。



如果我有更多的这个, a href =http://www.doctrine-project.org/ =nofollow noreferrer>教义和 Migrations 这里。我从来没有真正有机会在生产中使用它们,但是我已经广泛使用过它们,而且它们似乎非常强大。



部署



所以每当我们部署一个新版本,我们创建一个代码,我们检查出来的代码,然后通过几个检查列表等,然后我们在生产前端部署代码。为了进行所有部署,我在 Capistrano 中安装了几个任务。



查看此示例 capfile

 角色:web01,web02,web03
角色:web,web01,web02,web03,web04
角色:db,db01 db02

desc部署站点
task:deploy,:roles => :www do
runcd / usr / www / website&&sudo svn --username = deploy --password = foo update
end

Capistrano还允许您运行任何其他命令,而无需定义任务:

  cap调用COMMAND =正常运行时间ROLES = web 

(需要

编码样式和文档



我们几乎坚持 PEAR编码标准,我们使用 PHP_CodeSniffer (phpcs)进行检查。当我说了很多时,我的意思是我分发了提供的嗅觉,并添加了一些我自己的gusto的例外。



除了编码风格,phpcs检查内联文档以及。本文档最终由 phpDocumentor 创建。



CI



我在CI服务器(连续集成)中设置了这两个工具, phpUnderControl 使用上述和CruiseControl, phpUnit Xdebug (一对代码指标...)等。



单元测试是我们目前缺乏的。但是我们现在做的是,在我们的解析引擎(我们将文本解析为某些格式)中发现的每个错误,我们编写一个测试来确保它不会回来。我还编写了一些基本测试来检查URL路由和内部XMLRPC API,但这真的有待改进。我们同时使用phpUnit样式测试和 phpt



CI-server 每天几次新建一个版本,生成图形,文档和各种报告。



除了所提到的所有工具之外,我们还使用Google Apps(主要用于电子邮件),并将Google Sites wiki保留所有其他文档。例如,部署过程,QA测试列表等。


How can I best set up my PHP (LAMP) development environment so that I have development, staging and production servers. One-"click" deployment to any of those, as well as one-click rollback to any revision. Rollback should also rollback the database schema and data to how it was when that source code was current.

Right now I've done all of this (except the DB rollback ability) for one application using shell scripts. I'm curious to know how others' environments are setup, and also if there are any generic tools or best-practices out there to follow as far as layout is concerned.

So, how do you do this? What existing tools do you make use of?

Thanks!

UPDATE: Just to clarify as there is some confusion about what I'm interested in.

I really want people to chime in with how their environment is set up.

If you run a PHP project and you have your DB schema in version control, how do you do it? What tools do you use? Are they in-house or can we all find them on the web somewhere?

If you run a PHP project and you do automated testing on commit (and/or nightly), how do you do it? What source versioning system do you use? Do you use SVN and run your tests in post-commit hooks?

If you run a PHP project with multiple dev servers, a staging server and production server(s), how do you organize them and how do you deploy?

What I hope to get out of this is a good idea of how others glue everything together.

解决方案

Our production environment includes the following:

  • 3 frontends who serve our website
  • 2 database backends (Master-Slave, replication)
  • 1 mixed which runs httpd and database for adserving

Our development environment is a single server running both database and httpd, configuration-wise we have different workspaces for everyone setup and our VC is subversion. Staging is rather simple too - it runs on one of the frontends.

Database changes

Initially we spent a lot of time on the database design and it seems to have really paid off. We haven't changed anything major in five months now. Most of the changes we deploy are on the frontend. Now, so far we run all the changes to the database manually and I always wrote a small script to revert.

If I had more of those, I'd use Doctrine and Migrations here. I've never actually had the chance to use them in production but I've played with those extensively already and they seem very powerful.

Deployment

So whenever we deploy a new version we create a tag of the code which we check out on staging, then go through a couple lists of checks etc. and then we deploy the code on the production frontends. For doing all of the deployment, I have a couple tasks setup in Capistrano.

Check out this sample capfile:

role :www, "web01", "web02", "web03"
role :web, "web01", "web02", "web03", "web04"
role :db, "db01", "db02"

desc "Deploy sites"
task :deploy, :roles => :www do
    run "cd /usr/www/website && sudo svn --username=deploy --password=foo update"
end

Capistrano also allows you to run any other command without defining a task:

cap invoke COMMAND="uptime" ROLES=web

(Requires the role "web" to be setup. See example above.)

Coding style and documentation

We pretty much adhere to the PEAR Coding standard, which we check using PHP_CodeSniffer (phpcs). When I say pretty much, I mean that I forked the sniffs provided and added a few exceptions of my own gusto.

On top of coding style, phpcs checks on inline documentation as well. This documentation is created by phpDocumentor in the end.

CI

I have both of those tools setup in our CI-server (continuos-integration), which is phpUnderControl using the above and CruiseControl, phpUnit, Xdebug (a couple code metrics...), etc..

unit-testing is something we currently lack. But what we do right now is that with each bug we find in our parsing engine (we parse text into certain formats), we write a test to make sure it doesn't come back. I've also written some basic tests to check the URL-routing and the internal XMLRPC API but this is really subject to improvement. We employ both phpUnit-style tests and phpt as well.

The CI-server builds a new version a couple times per day, generates graphs, docs and all kinds of reports.

On top of all of the tools mentioned, we also use Google Apps (primarily for email) and keep a Google Sites wiki with all other documentation. For example, deployment procedure, QA test lists, etc..

这篇关于设置PHP Web项目,基础设施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆