简体   繁体   English

沙盒网站的最佳做法?

[英]Sandboxing website best practices?

I currently work in a web shop with almost no formal processes and a million PHP websites, including tricky stuff like custom CMS and shopping cart code. 我目前在网上商店工作,几乎没有正式流程和一百万个PHP网站,包括棘手的东西,如自定义CMS和购物车代码。

We are trying to improve things. 我们正在努力改善一切。 I am pushing for CVS/SVN. 我正在推动CVS / SVN。

My question is, what is the best practice for sandboxing website work? 我的问题是,沙盒网站工作的最佳做​​法是什么? We are on the LAMP stack. 我们在LAMP堆栈上。 Some of our sites have hardcoded (or user-inputted links) to the current domain, so setting up a different domain like preview.mysite.com will break links pointing to www.mysite.com. 我们的一些网站有当前域的硬编码(或用户输入的链接),因此设置一个不同的域,如preview.mysite.com将打破指向www.mysite.com的链接。 If we start applying regression tests, perhaps the domains should be uniform for testing? 如果我们开始应用回归测试,那么这些域应该是统一的测试? That can always be done with a local host entry. 这总是可以通过本地主机条目来完成。

So, considering we have lots of sites, it would be nice to have one process for always doing previewing in a proper sandbox. 因此,考虑到我们有很多站点,最好有一个进程来始终在适当的沙箱中进行预览。 Wondering how this would integrate with an SVN/CVS cycle. 想知道这将如何与SVN / CVS循环集成。

I am just looking for industry best practices because we are trying to get there. 我只是在寻找行业最佳实践,因为我们正努力实现这一目标。 If that means cloning a site to an extra server, so be it. 如果这意味着将站点克隆到额外的服务器,那就这样吧。

So yes, you should have a second STAGE server. 所以是的,你应该有第二个STAGE服务器。 What I do is put my code into CVS on my dev box, and do regular commits as i go along. 我所做的是将我的代码放入我的开发盒中的CVS,并在我进行时定期提交。 When I am ready to push a version to the "STAGE" server, I go through the files I want to STAGE and tag them STAGE: 当我准备将版本推送到“STAGE”服务器时,我会浏览我想要STAGE的文件并将它们标记为STAGE:

cvs tag -F STAGE cvs标签-F STAGE

Then I go to the STAGE server and do an update with the STAGE flag to get the STAGE version of files: 然后我转到STAGE服务器并使用STAGE标志进行更新以获取STAGE版本的文件:

cvs up -r STAGE cvs up -r STAGE

This also sets the sticky tag to be "STAGE" on those files, so in the future, I can just leave the STAGE tag off when I do updates on my stage server: 这也将粘性标记设置为这些文件的“STAGE”,因此将来我可以在我的舞台服务器上进行更新时关闭STAGE标记:

cvs up cvs up

finally, when I've tested my code on the STAGE server, I roll it to the production server using rsync... 最后,当我在STAGE服务器上测试我的代码时,我使用rsync将其滚动到生产服务器...

We have several developers working together so keeping a stable STAGE version up can get tricky. 我们有几个开发人员一起工作,因此保持稳定的STAGE版本可能会变得棘手。 In that case, if I just have small changes to one or two files, I will just scp them individually over to the production server.. 在这种情况下,如果我只对一个或两个文件进行小的更改,我将把它们单独scp到生产服务器上。

Finally, to ensure I know what is out on my production servers, after I send a file or files off to the production server, I tag all the files on my stage server as RELEASE, and also as RELEASE20090713 or whatever the current date is.. That way I have moving snapshots though time that I can get if needed. 最后,为了确保我知道生产服务器上的内容,在将文件或文件发送到生产服务器之后,我将我的舞台服务器上的所有文件标记为RELEASE,以及RELEASE20090713或当前日期。这样我就可以在需要的时候通过时间移动快照。 Note though, this doesn't update the sticky tag, so my regular old 请注意,这不会更新粘性标签,所以我的常规旧

cvs up cvs up

on the stage server still gets me the latest STAGE files. 在舞台服务器上仍然获取最新的STAGE文件。

Now in your case, as far as the hardcoded URL's goes... You already know.. bad bad bad... so fix them as you go... But you may be able to use apache URL rewriting to rewrite URL's on STAGE to talk to a custom TCP port. 现在就你的情况而言,就硬编码的网址而言......你已经知道......糟糕的坏事......所以你要去修理它们......但是你可以使用apache URL重写来重写STAGE上的URL与自定义TCP端口通信。

If you have a smart network device like a cisco router, you can set it up to do PAT (port address translation) for your IP's. 如果您有像cisco路由器这样的智能网络设备,则可以将其设置为为您的IP执行PAT(端口地址转换)。 Port 80 can forward to your regular production webserver, and port 8080 can forward to your STAGE server (its port 80).. Then all you do is have apache do URL rewriting on your STAGE server and append 8080 to all the hostnames it sees. 端口80可以转发到您的常规生产网络服务器,端口8080可以转发到您的STAGE服务器(其端口80)..然后您所做的就是让您的STAGE服务器上的URL重写URL并将8080附加到它看到的所有主机名。 Now all your posts and links will go to the correct STAGE servers, and your apache configs can be exactly the same also. 现在,您的所有帖子和链接都将转到正确的STAGE服务器,您的apache配置也可以完全相同。

Regarding the hard coded (or user-inputted) domain names: you could add the domains to your hosts file . 关于硬编码(或用户输入的)域名:您可以将域添加到主机文件中 That should solve your problems during development and preview. 这应该可以在开发和预览期间解决您的问题。 Your browser will retrieve the IP for www.mysite.com and find 127.0.0.1 or the IP of the preview site in the hosts file. 您的浏览器将检索www.mysite.com的IP并在hosts文件中找到127.0.0.1或预览站点的IP。 The tricky part is that just by looking at the URL in the browser, you cannot determine whether you are looking at the production site or not. 棘手的部分是,只是通过查看浏览器中的URL,您无法确定是否正在查看生产站点。 (The ShowIP addon for Firefox can help you here.) 适用于Firefox的ShowIP插件可以在这里为您提供帮助。)

Regarding CVS/SVN: I would really advice you to go for SVN. 关于CVS / SVN:我真的建议你去SVN。 It's not harder to use than CSV but has some advantages (eg renaming is possible). 它比CSV更难使用但具有一些优点(例如可以重命名)。 For more information see eg this question . 有关更多信息,请参阅此问题

As for the previewing in a sandbox, this is what we do: we do most of our development on trunk (or on a branch, but the rest of the process is almost the same). 至于沙盒中的预览,这就是我们所做的:我们在trunk (或在分支上)进行大部分开发,但其余过程几乎相同。 Once we are ready to show it to the customer, we create a tag . 一旦我们准备好向客户展示,我们就会创建一个标签 This tag is used to update the preview server. 此标记用于更新预览服务器。 If the customer isn't satisfied, we develop some more on trunk (or the branch), create a new tag, update preview with the tag, etc. Once the customer is happy we use the exact same tag running on preview to also update the production server. 如果客户不满意,我们会在主干(或分支机构)上开发更多内容,创建新标签,使用标签更新预览等。一旦客户满意,我们会使用在预览上运行的完全相同的标签来更新生产服务器。 This way we can be sure that the preview and production server have the same code base. 这样我们就可以确保预览和生产服务器具有相同的代码库。

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

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