我应该如何设置我的开发环境,以便将代码滚动到一个实时网站?

时间:2021-04-16 23:37:24

In the past, I've always edited all my sites live; wasn't too concerned about my 2 visitors seeing an error message.

在过去,我总是编辑我所有的网站;我不太担心我的两个访客看到错误信息。

However, there may come a day when I get more than 2 visitors. What would be the best approach to testing my changes and then making all the changes go live simultaneously?

然而,也许有一天我能得到2个以上的访客。测试我的更改并使所有更改同时工作的最佳方法是什么?

Should I copy and paste ever single file into a sub-folder and edit these, then copy them back when I'm done? What if I have full URLs in my code (they'll break if I move them)? Maybe I can use some .htaccess hackery to get around this? What about database dummy test data? Should I dupe all my MySQL tables and reference those instead?

我是否应该将单个文件复制粘贴到子文件夹中并编辑它们,然后在我完成后将它们复制回来?如果我的代码中有完整的url怎么办(如果我移动它们,它们就会崩溃)?也许我可以用。htaccess hackery来解决这个问题?那么数据库虚拟测试数据呢?我应该欺骗所有MySQL表并引用它们吗?

I'm using CakePHP for the particular project I'm concerned about, but I'm curious to know what approaches people are taking both with Cake (which may have tools to assist with this?), and without a framework.

我正在使用CakePHP来处理我所关心的特定项目,但是我很想知道人们同时使用Cake的方法是什么(它可能有工具来帮助我),而且没有框架。


I've been getting a lot of recommendations for SVN, which sounds great, but unfortunately my host doesn't support it :\

我收到了很多关于SVN的建议,这听起来不错,但不幸的是,我的主机不支持它:\。

5 个解决方案

#1


18  

The best thing you can do is to create a staging environment in which you test your changes. The staging environment (ideally) is a complete, working duplicate of your production system. This will prevent you from experiencing many headaches and inadvertent production crashes.

您可以做的最好的事情是创建一个测试更改的阶段环境。登台环境(理想地)是您的生产系统的一个完整的、工作的副本。这将防止您经历许多头痛和意外的生产崩溃。

If you are working on a small project the best thing to do is to recreate your remote site locally (including the database). Code all your changes there and then, once you are satisfied that you are finished, deploy the changes to your remote site in one go.

如果您正在处理一个小型项目,那么最好的做法是在本地重新创建远程站点(包括数据库)。在那里编写所有更改的代码,然后,一旦您满意地完成了更改,立即将更改部署到远程站点。

#2


5  

I would recommend putting your website code under full version control (git or subversion). Test and maintain your source in a separate, private sandbox server, and just check out the latest stable version at the production site whenever it's ready for release.

我建议您将网站代码置于完全版本控制(git或subversion)之下。在一个单独的、私有的沙箱服务器上测试和维护您的源代码,只要它准备好发布,就在生产站点上检查最新的稳定版本。

For database support, even for small projects I maintain separate development and production databases. You can version the SQL used to generate and maintain your schema and testing or bootstrapping data along with the rest of your site. Manage the database environment used by your site from an easily separated configuration file, and tell your version control solution to ignore it.

对于数据库支持,即使对于小型项目,我也维护独立的开发和生产数据库。您可以对用于生成和维护模式、测试或引导数据以及站点其余部分的SQL进行版本化。从容易分离的配置文件中管理站点使用的数据库环境,并告诉版本控制解决方案忽略它。

Absolute URLs are going to be a problem. If you can't avoid them, you could always store the hostname in the same configuration file and read it as needed... except within stylesheets and Javascript resources, of course. My second choice for that problem would be URL-rewriting magic or its equivalent in the development server, and my last choice would be just messing with the /etc/hosts file when I wanted to test features that depend on them.

绝对url将是一个问题。如果您无法避免它们,您可以将主机名存储在相同的配置文件中,并根据需要读取它……当然,除了样式表和Javascript资源。对于这个问题,我的第二个选择是url重写,或者在开发服务器中它的等效项,而我的最后一个选择就是在测试依赖于/etc/hosts文件的特性时把它们弄乱。

#3


3  

I set up a development server on my laptop that duplicates my web server as closely as possible (server software and configuration, operating system, filesystem layout, installed software, etc.) That way I can write the code on my laptop and test it locally; once I've gotten things working there, I copy it to the server. Sometimes a few problems arise because of slight differences between the two computers, but those are always quickly resolved (and just in case they're not, I have my site in an SVN repository so I can always revert it).

我在我的笔记本电脑上设置了一个开发服务器,它尽可能地复制我的web服务器(服务器软件和配置、操作系统、文件系统布局、已安装的软件等),这样我就可以在我的笔记本电脑上编写代码并在本地测试它;一旦我在那里工作,我将它复制到服务器。有时,由于这两台计算机之间的细微差异,会出现一些问题,但这些问题总是很快得到解决(为了防止出现这些问题,我将我的站点放在SVN存储库中,这样我就可以随时恢复它)。

On another website I used to maintain, I used a slightly different tactic: I designated a URL path within the site that would be a development version of the base site. That is, http://www.example.com/devweb would ordinarily mirror http://www.example.com, http://www.example.com/devweb/foo/bar.php would mirror http://www.example.com/foo/bar.php, etc. I created a folder devweb under the document root, but instead of copying all the files, I configured the server so that if a requested file didn't exist in the /devweb directory, it would look for it under the document root. That was a more fragile setup than having a separate development server, though.

在我以前维护的另一个网站上,我使用了一种稍微不同的策略:我在网站中指定了一个URL路径,该路径将是基础站点的开发版本。http://www.example.com/devweb通常镜子http://www.example.com,http://www.example.com/foo/bar.php,http://www.example.com/devweb/foo/bar.php镜像等等。我创建了一个文件夹devweb文档根下,而是复制所有的文件,我配置了服务器,如果请求的文件/ devweb目录不存在,它会寻找它在文档根目录下。不过,这比单独的开发服务器要脆弱得多。

#4


2  

I have a number of websites written in CakePHP. I develop and test on my local machine, using the database on my production server (I just have a MySQL login that works for my static IP address).

我有一些用CakePHP编写的网站。我在我的本地机器上开发和测试,在我的生产服务器上使用数据库(我只是有一个MySQL登录,它适用于我的静态IP地址)。

All code is checked into Subversion, and I then have a continuous integration server - Hudson:

所有代码都被检入Subversion中,然后我有一个持续集成服务器——Hudson:

https://hudson.dev.java.net/

https://hudson.dev.java.net/

This builds and deploys my project on the production machine. It just checks out the code in subversion for a specific project then runs a simple script to SSH/copy the files into the staging or production location on the server. You can either set this up to be a manual process (which I have currently) or you can set this up so that it deploys once code has been checked in. There's lots of other CI tools that can be setup to do this (have a look at Xinc as well).

这将在生产机器上构建并部署我的项目。它只检查subversion中的代码,然后运行一个简单的脚本,以SSH/copy文件到服务器上的登台或生产位置。您可以将其设置为手动流程(我目前已经这样做了),也可以将其设置为在签入代码后进行部署。有很多其他的CI工具可以用来做这个(也可以看看Xinc)。

http://code.google.com/p/xinc/

http://code.google.com/p/xinc/

As for absolute URLs you can always setup something in your host file to resolve the site locally on your machine instead. It works for me, just don't forget to take it out afterwards : )

至于绝对url,您可以在主机文件中设置一些内容,以便在计算机上本地解析站点。它对我很有用,但别忘了之后把它拿出来。

Hope that helps...

希望这有助于……

#5


2  

I have a version of config/database.php that uses the php server variable "SERVER NAME" to determine which system the app is running on. Then when I clone my git repo across my home system, development site (which shares the same specs as the live machine), and the live machine they all connect to their respective databases.

我有一个配置/数据库版本。php,使用php服务器变量“服务器名”来确定应用程序正在运行的系统。然后,当我在我的家庭系统、开发站点(与活动机器共享相同的规格)和活动机器上克隆git repo时,它们都连接到各自的数据库。

I pasted here, but I also believe its available on thebakery.

我在这里贴的,但我也相信它在面包店买的。

http://pastebin.com/f1a701145

http://pastebin.com/f1a701145

#1


18  

The best thing you can do is to create a staging environment in which you test your changes. The staging environment (ideally) is a complete, working duplicate of your production system. This will prevent you from experiencing many headaches and inadvertent production crashes.

您可以做的最好的事情是创建一个测试更改的阶段环境。登台环境(理想地)是您的生产系统的一个完整的、工作的副本。这将防止您经历许多头痛和意外的生产崩溃。

If you are working on a small project the best thing to do is to recreate your remote site locally (including the database). Code all your changes there and then, once you are satisfied that you are finished, deploy the changes to your remote site in one go.

如果您正在处理一个小型项目,那么最好的做法是在本地重新创建远程站点(包括数据库)。在那里编写所有更改的代码,然后,一旦您满意地完成了更改,立即将更改部署到远程站点。

#2


5  

I would recommend putting your website code under full version control (git or subversion). Test and maintain your source in a separate, private sandbox server, and just check out the latest stable version at the production site whenever it's ready for release.

我建议您将网站代码置于完全版本控制(git或subversion)之下。在一个单独的、私有的沙箱服务器上测试和维护您的源代码,只要它准备好发布,就在生产站点上检查最新的稳定版本。

For database support, even for small projects I maintain separate development and production databases. You can version the SQL used to generate and maintain your schema and testing or bootstrapping data along with the rest of your site. Manage the database environment used by your site from an easily separated configuration file, and tell your version control solution to ignore it.

对于数据库支持,即使对于小型项目,我也维护独立的开发和生产数据库。您可以对用于生成和维护模式、测试或引导数据以及站点其余部分的SQL进行版本化。从容易分离的配置文件中管理站点使用的数据库环境,并告诉版本控制解决方案忽略它。

Absolute URLs are going to be a problem. If you can't avoid them, you could always store the hostname in the same configuration file and read it as needed... except within stylesheets and Javascript resources, of course. My second choice for that problem would be URL-rewriting magic or its equivalent in the development server, and my last choice would be just messing with the /etc/hosts file when I wanted to test features that depend on them.

绝对url将是一个问题。如果您无法避免它们,您可以将主机名存储在相同的配置文件中,并根据需要读取它……当然,除了样式表和Javascript资源。对于这个问题,我的第二个选择是url重写,或者在开发服务器中它的等效项,而我的最后一个选择就是在测试依赖于/etc/hosts文件的特性时把它们弄乱。

#3


3  

I set up a development server on my laptop that duplicates my web server as closely as possible (server software and configuration, operating system, filesystem layout, installed software, etc.) That way I can write the code on my laptop and test it locally; once I've gotten things working there, I copy it to the server. Sometimes a few problems arise because of slight differences between the two computers, but those are always quickly resolved (and just in case they're not, I have my site in an SVN repository so I can always revert it).

我在我的笔记本电脑上设置了一个开发服务器,它尽可能地复制我的web服务器(服务器软件和配置、操作系统、文件系统布局、已安装的软件等),这样我就可以在我的笔记本电脑上编写代码并在本地测试它;一旦我在那里工作,我将它复制到服务器。有时,由于这两台计算机之间的细微差异,会出现一些问题,但这些问题总是很快得到解决(为了防止出现这些问题,我将我的站点放在SVN存储库中,这样我就可以随时恢复它)。

On another website I used to maintain, I used a slightly different tactic: I designated a URL path within the site that would be a development version of the base site. That is, http://www.example.com/devweb would ordinarily mirror http://www.example.com, http://www.example.com/devweb/foo/bar.php would mirror http://www.example.com/foo/bar.php, etc. I created a folder devweb under the document root, but instead of copying all the files, I configured the server so that if a requested file didn't exist in the /devweb directory, it would look for it under the document root. That was a more fragile setup than having a separate development server, though.

在我以前维护的另一个网站上,我使用了一种稍微不同的策略:我在网站中指定了一个URL路径,该路径将是基础站点的开发版本。http://www.example.com/devweb通常镜子http://www.example.com,http://www.example.com/foo/bar.php,http://www.example.com/devweb/foo/bar.php镜像等等。我创建了一个文件夹devweb文档根下,而是复制所有的文件,我配置了服务器,如果请求的文件/ devweb目录不存在,它会寻找它在文档根目录下。不过,这比单独的开发服务器要脆弱得多。

#4


2  

I have a number of websites written in CakePHP. I develop and test on my local machine, using the database on my production server (I just have a MySQL login that works for my static IP address).

我有一些用CakePHP编写的网站。我在我的本地机器上开发和测试,在我的生产服务器上使用数据库(我只是有一个MySQL登录,它适用于我的静态IP地址)。

All code is checked into Subversion, and I then have a continuous integration server - Hudson:

所有代码都被检入Subversion中,然后我有一个持续集成服务器——Hudson:

https://hudson.dev.java.net/

https://hudson.dev.java.net/

This builds and deploys my project on the production machine. It just checks out the code in subversion for a specific project then runs a simple script to SSH/copy the files into the staging or production location on the server. You can either set this up to be a manual process (which I have currently) or you can set this up so that it deploys once code has been checked in. There's lots of other CI tools that can be setup to do this (have a look at Xinc as well).

这将在生产机器上构建并部署我的项目。它只检查subversion中的代码,然后运行一个简单的脚本,以SSH/copy文件到服务器上的登台或生产位置。您可以将其设置为手动流程(我目前已经这样做了),也可以将其设置为在签入代码后进行部署。有很多其他的CI工具可以用来做这个(也可以看看Xinc)。

http://code.google.com/p/xinc/

http://code.google.com/p/xinc/

As for absolute URLs you can always setup something in your host file to resolve the site locally on your machine instead. It works for me, just don't forget to take it out afterwards : )

至于绝对url,您可以在主机文件中设置一些内容,以便在计算机上本地解析站点。它对我很有用,但别忘了之后把它拿出来。

Hope that helps...

希望这有助于……

#5


2  

I have a version of config/database.php that uses the php server variable "SERVER NAME" to determine which system the app is running on. Then when I clone my git repo across my home system, development site (which shares the same specs as the live machine), and the live machine they all connect to their respective databases.

我有一个配置/数据库版本。php,使用php服务器变量“服务器名”来确定应用程序正在运行的系统。然后,当我在我的家庭系统、开发站点(与活动机器共享相同的规格)和活动机器上克隆git repo时,它们都连接到各自的数据库。

I pasted here, but I also believe its available on thebakery.

我在这里贴的,但我也相信它在面包店买的。

http://pastebin.com/f1a701145

http://pastebin.com/f1a701145