The first thing to be aware of is that you didn't just install two instances of apache, you actually used two different installation mechanisms - one by compiling, the other by using the resident dpkg (called via apt) mechanism.
Neither method is more (or less) valid than the other, and, one can't categorically state you have to use only one method; but you've already identified the first issue with using two different mechanisms - your package manager (dpkg) doesn't know anything about your hand-compiled installation.
The reason you ended up with a version of apache from the apt-get install php5, is that built into the php5 package is a number of dependencies. You can query the packaging database for the dependencies with dpkg-query:
# dpkg-query -W -f='${Package} ${Version}\t${Maintainer}\n${Depends}\n' php5
php5 5.2.4-2ubuntu5.6 Ubuntu Core Developers <ubuntu-develdiscuss@lists.ubuntu.com>
libapache2-mod-php5 (>= 5.2.4-2ubuntu5.6) | php5-cgi (>= 5.2.4-2ubuntu5.6),
php5-common (>= 5.2.4-2ubuntu5.6)
You'll see a link to libapache2-mod-php5, which in turn references the apache that was installed.
As to removal - apt-get remove apache2 will remove the version of apache2 installed by the package manager, but it will not touch (nor would you want it to) files that have been manually added - those will require your careful inspection and analysis of the system.
If you are lucky, the make file that did the install when you typed
make install
also has a
make remove
In the case of apache2/httpd - you don't have that luxury, but that's a fairly clean install, as installs go, so you should be able to identify the directory that you installed in, and an
rm -rf /usr/local/apache2 (or wherever you installed apache)
should remove most files placed onto your system.
If you don't have a clean install - you'll need to search for the files that were installed on your system.
One typical way of determining what has been added to your system after an installation done manually (works for everything, not just autoconfig installs) is to run the command:
find / -cmin -2 2>/dev/null | egrep -v '^(/proc|/sys)'
You can then use the output of that command to provide you with a list of files that should be considered for removal.
I realize this isn't a soup-nuts guide to removing what has been placed on your system, but the challenges you are experiencing are precisely why people work so hard to use package managers to manage their system (which, in addition to clean adding/removing of files, also provides a number of other useful benefits, such as binary-verification to see if anything has been modified)
If you want to change the ./configure options if a package, you need to rebuild the package. The easiest way to do this is run:
# apt-get install build-essential devscripts
# apt-get source php5
# cd php5-*
# vim debian/rules
# debuild -us -uc -b
You should now find the rebuild packages in the directory above the source. You can install these using "dpkg -i php5_1.2.3-4_amd64.deb" where the filename is the list of packages you want to install.
Best Answer
Removing a package built and installed from source is not an easy task. Usually, these packages come with a make file which enables you to build and install them. If you did not find any option like
make uninstall
(which is most likely), then you need to remove it manually!If you still need to remove it, you can follow what the
make install
command does and run the necessary commands to reverse its changes.