为 Eclipse 配置 Apache HTTP 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10400752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Config Apache HTTP Server for Eclipse
提问by hqt
Maybe this question is silly but I really don't know how to solve.
也许这个问题很愚蠢,但我真的不知道如何解决。
First, as other server, I want to define new server. So, in Eclipse, I go to: Windows>Preference>Server:
首先,作为其他服务器,我想定义新服务器。因此,在 Eclipse 中,我转到:Windows>Preference>Server:
1) When I add new server, in list, no category for Apache HTTP server. Just has Apache Tomcat. So, I click into download additional server adapter-->still don't have in list.
1) 当我添加新服务器时,列表中没有 Apache HTTP 服务器的类别。只有 Apache Tomcat。所以,我点击下载额外的服务器适配器-->列表中仍然没有。
2) So, I search. I point to location I have installed. Good, Eclipse sees that is a HTTP Server. And Eclipse sees folder to put project into for me (because I use LAMP so that folder isn't in Apache folder).
2)所以,我搜索。我指向我安装的位置。很好,Eclipse 认为这是一个 HTTP 服务器。Eclipse 会为我看到将项目放入的文件夹(因为我使用 LAMP,因此该文件夹不在 Apache 文件夹中)。
But here is my problem. When I want to run a new PHP Project. Right click, run on server. A new dialog appear take me to choose which server to run. And, in list of server, no HTTP Server, So, I don't know how to choose Apache HTTP Server !!! (because Eclipse doesn't see which server that I have defined, eclipse just find adapter first)
但这是我的问题。当我想运行一个新的 PHP 项目时。右键,在服务器上运行。出现一个新对话框让我选择要运行的服务器。而且,在服务器列表中,没有HTTP Server,所以,我不知道如何选择Apache HTTP Server !!! (因为Eclipse看不到我定义了哪个服务器,eclipse只是先找适配器)
So, if I want to run this project, I must copy all and paste to Apache folder. Too handy !!!
所以,如果我想运行这个项目,我必须全部复制并粘贴到 Apache 文件夹。太方便了!!!
Please help me.
请帮我。
Thanks :)
谢谢 :)
采纳答案by Gilbert Le Blanc
Apache's HTTP server and Eclipse don't communicate with each other. The servers under Windows -> Preference -> Server are Java servers like Tomcat and Glassfish.
Apache 的 HTTP 服务器和 Eclipse 不相互通信。Windows -> Preference -> Server 下的服务器是Java服务器,如Tomcat和Glassfish。
What you need to do is define your web project in Eclipse, then define that same directory to the HTTP server in the httpd.conf file. Or, since you're already set up, write an Ant script in Eclipse to copy the PHP files to your HTTP folder.
您需要做的是在 Eclipse 中定义您的 Web 项目,然后在 httpd.conf 文件中为 HTTP 服务器定义相同的目录。或者,因为您已经设置好了,所以在 Eclipse 中编写一个 Ant 脚本来将 PHP 文件复制到您的 HTTP 文件夹中。
Edited to add: Here's my Ant script to keep my Eclipse directory and my HTTP directory synchronized. I develop in Windows.
编辑添加:这是我的 Ant 脚本,用于保持我的 Eclipse 目录和我的 HTTP 目录同步。我在 Windows 中开发。
<?xml version="1.0" encoding="UTF-8"?>
<project name="build" default="" basedir=".">
<description>
Synchronize the Eclipse folders and the web site folders
</description>
<!-- Relative location of eclipse folder -->
<property name="eclipse" value="." />
<!-- Absolute location of web site folder -->
<property name="website" value="C:/Presbury UMC/" />
<!-- Copy new web site files -->
<copy todir="${eclipse}">
<fileset file="${website}/index.php"/>
</copy>
<copy todir="${eclipse}/css">
<fileset dir="${website}/css"/>
</copy>
<copy todir="${eclipse}/images">
<fileset dir="${website}/images"/>
</copy>
<copy todir="${eclipse}/protected">
<fileset dir="${website}/protected/">
<exclude name="yiic*"/>
<exclude name=".htaccess"/>
</fileset>
</copy>
<copy todir="${eclipse}/themes">
<fileset dir="${website}/themes"/>
</copy>
<!-- Copy new Eclipse files -->
<copy todir="${website}">
<fileset file="${eclipse}/index.php"/>
</copy>
<copy todir="${website}/css">
<fileset dir="${eclipse}/css"/>
</copy>
<copy todir="${website}/images">
<fileset dir="${eclipse}/images"/>
</copy>
<copy todir="${website}/protected">
<fileset dir="${eclipse}/protected/"/>
</copy>
<copy todir="${website}/themes">
<fileset dir="${eclipse}/themes/"/>
</copy>
</project>
回答by humble_wolf
Go to apache>conf>httpd.conf file and open it.Below "ServerName localhost:80" change your document root and directory to your working directory(in eclipse it is workspace).Now you can run your php file/project by typing its full url in any browser or if you want to run it through eclipse you have to configure that run also by synchronizing both server copy and local copy(in this case both are same)in mapping tab.
转到 apache>conf>httpd.conf 文件并打开它。在“ServerName localhost:80”下面将您的文档根目录和目录更改为您的工作目录(在 eclipse 中它是工作区)。现在您可以通过键入运行您的 php 文件/项目它在任何浏览器中的完整 url,或者如果您想通过 eclipse 运行它,您还必须通过在映射选项卡中同步服务器副本和本地副本(在这种情况下两者相同)来配置该运行。
回答by michel.iamit
I let the apache config file be in my source code folder (in a folder /etc for example).
我让 apache 配置文件位于我的源代码文件夹中(例如在文件夹 /etc 中)。
In ubuntu you can create a symbolic link in your sites available to this config file in your code source folder:
在 ubuntu 中,您可以在您的站点中创建一个符号链接,该链接可用于代码源文件夹中的此配置文件:
sudo ln -s path_to_your_conf .
And in sites enabled you create a symbolic link to the conf file in sites available (or use the apache 2 command: sudo a2ensite example.com.conf ).
在启用的站点中,您可以在可用站点中创建一个指向 conf 文件的符号链接(或使用 apache 2 命令: sudo a2ensite example.com.conf )。
In windows you can also create a symbolic link:
google for the command mklink
在 Windows 中,您还可以创建符号链接: google 命令 mklink
I am not working a lot with windows, but seems the same option).
我在 Windows 上工作不多,但似乎是相同的选择)。
This way you do not need to copy anything to the apache var/www folder, and you can access the settings for Apache for the project you work on in your source code folder.
通过这种方式,您无需将任何内容复制到 apache var/www 文件夹,并且您可以在源代码文件夹中访问您正在处理的项目的 Apache 设置。
So not sure this will work in windows, but if it does, for me this is the easiest way to develop any web project. Keep the things you need in source folder and the same way you can do it on the real server (I use some deploy and build scripts to do this, but this is the concept and that's working good for me).
所以不确定这是否会在 Windows 中工作,但如果确实如此,对我来说这是开发任何 Web 项目的最简单方法。将您需要的东西保存在源文件夹中,并以与在真实服务器上相同的方式进行操作(我使用了一些部署和构建脚本来执行此操作,但这是概念,这对我很有用)。
回答by Marc
Quite some time ago, that this question has been asked, but here is how I handle this:
很久以前,有人问过这个问题,但我是这样处理的:
I develop some web application (with a Python CGI backend and the usual database store) on Windows and run Apache 2.2 httpd.exe
from it's standard installation path C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin
我在 Windows 上开发了一些 Web 应用程序(带有 Python CGI 后端和通常的数据库存储)并httpd.exe
从它的标准安装路径运行 Apache 2.2C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin
I prefer having an adjusted httpd.conf (std location on Windows would be ~\conf\httpd.conf
) for the project I'd like to debug.
我更喜欢~\conf\httpd.conf
为我想要调试的项目调整 httpd.conf(Windows 上的标准位置)。
Start/stop is done manual using the External Tools runner. You could even put all required command line options in there if you prefer to have the httpd.conf
together with your project or like to add further options like logging to stdout (which would then go to an Eclipse console window) vs. logging to file in ~\logs
.
启动/停止是使用外部工具运行器手动完成的。如果您更喜欢将所有必需的命令行选项httpd.conf
与您的项目一起使用,或者想添加更多选项,例如记录到 stdout(然后转到 Eclipse 控制台窗口)与记录到~\logs
.
回答by Deepak Madhaan
you can download Ant ,then go to your project go on run as,there will be two options 1.Ant build 2.Ant build,choose the second one check the box of war(generate war),your build will be generated and your war will be created ,put this .war file in the webapps folder of your apache server. Hope it helps
你可以下载Ant,然后去你的项目继续运行,会有两个选项1.Ant build 2.Ant build,选择第二个勾选war(generate war)框,你的构建将被生成,你的将创建war,将此.war 文件放在apache 服务器的webapps 文件夹中。希望能帮助到你
回答by Patrice Cotte
This answer is based on a Windows configuration, hopefully it works also in a MacOSX configuration.
这个答案基于 Windows 配置,希望它也适用于 MacOSX 配置。
- Say your AMP Server is installed in C:\AMP then your PHP files are in C:\AMP\www if you stick to using a standard configuration.
- In Eclipse you must have the PDT (PHP development tool) and SDK installed. If not get it using the Eclipse 'Install new software' feature. With PDT installed you can create a PHP project. Say you create a PHP project PHP001. By default Eclipse would store the sources for your project PHP001 in a subfolder of your Eclipse workpace, like ..\workspace\PHP001. This is where you need to change the location to C:\AMP\www.
- PHP001 shows in the Eclipse Projects view. You'll see it already shows the PHP files that you have in your wwww folder.
- To add a PHP file, right-click your PHP project, then New PHP file.
- To execute a PHP file, right-click it, Run as, then PHP Web application. Here again Eclipse will propose to start something like localhost/PHP001/your-php-file.php; you need to remove PHP001 level and submit localhost/your-php-file.php instead.
- 假设您的 AMP 服务器安装在 C:\AMP 中,那么如果您坚持使用标准配置,那么您的 PHP 文件将位于 C:\AMP\www 中。
- 在 Eclipse 中,您必须安装 PDT(PHP 开发工具)和 SDK。如果没有使用 Eclipse 的“安装新软件”功能获得它。安装 PDT 后,您可以创建一个 PHP 项目。假设您创建了一个 PHP 项目 PHP001。默认情况下,Eclipse 会将项目 PHP001 的源代码存储在 Eclipse 工作区的子文件夹中,例如 ..\workspace\PHP001。这是您需要将位置更改为 C:\AMP\www 的地方。
- PHP001 显示在 Eclipse 项目视图中。您会看到它已经显示了您在 wwww 文件夹中的 PHP 文件。
- 要添加 PHP 文件,请右键单击您的 PHP 项目,然后单击新建 PHP 文件。
- 要执行 PHP 文件,请右键单击它,选择运行方式,然后单击 PHP Web 应用程序。Eclipse 将再次建议启动类似 localhost/PHP001/your-php-file.php 的内容;您需要删除 PHP001 级别并提交 localhost/your-php-file.php 代替。
This situation might become messy if you create lot of test php files in your project, in which case you may want to develop your phps in an Eclipse folder and copy them to the www folder only when finished using Gilbert Le Blanc's method.
如果您在项目中创建大量测试 php 文件,这种情况可能会变得混乱,在这种情况下,您可能希望在 Eclipse 文件夹中开发您的 php,并且只有在使用 Gilbert Le Blanc 的方法完成后才将它们复制到 www 文件夹。