简体   繁体   English

为Eclipse配置Apache HTTP Server

[英]Config Apache HTTP Server for Eclipse

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. 1)当我添加新服务器时,列表中没有Apache HTTP服务器的类别。 Just has Apache Tomcat. 仅有Apache Tomcat。 So, I click into download additional server adapter-->still don't have in list. 因此,我单击进入下载其他服务器适配器->列表中仍然没有。

2) So, I search. 2)所以,我搜寻。 I point to location I have installed. 我指向我已安装的位置。 Good, Eclipse sees that is a HTTP Server. 很好,Eclipse认为这是一个HTTP Server。 And Eclipse sees folder to put project into for me (because I use LAMP so that folder isn't in Apache folder). Eclipse会为我找到要放入项目的文件夹(因为我使用了LAMP,所以该文件夹不在Apache文件夹中)。

But here is my problem. 但是,这是我的问题。 When I want to run a new PHP Project. 当我想运行一个新的PHP项目时。 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 !!! 而且,在服务器列表中,没有HTTP Server,所以,我不知道如何选择Apache HTTP Server! (because Eclipse doesn't see which server that I have defined, eclipse just find adapter first) (因为Eclipse没有看到我定义的服务器,所以eclipse只能先找到适配器)

So, if I want to run this project, I must copy all and paste to Apache folder. 因此,如果要运行此项目,则必须全部复制并粘贴到Apache文件夹中。 Too handy !!! 太方便了!

Please help me. 请帮我。

Thanks :) 谢谢 :)

Apache's HTTP server and Eclipse don't communicate with each other. Apache的HTTP服务器和Eclipse无法相互通信。 The servers under Windows -> Preference -> Server are Java servers like Tomcat and Glassfish. Windows->首选项->服务器下的服务器是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. 您需要做的是在Eclipse中定义您的Web项目,然后在httpd.conf文件中为HTTP服务器定义该目录。 Or, since you're already set up, write an Ant script in Eclipse to copy the PHP files to your HTTP folder. 或者,由于已经完成设置,因此可以在Eclipse中编写一个Ant脚本以将PHP文件复制到HTTP文件夹中。

Edited to add: Here's my Ant script to keep my Eclipse directory and my HTTP directory synchronized. 编辑添加:这是使我的Eclipse目录和HTTP目录保持同步的Ant脚本。 I develop in Windows. 我在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>

转到apache> conf> httpd.conf文件并将其打开。在“ ServerName localhost:80”下面,将文档根目录和目录更改为工作目录(在Eclipse中为工作区)。现在,您可以通过键入以下内容运行php文件/项目在任何浏览器中的完整URL,或者如果要通过Eclipse运行它,则还必须通过在映射选项卡中同步服务器副本和本地副本(在这种情况下,两者相同)来配置运行。

This answer is based on a Windows configuration, hopefully it works also in a MacOSX configuration. 该答案基于Windows配置,希望它也可以在MacOSX配置中使用。

  1. 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. 假设您的AMP服务器安装在C:\\ AMP中,那么如果您坚持使用标准配置,则PHP文件在C:\\ AMP \\ www中。
  2. In Eclipse you must have the PDT (PHP development tool) and SDK installed. 在Eclipse中,您必须安装PDT(PHP开发工具)和SDK。 If not get it using the Eclipse 'Install new software' feature. 如果没有,请使用Eclipse“安装新软件”功能来获取。 With PDT installed you can create a PHP project. 安装了PDT后,您可以创建一个PHP项目。 Say you create a PHP project PHP001. 假设您创建一个PHP项目PHP001。 By default Eclipse would store the sources for your project PHP001 in a subfolder of your Eclipse workpace, like ..\\workspace\\PHP001. 默认情况下,Eclipse会将项目PHP001的源存储在Eclipse工作区的子文件夹中,例如.. \\ workspace \\ PHP001。 This is where you need to change the location to C:\\AMP\\www. 在这里您需要将位置更改为C:\\ AMP \\ www。
  3. PHP001 shows in the Eclipse Projects view. PHP001显示在Eclipse Projects视图中。 You'll see it already shows the PHP files that you have in your wwww folder. 您会看到它已经显示出您wwww文件夹中的PHP文件。
  4. To add a PHP file, right-click your PHP project, then New PHP file. 要添加一个PHP文件,请右键单击您的PHP项目,然后单击“新建PHP”文件。
  5. To execute a PHP file, right-click it, Run as, then PHP Web application. 要执行PHP文件,请右键单击它,然后依次单击“运行方式”和“ PHP Web应用程序”。 Here again Eclipse will propose to start something like localhost/PHP001/your-php-file.php; Eclipse在这里再次建议启动类似localhost / PHP001 / your-php-file.php的东西; you need to remove PHP001 level and submit localhost/your-php-file.php instead. 您需要删除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文件夹。

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. 因此,不确定这是否可以在Windows中运行,但如果可以,对我来说,这是开发任何Web项目的最简单方法。 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). 将所需的内容和在真实服务器上使用的方式相同的方式保存在源文件夹中(我使用一些部署和构建脚本来执行此操作,但这是个概念,对我来说很有效)。

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后端和通常的数据库存储),并从其标准安装路径C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\bin运行Apache 2.2 httpd.exe

I prefer having an adjusted httpd.conf (std location on Windows would be ~\\conf\\httpd.conf ) for the project I'd like to debug. 我更喜欢为我要调试的项目调整httpd.conf(Windows上的std位置为~\\conf\\httpd.conf )。

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

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. 您可以下载Ant,然后以您的项目运行的方式运行,有两个选项:1.Ant构建2.Ant构建,选择第二个复选框,选中war(生成战争)复选框,您的构建将生成,您的将创建war,然后将该.war文件放入apache服务器的webapps文件夹中。 Hope it helps 希望能帮助到你

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

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