简体   繁体   English

设置开发服务器

[英]Setting up a development server

When developing PHP applications, it's best to have a server you develop/test on, and then a live server you put everything once it's ready. 在开发PHP应用程序时,最好有一个你开发/测试的服务器,然后是一个实时服务器,一旦它准备好就放好了。

OK, but how? 好的,但是怎么样?

If you are hosting through a hosting company how can you setup your own development server to test on that mimics all the LAMP settings as your live server? 如果您通过托管公司托管,您如何设置自己的开发服务器进行测试,模仿所有LAMP设置作为您的实时服务器? Because if they differ then testing on one that isn't identical to the live one, defeats the purpose right? 因为如果它们不同,那么测试一个与现场不同的那个,就会失败了吗?

Is it better use another server through the same hosting company and ask them make both the development and live ones have the exact same settings? 是否更好地通过同一个托管公司使用另一台服务器并要求他们使开发和实时的服务器具有完全相同的设置?

Also what is the best work-flow to use to check files out from "live server" work on them in the "development server", then check them back into the live server? 还有什么是用于在“开发服务器”中检查“实时服务器”文件的最佳工作流程,然后将它们检入实时服务器?

Thanks!! 谢谢!!

Two points from my daily work: 我日常工作中的两点:

  • XAMPP is your one-stop shop for setting up a Apache/mySQL/PHP stack on Windows. XAMPP是您在Windows上设置Apache / mySQL / PHP堆栈的一站式商店。 I develop with it and deploy to Linux machines, no problem. 我用它开发并部署到Linux机器,没问题。

  • If you want to set up a Linux environment on a home server or virtual machine, I asked a question a while ago that may interest you: Pre-installed Linux for Web Developers? 如果你想在家庭服务器或虚拟机上设置一个Linux环境,我前一段时间问了一个你可能感兴趣的问题: 预装Linux for Web Developers?

Is it better use another server through the same hosting company and ask them make both the development and live ones have the exact same settings? 是否更好地通过同一个托管公司使用另一台服务器并要求他们使开发和实时的服务器具有完全相同的设置?

If you can afford a second server, it may well be the best way to go. 如果你能买得起第二台服务器,那么它可能是最好的选择。 On the other hand, a local machine you could upgrade and fiddle around with at will, and all that at a fraction of the long-term cost of a second rented server. 另一方面,你可以随意升级和摆弄本地机器,所有这些只需要第二台租用服务器的长期成本的一小部分。 If in doubt, I would go for a local machine. 如果有疑问,我会选择本地机器。

Don't forget PHP is a very portable language. 不要忘记PHP是一种非常便携的语言。 If you don't use any specific command-line tools or totally exotic extensions, making a PHP application work across Linuxes, and even on Windows is a question of some settings and details, but not really a big deal any more. 如果你不使用任何特定的命令行工具或完全奇特的扩展,使PHP应用程序在Linux上工作,甚至在Windows上都是一些设置和细节的问题,但不再是一个大问题。

Also what is the best work-flow to use to check files out from "live server" work on them in the "development server", then check them back into the live server? 还有什么是用于在“开发服务器”中检查“实时服务器”文件的最佳工作流程,然后将它们检入实时服务器?

There are many, many opinions and practices in this field. 这个领域有很多很多意见和做法。 For me personally, the following workflow has turned out to be ideal wherever I've used it - I am still in the process of implementing this myself in all projects and for all clients. 就我个人而言,无论我在哪里使用它,以下工作流程都是理想的 - 我仍然在所有项目和所有客户中实现这一点。

  1. Edit files locally in IDE 在IDE中本地编辑文件

  2. Upload to development server via built-in FTP function of IDE 通过IDE的内置FTP功能上传到开发服务器

  3. Test on development server 测试开发服务器

  4. Once a feature is tested and works on the development server (ie it's "finished"), check the whole package into a Subversion (or other) repository 一旦功能被测试并在开发服务器上运行(即它已“完成”),请将整个包检查到Subversion(或其他)存储库中

  5. On the live server, have a build script check out the latest revision from the repository, download it to a directory with the revision number, and when finished, change a symbolic link that pointed to the previous revision to the latest one. 在实时服务器上,让构建脚本从存储库中检出最新版本,将其下载到具有修订号的目录,完成后,将指向上一版本的符号链接更改为最新版本。

That way, every change you make to the live environment is logged in the version control system, and reverting to the previous revision is a question if seconds. 这样,您对实时环境所做的每个更改都会记录在版本控制系统中,如果是秒,则还原到以前的版本是一个问题。 To me, this was a huge relief compared to working with pure FTP everywhere. 对我而言,与在任何地方使用纯FTP相比,这是一个巨大的解脱。

Possibly also interesting question: Setting up a deployment / build / CI cycle for PHP projects 可能也是一个有趣的问题: 为PHP项目设置部署/构建/ CI循环

You can check all the production server's setup via phpinfo() and copy them on your development environment, no need for them to be on the same provider. 您可以通过phpinfo()检查所有生产服务器的设置,并将它们复制到您的开发环境中,无需将它们放在同一个提供程序上。

I usually commit the code to source control, and checkout in the production environment, hiding all the repository information via .htaccess, for example, see here . 我通常将代码提交到源代码控制,并在生产环境中检出,通过.htaccess隐藏所有存储库信息,例如,请参见此处

Another (less recommended) option is to just have your master source in the development machine, and once it's ready FTP it up, there are various free tools that will only upload changed files. 另一个(不太推荐)选项是在开发机器中拥有主源,一旦准备好FTP它,有各种免费工具只会上传更改的文件。

As for the server side, you have multiple possibilities. 至于服务器端,您有多种可能性。 You could use vHosts when you have Apache, with two different DocumentRoots: one for the live version, and one for development. 你有Apache时可以使用vHosts,有两个不同的DocumentRoots:一个用于实时版本,一个用于开发。 Or you can have the development environment on your local machine, and then the live (+ staging) on your dedicated server / webspace whatsoever. 或者,您可以在本地计算机上使用开发环境,然后在专用服务器/网站空间上使用实时(+ staging)。

In our current project we have a three-tier system: 在我们目前的项目中,我们有一个三层系统:

development, staging and live. 发展,分期和生活。 Staging and live are really almost the same, so that I can eliminate any problems when rolling out from dev to staging. 暂存和实时几乎是一样的,这样我就可以在从开发到分期时消除任何问题。 It gives me another security layer before rolling out to live and eventually noticing that something went wrong. 在推出生活并最终注意到出现问题之前,它为我提供了另一个安全层。

Considering the workflow for rolling out, you should create an application config, where you can define several application environments (development and production) that automatically choose their environment based on URLs, defined environment variables or something else. 考虑到推出的工作流程,您应该创建一个应用程序配置,您可以在其中定义多个应用程序环境(开发和生产),这些环境会根据URL,已定义的环境变量或其他内容自动选择其环境。 So, in Zend Framework for example, this configuration driven behavior is built into your applications. 因此,在Zend Framework中,这种配置驱动的行为内置于您的应用程序中。 In your config.ini file, you have a template which looks like this: 在config.ini文件中,您有一个如下所示的模板:

[production]

[staging : production]

[testing : production]

[development : production]

In there you can define different options for, lets say, your database connection ie 在那里,您可以为数据库连接定义不同的选项,即

So when you check your changes on the dev machine into subversion and do a rollout onto your live system, you do not have to change the configuration. 因此,当您将开发机器上的更改检查到subversion并在实际系统上进行部署时,您不必更改配置。 It should just work. 它应该工作。

As far as workflow goes, that's typically what happens for small sites. 就工作流程而言,这通常是针对小型网站的情况。 Depending on the size of the project, though, it might be a good idea to use version control like Git or Subversion. 但是,根据项目的大小,使用Git或Subversion等版本控制可能是个好主意。

You don't need to go anywhere near as far as asking a hosting company to setup two identical hosting environments for you. 在要求托管公司为您设置两个相同的托管环境时,您不需要去任何地方。 The majority of the time they have up to date versions of php, mysql and apache. 大多数时候他们拥有最新版本的php,mysql和apache。 I develop on a Linux machine, that has a lamp stack setup already, so my workflow is pretty seamless, and I use a svn with post-commit hooks to upload to the live server. 我在Linux机器上开发,已经有灯泡设置,所以我的工作流程非常无缝,我使用带有post-commit钩子的svn上传到实时服务器。 If you are worried about incompatibilities between you're 'dev' server and the hosting server, the easiest thing to do is make a phpinfo file, 如果您担心您的'dev'服务器和托管服务器之间不兼容,最简单的方法是制作一个phpinfo文件,

<?php phpinfo(); ?>

and check that your hosting server does not prohibit any special functions you use on your dev server (and this is pretty rare that the hosting company blocks vital things, and if they do you can easily send support an email and 99% of the time they will assist you in enabling whatever particulars you require. But as far as setting up your dev environment, I would go down the track of grabbing virtualbox, and installing ubuntu, find a tutorial for making ubuntu a web server (seriously only a few apt-get commands) and you will be smoking with gas ! 并检查您的托管服务器是否禁止您在开发服务器上使用的任何特殊功能(托管公司很少阻止重要的事情,如果他们这样做,您可以轻松地发送支持电子邮件,99%的时间他们将帮助您实现您需要的任何细节。但是就设置您的开发环境而言,我会走下去抓取虚拟机的轨道,并安装ubuntu,找到一个教程,让ubuntu成为一个Web服务器(严重的只有几个 - 得到命令),你将吸烟天然气!

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

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