hqt
hqt

Reputation: 30284

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:

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.

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).

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)

So, if I want to run this project, I must copy all and paste to Apache folder. Too handy !!!

Please help me.

Thanks :)

Upvotes: 12

Views: 46829

Answers (6)

Deepak Madhaan
Deepak Madhaan

Reputation: 31

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

Upvotes: 0

Marc
Marc

Reputation: 127

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

I prefer having an adjusted httpd.conf (std location on Windows would be ~\conf\httpd.conf) for the project I'd like to debug.

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.

Upvotes: 0

michel.iamit
michel.iamit

Reputation: 5906

I let the apache config file be in my source code folder (in a folder /etc for example).

In ubuntu you can create a symbolic link in your sites available to this config file in your code source folder:

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 ).

In windows you can also create a symbolic link: google for the command mklink

I am not working a lot with windows, but seems the same option).

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.

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).

Upvotes: 0

humble_wolf
humble_wolf

Reputation: 1668

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.

Upvotes: 2

Patrice Cotte
Patrice Cotte

Reputation: 1

This answer is based on a Windows configuration, hopefully it works also in a MacOSX configuration.

  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.
  2. 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.
  3. PHP001 shows in the Eclipse Projects view. You'll see it already shows the PHP files that you have in your wwww folder.
  4. To add a PHP file, right-click your PHP project, then New PHP file.
  5. 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.

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.

Upvotes: 0

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51485

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.

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.

Edited to add: Here's my Ant script to keep my Eclipse directory and my HTTP directory synchronized. I develop in 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>

Upvotes: 8

Related Questions