简体   繁体   English

用git和php开发(web开发)

[英]development with git and php (web development)

I'm struggling with the best approach to test php development code which is dependent on certain framework files to be present. 我正在努力尝试测试php开发代码的最佳方法,该代码依赖于某些框架文件。 I think there are three possible scenario's with git: 我认为git有三种可能的情况:

  • Create a copy of the live production directory and clone this 'dev' directory to the local workstation. 创建实时生产目录的副本,并将此“dev”目录克隆到本地工作站。 The next step would be to edit code on the local workstation and commit/push every change. 下一步是编辑本地工作站上的代码并提交/推送每个更改。 You can check your work via the 'dev' url on the production server. 您可以通过生产服务器上的“dev”URL检查您的工作。 If everything is alright you can push the changes to the 'live' directory. 如果一切正常,您可以将更改推送到“实时”目录。 This approach may result in a lot of commits as you are editing/fixing your code (syntax errors or other obvious mistakes) and it adds an extra step (commit/push) to see your result. 在编辑/修复代码时(语法错误或其他明显的错误),这种方法可能会导致很多提交,并且会增加额外的步骤(提交/推送)以查看结果。

  • Create a 'dev' server which mirrors the production server. 创建一个镜像生产服务器的“dev”服务器。 This server will contain all the framework files and you'll be able to edit a copy of the 'live' directory directly and immediately see your changes. 此服务器将包含所有框架文件,您将能够直接编辑“实时”目录的副本,并立即查看您的更改。 If you prefer you can mount the remote 'dev' directory to your local workstation. 如果您愿意,可以将远程“dev”目录安装到本地工作站。 This requires an extra server which needs to be maintained and you would need the resources to set it up. 这需要额外的服务器,需要维护,您需要资源来设置它。

  • Create a local 'dev' workstation environment and clone the repository on the 'live' or 'dev' server. 创建本地“dev”工作站环境并在“live”或“dev”服务器上克隆存储库。 This way you'll be able to test all the code on your local machine and only push out the commits which have been tested and approved. 这样,您就可以测试本地计算机上的所有代码,只推出已经过测试和批准的提交。 This reduces the number of commits as opposed to method one. 与方法一相反,这减少了提交次数。 To recreate the 'dev' environment locally you might have to install a lot framework/dependent files to your local workstation and even then it might not be 100% reliable when the code is ported to the actual live server. 要在本地重新创建“dev”环境,您可能必须在本地工作站上安装很多框架/相关文件,即使这样,当代码移植到实际的实时服务器时,它可能也不是100%可靠。

Basically I want to find the best method for the 'write-test-revise-test-revise-test-commit' cycle if you are dependent on framework files (whatever framework that may be). 基本上我想找到'write-test-revise-test-revision-test-commit'循环的最佳方法,如果你依赖于框架文件(可能是任何框架)。 Would you create a 'dev' server or would you recreate the exact production environment on your local workstation? 你会创建一个'dev'服务器,还是会在本地工作站上重新创建确切的生产环境? Ideally you would only commit the code when you have done some initial testing (obvious syntax errors etc.). 理想情况下,只有在完成一些初始测试(明显的语法错误等)后才会提交代码。 A 'dev' server with local git repo would require that you commit every little change to test your work which may be tedious.... 一个带有本地git repo的'dev'服务器需要你提交每一个小改动来测试你的工作,这可能是乏味的....

I hope I have made myself clear. 我希望我已经说清楚了。 I'm looking for the best way to integrate git and the 'write-test-commit' cycle. 我正在寻找集成git和'write-test-commit'循环的最佳方法。 Normally you would test on the local machine but with web development you may need a webserver + framework to be able to test your code. 通常,您将在本地计算机上进行测试,但通过Web开发,您可能需要一个Web服务器+框架才能测试您的代码。 Editing directly on the 'live' server is what I want to avoid. 直接在“实时”服务器上编辑是我想要避免的。

Thanks for your input! 感谢您的输入!

Call me opinionated, but every developer should have a local development AMP stack which they can develop against. 叫我自以为是,但每个开发人员都应该有一个他们可以开发的本地开发AMP堆栈。 If you don't know how to set up an exact mirror of your production server, solve that problem first. 如果您不知道如何设置生产服务器的精确镜像,请首先解决该问题。

Once you're there, it should be trivial to have each developer set up a virtual machine with a clean OS install, configure web/php/db servers and libraries/framewroks to match the production environment, check out your project, and get to work. 一旦你在那里,让每个开发人员设置一个干净的OS安装的虚拟机,配置web / php / db服务器和库/ framewroks以匹配生产环境,检查你的项目,然后到达它应该是微不足道的。工作。

Developers commit against personal branches in their own local repos as they go, and after local testing, ship their code (via either a push, or a pull request, or whatever). 开发人员在他们自己的本地存储库中提交个人分支,并在本地测试之后,发送他们的代码(通过推送或拉取请求,或其他)。

The exact rules about how to merge changes into master depend on your team an preferences. 有关如何将更改合并到主服务器的确切规则取决于您的团队的首选项。 But developers should almost always have a complete local dev environment. 但开发人员应该几乎总是拥有完整的本地开发环境。 If it seems like it's hard to set one up, that's a big problem. 如果看起来很难设置一个,这是一个大问题。 Figure out how to make it easy and then document it. 弄清楚如何使它变得简单然后记录它。

There are definitely many ways to do this, but here is my 2 cents from how I have been working lately. 肯定有很多方法可以做到这一点,但这是我最近工作的2美分。

First off, I would probably avoid a dev server per se, because if you have more than 1 developer, each developer may try to update the dev server with conflicting code, or if they are working on similar areas, overwrite some of your test code since you both probably are working from the same branch but have both modified the code and not yet pushed the changes. 首先,我可能会避免开发服务器本身,因为如果你有超过1个开发人员,每个开发人员可能会尝试使用冲突的代码更新开发服务器,或者如果他们正在处理类似的区域,则覆盖一些测试代码既然你们两个都可能在同一个分支机构工作,但都修改了代码并且还没有推动更改。

That said, you may want a dev server that closely resembles your live server so that after you and some of your other developers have made a number of changes, you can test them on the dev server before updating the code on the live server. 也就是说,您可能需要一个与您的实时服务器非常相似的开发服务器,以便在您和其他一些开发人员进行了一些更改之后,您可以在更新实时服务器上的代码之前在开发服务器上测试它们。

In my environment, I develop on Linux and have Apache/PHP running the same versions and configs as the live server. 在我的环境中,我在Linux上开发并使Apache / PHP运行与实时服务器相同的版本和配置。 This way, I clone my git repo, have my environment set up so that my document root is the "public" directory of my git repo (eg htdocs). 这样,我克隆了我的git repo,设置了我的环境,以便我的文档根目录是我的git repo的“公共”目录(例如htdocs)。 In this case, we have a dev MySQL server which is usually shared, and not on the local machine, but you can do whatever is easiest there. 在这种情况下,我们有一个开发MySQL服务器,它通常是共享的,而不是在本地机器上,但你可以做任何最简单的事情。 Our system depends on constantly updated data from the field so this is why the shared database, we have a system which adds a lot of this necessary "test" data automatically to the database. 我们的系统依赖于来自现场的不断更新的数据,所以这就是共享数据库的原因,我们有一个系统可以自动将大量这些必要的“测试”数据添加到数据库中。

This way, I can pull the latest code from git, work on it all I want, work-break-fix-work-work-work etc etc and when I have completed my task, I can push the changes back to git for other developers. 通过这种方式,我可以从git中提取最新的代码,完成我想要的工作,工作 - 修复 - 工作 - 工作 - 工作等等,当我完成任务时,我可以将更改推回到git for other开发人员。

When you are ready for a release, you can do all of your testing and stuff on the dev server, verify it is good to go and then push to the live. 当你准备好发布时,你可以在开发服务器上完成所有的测试和工作,验证它是好的,然后推送到实时。

In my case for updating the "live" server, one person is responsible for that, and I use rsync to sync my local working directory to the live server. 在我更新“实时”服务器的情况下,一个人负责,我使用rsync将我的本地工作目录同步到实时服务器。 So when I am absolutely sure we are ready to deploy, I pull the most recent code from git, and run my script which rsyncs my git directory to the server. 因此,当我完全确定我们已准备好部署时,我从git中提取最新的代码,并运行我的脚本,其中rsyncs我的git目录到服务器。

I'd avoid your methods 1 & 2, and go with something like 3. That will probably be the sanest thing for you to do and easiest to manage. 我会避免使用你的方法1和2,并使用类似于3的方法。这可能是你做的最容易管理的事情。 Depending on what your team is like, you could create a dev VM that is pre-built with all the dependencies, correct software, and development tools you are all using, or leave it up to the developer to set themselves up. 根据您的团队的需要,您可以创建一个预先构建的开发虚拟机,其中包含您正在使用的所有依赖项,正确的软件和开发工具,或者让开发人员自行设置。

So far this method has worked pretty well for me and the others on my team. 到目前为止,这种方法对我和我团队中的其他人来说非常有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM