Note: this can be only done when you are having cpanel installed on server.
Please try to install GD from shell using the easyapache script.
To install GD from shell :-
Select 7th option
Select PHP and then select GD using space bar.
Select ‘Exit’ and then say ‘Yes’ to save.
Let the script execute completely and you will find GD is installed on your machine.
You mat get an error at the end of the script “httpd not restarted. Please contact your sysadmin”
Just do :-
service httpd stop
service httpd start
You can use the url :- http://serverip/phpinfo.php to check whether GD is installed on your machine.
Well this not the best option to complile Apache, the best way is to do it from WHM
WHM >> MAIN >> SOFTWARE >> APACHE UPDATE
select all the options you need and start compile