PHP开发生产环境
我想为我用 PHP 编写的新网站设置两个环境。 一 - 开发新版本并测试它们。 第二次制作将提供我的网站的实际稳定版本。
PHP 网站将由许多 PHP 和其他文件(JS、图像等)组成。 所以我想如何以最好的方式准备这个环境,以便于进行源代码控制,快速将网站从开发环境复制到生产环境,并使开发版本可供网络上的人们使用,以便他们能够看到实际的工作进度并建议更改或报告错误。
您能否给我一些建议,从这个起点该往哪里走? 有没有关于这方面的书籍(从实用的角度来看?)或者您有经验或建议要注意什么以及什么对于使这个过程变得简单并且对我和参与开发新项目的其他人有利?
I would like to setup two environments for my new website written in PHP. One - to develop new versions and test them. And second production where my actual stable version of website will be available.
Website in PHP will consist of many PHP and other files (JS, images, and so on). So I think how to prepare this environment in best way to make it easy to do source control, fast copy website from development environment to production environment and to make development version available for people on the web so they will be able to see actual work progress and suggest changes or report bugs.
Could you please give me some advice where to go from this starting point? Are there books about this (from practical point of view?) or do you have experience or tips what to watch out and what is important to make this process easy and good for me and other people involved in developing new project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于初学者,请使用以下三个:
SVN - 这将为您提供源代码控制并允许您跟踪更改。 您可能希望在此之上获得 GUI(Tortoise 是一种流行的 GUI)来简化学习曲线。
RSYNC - 这将允许您使用单个命令简化本地和远程站点之间的同步。 RSYNC 使用差异引擎进行同步,这意味着增量同步在几秒钟内发生。 在紧张的编程过程中,我有时会在一小时内同步 4-5 次,真正快速地推出微小的更改,只是因为我可以如此轻松地进行。
MySQLDump - 这将允许您从生产站点导入/导出数据。 我通常每周执行一次此操作,以获取本地服务器上的生产数据,这不仅为我提供了本地备份,还让我可以在本地测试环境上使用生产数据。
从长远来看,仅这三个就可以为您节省大量时间,并允许您进行扩展。 稍后您可以研究自动化构建工具、单元测试框架、xml 文档框架等来构建一些严肃的产品。
For starters use the following three:
SVN - this will give you source control and allow you to track changes. You may want to get GUIs on top of this (Tortoise is a popular one) to ease the learning curve.
RSYNC - this will allow you to streamline your syncing between local and remote site with a single command. RSYNC uses a diff engine to sync which means that incremental syncs happen in a matter of seconds. During intense programming, I will sometimes sync 4-5 times in one hour pushing out little changes real fast just because I can so easily.
MySQLDump - This will allow you to import/export data from your production site. I usually do this once a week to get production data on my local servers which not only gives me a local backup but also lets me toy around with production data on a local test environment.
Those three alone will save you a lot of time in the long run and allow you to scale. Later on you can look into an automated build tools, unit testing frameworks, xml documentation framework and the like to build some serious products.
我使用这样的设置,因此我可以为您提供一些有关如何执行此操作的提示。 我已经这样做了一段时间了,解决了这里那里的问题,并且感觉这是一个我可以诚实地说非常高效的设置。
小提示:我在 OSX 上工作,因此如果您是 Linux/Windows 用户,则使用的特定应用程序可能与您有所不同。
我在 Mac 上运行一个生产“服务器”,使用 MAMP (www.mamp.info) 轻松地为我提供带有 PHP 和 MySQL 的 Apache 服务器。 您可以使用类似的工具(例如 XAMPP)或手动安装所有内容,这完全取决于您。
然后我有我的实时服务器,我的网站和客户网站都托管在其中。 对于每个新网站项目(以 abc.com 为例),我创建一个名为 staging.abc.com 的子域,在该子域上进行测试。 在实际投入使用之前,在完全相同的硬件和软件上进行测试总是一件好事。
我使用 Subversion(或者简称 SVN)来满足我的版本控制需求,还有一个额外的好处,就是每当我将新更新的版本发送到 SVN 服务器时,我都可以轻松添加“挂钩”来自动更新我的在线生产服务器。 SVN 还允许您轻松地与多个人一起处理同一项目。 有关 SVN 以及如何使用它的更多信息,我建议您在这里找到一本很棒的(免费的)在线书籍:http ://svnbook.red-bean.com/
简而言之:我在本地使用 MAMP 工作,为我提供了本地“工作”服务器。 之后,我在 staging.abc.com 位置进行在线测试,看看一切是否正常,并且可能允许其他人看到该项目(如果您希望您的客户看到正在发生的事情,例如),之后我通过将其放在实际域上来实际发布该项目。
还有很多事情可以用来优化您的工作流程,但这应该可以帮助您入门。
希望这可以帮助!
-戴夫
I work with a setup like this, so I can give you some tips on how to do this. I've been doing this for a while now, working out the kinks here and there, and feel like this is a setup I can honestly say is pretty darn productive.
Small note: I work on OSX, so the specific applications used might be a bit different from you if you're a linux/windows user.
I run a production 'server' on my Mac, using MAMP (www.mamp.info) to easily supply me with an Apache server with PHP and MySQL. You could use a similar tool such as XAMPP or install everything manually, it's really up to you.
Then I have my live servers, where my websites and customer websites are hosted. For each new website project (let's take abc.com as an example) I create a subdomain called staging.abc.com, on which I do my testing. It's always a good thing to test things on the exact same hard- and software before actually going live.
I use Subversion (or in short, SVN) for my versioning needs, with the added bonus that I can easily add 'hooks' to automatically update my online production server whenever I send my newly updated version to the SVN server. SVN also allows you to easily work with more than one person on the same project. For more information on SVN and how to use it, I suggest the great (and free) online book found here: http://svnbook.red-bean.com/
So in short: I work locally with MAMP providing me with a local 'working' server. After that, I test online on a staging.abc.com location to see if everything works well, and to possibly allow others to see the project (in case you want your client to see what's going on, for example), and after that I actually publish the project by putting it on the actual domain.
There are many more things that can be done to optimize your workflow, but this should get you started.
Hope this helps!
-Dave
如果可能的话,我更喜欢在开发人员本地进行开发。 如果涉及其他开发人员,您可能希望设置版本控制,以便数据库架构、javascript、css 和 php 代码都可以很容易地在开发人员的个人盒子上检出和设置(假设他们有正确的 LAMP/ WAMP 设置)
我还看到人们在进行积极开发的服务器上维护一个测试网站。 对于主动开发,我会避免这种情况,但将其用于最新签入代码(最新版本)的黑盒测试。
一旦您的测试网站签出,就可以将代码从版本控制导出到实时网站所在的位置。 使用 svn,您实际上可以使用 svn update 指定指示当前实时版本的修订或标记来更新实时代码。
我还建议将一些设置(例如数据库访问/用户名/密码)保留在不受版本控制的单独包含文件中。 将其保留在其他地方,让开发人员在其 PC 上插入对本地数据库的访问权限。 在您的服务器上,插入访问数据库所需的一切。 这应该是非常简单的代码(定义了一些变量),因此不进行版本控制应该不是什么大问题。 如果您愿意,您可以对模板版本进行版本控制,但我不会将真实的数据库信息放入版本控制中。
I prefer to have development occur on the developers local box if possible. If other developers are involved, you probably want to setup your version control such that both the database schema, javascript, css, and the php code can be checked out and setup on a developer's personal box pretty easily (assuming they have the correct LAMP/WAMP setup)
I've also seen it where people maintain a test website on a server where active development occurs. I would avoid this for active development, but use this for black-box testing of the latest checked in code (the latest build).
Once your test website checks out, then its a matter of exporting the code from your version control to the location the live website is. With svn, you can really just do an update of the live code with svn update specifying a revision or tag that indicates the current live version.
I would further recommend keeping some settings, like db access/username/pass, in a separate included file that is not version controlled. Keep this elsewhere, let developers plug in the access rights to their local database on their PC. On your server, plug in everything you need to access the database there. This should be really trivial code (defining a few variables) so not having it version controlled shouldn't be a big deal. If you like, you could version control a templated version, but I wouldn't put the real database info into version control.
如果您想使用 MAMP 或 WAMP 进行本地开发,然后将其推送到 github,然后从 github 更新您的实时站点,那么这里是一个非常好的起点:
http:// www.mybringback.com/bringers/14509/git-local-and-shared-server-development-environment-with-ssh-setup/
希望有所帮助。
Here is a pretty good starting place if you want to use MAMP or WAMP to develop locally and then push that to github and then update your live site from github:
http://www.mybringback.com/bringers/14509/git-local-and-shared-server-development-environment-with-ssh-setup/
Hope that helps.