设置Apache进行本地开发/测试? [英] Set up Apache for local development/testing?

查看:118
本文介绍了设置Apache进行本地开发/测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Rails的屏幕录像印象深刻,它演示了内置的Web服务器和数据库,以允许在本地机器上进行开发和测试。我如何获得一个Apache的实例来执行一个项目目录作为它的DocumentRoot,并可能提供的端口8080(或类似的东西)?

I've been impressed by the screencasts for Rails that demonstrate the built-in web server, and database to allow development and testing to occur on the local machine. How can I get an instance of Apache to execute a project directory as its DocumentRoot, and maybe serve up the files on port 8080 (or something similar)?

的原因我问的是因为我要试用CodeIgniter,我想使用它的多个项目。我宁愿不把我的机器的DocumentRoot与每个。也欢迎提供关于如何进行数据库迁移的建议。

The reason why I'm asking is because I'm going to be trying out CodeIgniter, and I would like to use it for multiple projects. I would rather not clutter up my machine's DocumentRoot with each one. Suggestions on how to do database migrations are also welcome.

感谢您的回复。我应该澄清,我在Mac OS X.它看起来像WAMP是只有Windows。此外,XAMPP看起来像一个伟大的方式来安装Apache和许多其他Web工具,但我没有看到一个方法加载实例来提供一个项目目录。 Mac OS X已经安装了Apache和PHP - 我只是想找到一个方法来提供一个非标准端口上的项目。

Thank you for your responses so far. I should clarify that I'm on Mac OS X. It looks like WAMP is Windows-only. Also, XAMPP looks like a great way to install Apache and many other web tools, but I don't see a way of loading up an instance to serve up a project directory. Mac OS X has both Apache and PHP installed - I'm just looking for a way to get it to serve up a project on a non-standard port.

我只是找到了 MAMP Pro ,它能做我想要的,但更简洁的方法会更好如果它是可能的。有没有人有一个httpd.conf文件,可以编辑和删除到项目目录中?

I just found MAMP Pro which does what I want, but a more minimalist approach would be better if it's possible. Does anyone have a httpd.conf file that can be edited and dropped into a project directory?

另外,对不起,我只是在数据库迁移问题。我希望找到的东西,将使我能够将模式更改推送到实时服务器上,而不会丢失现有的数据。我怀疑这很困难,高度依赖于环境因素。

Also, sorry that I just threw in that database migration question. What I'm hoping to find is something that will enable me to push schema changes onto a live server without losing the existing data. I suspect that this is difficult, and highly dependent on environmental factors.

推荐答案

您的Mac附带Apache Web服务器和构建PHP。

Your Mac comes with both an Apache Web Server and a build of PHP. It's one of the big reasons the platform is well loved by web developers.

由于您使用的是代码Igniter,因此您需要PHP 5,这是默认版本的PHP随附10.5。如果您使用的是旧版本的操作系统,请转到 entropy.ch 并安装提供PHP5包。

Since you're using Code Igniter, you'll want PHP 5, which is the default version of PHP shipped with 10.5. If you're on a previous version of the OS hop on over to entropy.ch and install the provided PHP5 package.

接下来,您需要打开Apache。在共享首选项面板中,打开个人网络共享。这将在您的本地计算机上启动apache。

Next, you'll want to turn Apache on. In the sharing preferences panel, turn on personal web sharing. This will start up apache on your local machine.

接下来,您需要设置一些假冒的开发URL以用于您的网站。我使用假的TLD .dev这个(例如stackoverflow.dev)。编辑您的/ etc / hosts文件并添加以下行

Next, you'll want to setup some fake development URLs to use for your sites. I use the fake TLD .dev for this (ex. stackoverflow.dev). Edit your /etc/hosts file and add the following lines

127.0.0.1    www.example.dev
127.0.0.1    example.dev

这指向本地计算机上的上述URL。最后一步是配置apache。具体来说,启用命名虚拟主机,启用PHP和设置几个虚拟主机。如果使用熵PHP包,启用PHP将已经完成。如果没有,您需要按照此处中所述修改http.conf文件。基本上,您取消注释将加载PHP模块的行。

This points the above URLs at your local machine. The last step is configuring apache. Specifically, enabling named virtual hosting, enabling PHP and setting up a few virtual hosts. If you used the entropy PHP package, enabling PHP will already be done. If not, you'll need to edit your http.conf file as described here. Basically, you're uncommenting the lines that will load the PHP module.

无论何时更改apache配置,您都需要重新启动apache以进行更改生效。在终端窗口中,键入以下命令

Whenever you make a change to your apache config, you'll need to restart apache for the changes to take effect. At a terminal window, type the following command

sudo apachectl graceful

这将正常重新启动apache。如果你在配置文件中出现语法错误,apache将不会重新启动。您可以突出显示配置问题

This will gracefully restart apache. If you've made a syntax error in the config file apache won't restart. You can highlight config problems with

sudo apachectl configtest

因此,启用PHP后,您将需要打开NamedVirtualHosts。这将让apache响应多个URL。在您的http.conf文件中查找以下(或类似)行并取消注释。

So,with PHP enabled, you'll want to turn on NamedVirtualHosts. This will let apache respond to multiple URLs. Look for the following (or similar) line in your http.conf file and uncomment it.

#NameVirtualHost *  

最后,您需要告诉apache它应该在哪里查找新虚拟主机的文件。您可以通过将以下内容添加到http.conf文件中来实现。注意:我发现这是一个很好的最佳做法,将这样的配置规则分成一个单独的文件,并使用include指令来包含您的更改。这将停止任何自动更新,以清除您的更改。

Finally, you'll need to tell apache where it should look for the files for your new virtual hosts. You can do so by adding the following to your http.conf file. NOTE: I find it's a good best practice to break out config rules like this into a separate file and use the include directive to include your changes. This will stop any automatic updates from wiping out your changes.

<VirtualHost *>
    DocumentRoot /Users/username/Sites/example.dev
    ServerName example.dev
    ServerAlias www.example.dev    
</VirtualHost>

您可以指定任何文件夹作为DocumentRoot,但我发现使用您的个人网站文件夹因为它已经配置了包含文件的正确权限。

You can specify any folder as the DocumentRoot, but I find it convenient to use your personal Sites folder, as it's already been configured with the correct permissions to include files.

这篇关于设置Apache进行本地开发/测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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