如何正确部署 PHP 应用程序? [英] How To Deploy Your PHP Applications Correctly?

查看:37
本文介绍了如何正确部署 PHP 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何正确部署从开发到生产的应用程序以及如何处理多个站点配置.我所有的开发都是通过位于 var/svn/myapp/trunk 的 svn 完成的实际的生产代码在/var/www/myapp 中.

How to correctly deploy applications from development to production and how to deal with multiple site configurations. All my development are done thru svn located at var/svn/myapp/trunk and the actual production code is in /var/www/myapp.

我将本地机器上的最新代码检出到名为myapp_latest_svn"的目录中.我的主要 settings.php 中有特定于站点和位置的代码,其中 H_PATH = 'http://myapp.com'&db_host、db_user_name 和 db_password 的 db 配置设置,正如您所知,在本地机器设置(其中 localhost/myapp.com 只是一个 Apache 别名)&在生产(实时站点在 myapp.com 上运行)服务器上.

I check out the latest code to my local machine into a directory called "myapp_latest_svn". I have site and location specific code in my main settings.php, which has H_PATH = 'http://myapp.com' & db config settings for db_host, db_user_name and db_password which is as you know different in local machine settings ( where localhost/myapp.com is just an Apache alias) & on the production ( live site runs on myapp.com) server.

.htaccess 文件也与生产服务器上的不同.简而言之,开发和生产之间存在许多差异.

Also the .htaccess file is different from that on the production server. In short, there are a number of differences between dev and production.

我所有的工作都保存在 SVN 中.每天早上我都使用 SVN 更新,它将最新代码更新到我的本地 svn 存储库.当我准备好上线时,我使用 svn Commit 构建一个版本.

I keep all my work in SVN. Every morning i use SVN Update which updates the latest code to my local svn repository. When I am ready to go live, I build a release with svn Commit.

然后在发行版中,我必须记住将所有适当的开发文件更改为它们的生产对应文件.现在我不得不手动编辑生产 settings.php &.htaccess 以反映站点特定的更改.

Then in the release I have to remember to change all the appropriate dev files to their production counterpart. Now I had to manually edit the production settings.php & .htaccess to reflect the site specific changes.

我正在寻找一种自动化的方式从开发到生产完成版本控制和无需手动编辑文件,这很容易出错,而且做法很糟糕.

I am looking for an automated way to go from dev to production complete with versioning and no manually editing of files which is error prone and bad practice.

一种方法是将文件的生产版本设为只读 (0444).这样当我进行 svn 导出时,它们不会被文件的开发版本覆盖,我不必担心编辑文件从开发到生产的每一步.但这是做持续集成等事情的糟糕方式.

One way is making the production version of files read only (0444). That way when I do a svn export, they are not overwritten by the dev version of the files and I don't have to worry about editing files on each move from dev to production. But that's bad way of doing things like continuous integration.

还通过制作 settings.php 的多个副本(一个用于 localhost、beta 和 prod).然后使用shell脚本从svn导出,然后一旦导出完成,它会用正确的settings.php替换settings.php,取决于我们部署到的位置.这样一切都是自动化的.但这也是一条蹩脚的路.

Also by making multiple copies of the settings.php (one for localhost, beta, and prod). Then using a shell script that exports from svn, and then once the export is done, it replaces the settings.php with the correct settings.php, depending on the location that we are deploying to. That way everything is automated. But this is also a lame way to go.

最后一种方法是

if( eregi ("myapp.com$", $_SERVER['HTTP_HOST']) ){

    define('H_PATH', 'myapp.com');

} else {

    define('H_PATH', 'localmyapp.com');

}

就 settings.php 而言,这很好.但是 .htaccess 是什么,你不能像上面那样在 .htaccess 中检查.

This is fine as far as settings.php is concerned. But what abt the .htaccess, u cannot check like the above in .htaccess.

每次部署网站时我都不想做的事情是我必须更改设置.

What I don't want end up doing every time I deploy my site that I have to change settings.

我的数据库架构不在版本控制中,所以 db 对我来说不是问题,只有 settings.php 和 .htaccess.

My DB schema is not in version control so db is not an issue with me, only the settings.php and .htaccess.

另外,我如何告诉 svn 不要更新某些目录,因为这也是特定于站点的(/log、/cache、/assets、/downloads).此外,我还需要为上述文件保留完整的 apache ( www_data) 写访问权限.

Also how can i tell svn not to update some directories since that is also site specific (/log, /cache, /assets, /downloads). Also i need to preserve the apache ( www_data) write access intact for the above files as well.

最后,我不想在导出时将空的主干目录和 .svn 文件复制到生产服务器.

Lastly i don't want to copy the empty trunk directory and the .svn files to the production server when i export.

在从 svn 构建到生产服务器时,如何使用 Phing 甚至 shell 脚本进行集成,而不会导致任何这些问题.

How can i use Phing or even a shell script to integrate without causing any of these issues when building from svn to production servers.

这对于很多想成为应用开发者的人来说可能很有用.

This could be useful for many wannabe app developers out there in the wild.

提前致谢,

工作时间

推荐答案

我建议你看看 Capistrano解决您的部署问题.我用它来部署 PHP 系统,它会完成你描述的所有事情(在你的部署配方中有一些脚本工作).

I'd recommend you look at Capistrano for your deployment woes. I used it to deploy PHP systems, and it will do everything you describe (with a little script work in your deploy recipe).

我没有在我的远程仓库中保留任何配置文件 - 当我在 dev 中结帐时,我可以添加它们一次,然后忽略它们,这样我就不会无意中检查它们.在部署方面,我的 cap deploy recipe 已设置好,以便它将设置文件写入已部署的版本.这样,我再也不用担心部署和遗漏任何重要的东西.

I don't keep any config files in my remote repo - when I checkout in dev, I can add them once, then ignore them so I don't check them im by accident. When it comes to deploying, my cap deploy recipe is set up so that it will write the settings files into the deployed version. This way, I never have to worry about deploying and missing anything critical.

Cap 还会处理任何上传的资产(对目录进行符号链接,以便它们在每次部署时保持原位),并且还会在部署时自动将所有资产文件和数据库备份到 Amazon S3.很漂亮吧?

Cap also takes care of any uploaded assets (symlinking the directories so they remain in place on each deploy), and it also automatically backs up all asset files and the database on deploy to Amazon S3. Pretty nifty, eh?

这篇关于如何正确部署 PHP 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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