Dashboard > Development > Eclipse and Apache
Development Log In   View a printable version of the current page.
Eclipse and Apache
Added by Joe Selman, last edited by Brandon Philips on May 13, 2004  (view change)
Labels: 
(None)

Warning This documentation is outdated and probably broken – proceed at your own risk

This guide covers how to set up a local apache server for use with php development in eclipse. The server runs on port 8080 on your local machine, and only allows access from your local machine.

Note that you must have eclipse installed and set up along with the phpeclipse plugin.

Install apache and php

Install the apache, php4, php4-mysql, mysql-client, and mysql-server packages (if they aren't already installed).

sudo apt-get install apache php4 php4-mysql mysql-server mysql-client

Set up an apache running directory

Go into your home directory, and create a directory called 'apache'. This will be where the server will contain all the config and log files.

cd
mkdir apache

Download the sample config file for apache into your newly created apache running directory as httpd.conf . There are a few lines you need to change in the config in order to get the server to run correctly.

Find the ServerRoot directive, which should look like this:

ServerRoot /change/this/to/your/apache/dir

Change this to point to your apache running directory, created earlier. For example, mine points to /nfs/guy/u1/selman/apache . Be sure not to put a slash at the end of the directive.

Next, find the DocumentRoot directive, which should look like:

DocumentRoot /change/to/your/eclipse/dir

Change this to point to your eclipse directory. All files within the directory will be accessible by the server.

A few lines down, you should see a directive that looks like:

<Directory /change/to/your/eclipse/dir/>

Change this to point to the same directory you specified in the DocumentRoot directive.

Make a custom copy of apachectl

apachectl is a handy script for handling apache processes. Locate this file (which is usually located in /usr/sbin/apachectl) and copy it to your apache directory.

cp /usr/sbin/apachectl ~/apache

Again, we need to modify the file to make it work with our local apache service. Open it with your favorite editor and look for the line in the configuration section that specifies where the PID file is located. Change it so it points to the apache.pid file (which will be created upon the first server launch) in your new apache directory. For instance, mine looks like:

PIDFILE='/nfs/guy/u1/selman/apache/apache.pid'

Now, modify the HTTPD variable so that apache knows to use an alternate config file than the one located at /etc/apache/httpd.conf. Make it point to your (renamed) httpd.conf that you modified earlier. Again, my file looks like:

HTTPD='/usr/sbin/apache -f /nfs/guy/u1/selman/apache/httpd.conf'

That is all the configuration required. Test the server by running your apachectl command.

apachectl start

If everything started fine, and you can see your eclipse directory at http://localhost:8080/ then proceed to the next step.

Setting up eclipse to recognize the apache server.

Launch eclipse. Click on Window -> Preferences, then click on PHP in the left box. Here are the values you should change:

  • Click on the 'Use External Browser' checkbox, then fill in your favorite browser in the 'External Browser Command' window. Mozilla's profile system can really wreck havoc with you, so if you're like me and you always have a mozilla process running, you can change this to say 'firefox -remote openurl({0}, new-window)' and a new window will be opened in your workspace every time you view a php file with the browser. For more information on the -remote option, visit this page.
  • Fill in the localhost box with http://localhost:8080 . Note there is no / at the end.
  • Set the DocumentRoot box to your eclipse directory.
  • In the apache box, make sure that all the checkmarks that say 'Run in background mode' are checked. Then fill in the start apache, stop apache, and restart apache boxes with 'start', 'stop', and 'restart' respectively.
  • Finally, set the 'Apache' box to the full path of your custom apachectl file. Mine is set to '/nfs/guy/u1/selman/apache/apachectl'.

Conclusion

Test out the configuration to make sure everything works. Click on PHP/Apache -> Start Apache. Then right click on one of your php files and select 'Open PHP browser'. If everything worked correctly, a browser window should launch, showing you the output of your php file.


There is an Apache forum that you can search or post questions there: http://www.nabble.com/Apache-f90.html - it's hosted by Nabble which archives all the mailing lists from Apache.

Posted by Will Lin at Aug 02, 2005 18:17 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.7 Build:#524 Jul 28, 2006) - Bug/feature request - Contact Administrators