如何发布Web应用程序?
我真的不知道如何在 Web 开发中正确执行从离线开发到实时 Web 服务器的部署.我主要依靠直觉,但这或多或少是我到现在为止所做的:我有一个使用 python 或 php 编写的 Web 应用程序,并且我将它托管在实时网络服务器上.我用的是svn下的离线开发版.
I don't really know how to perform deployment from offline development to live webserver correctly in web development. I mostly resort on intuition, but this is more or less what I did until now: I have a web application in python, or php, and I am hosting it on a live webserver. I use an offline development version whose source is under svn.
现在,当我开发离线版本时,我将对 svn 执行提交.当发布时间到了,我可以:
Now, as I develop the offline version, I will perform commits to the svn. When time has come for release, I could either:
- 将代码从离线服务器复制到实时网络服务器上的临时目录,然后将旧代码库与新代码库交换(例如,使用链接),或者...
- 让实时网络服务器在结帐 svn 上工作,然后运行 svn update.
我通常做第二个,尽管如果我必须在实时部署之前升级数据库,我通常会编写升级 sql 脚本,然后先在实时数据库上运行它们,然后结帐.
I normally do the second, although if I have to upgrade the database before the live deployment, I normally write upgrade sql scripts, and run them first on the live database, then checkout.
这项任务的最佳实践是什么?
What are the best practices for this task ?
我建议利用 SVN 导出而不是结帐.这样,您就不会向全世界公开任何 SVN 文件.它还通常会创建一个更清晰的文件夹结构.
I recommend leveraging SVN export instead of checkout. This way, you will not expose any of the SVN files to the world. It also generally creates a cleaner folder structure.
我之前在舞台和制作之间移动文件时使用过 rsync.
I have leveraged rsync before when moving files between stage and production.
我的典型部署过程如下:
My typical deployment proceeds as follows:
- 备份生产站点
- 从备份恢复到暂存服务器
- 从所有外部 IP 地址锁定服务器
- 将代码从存储库导出到临时文件夹中(可选择将两个文件夹进行比较以进行小的更改)
- rsyc 文件从临时文件夹到阶段服务器文件夹
- 验证只有您希望更改的文件实际发生了更改.
- 将 SQL 脚本应用到数据库
- 测试升级
- 解锁网络服务器
现在,要部署到生产环境,请快速重播这些步骤.使用脚本可以更轻松.
Now, to deploy to production, replay these steps in fast forward. Using scripts make it much easier.