I'm sure you have already checked the obvious facts that:
- Apache B probably runs as a different user than when you run on the command line
- Apache B has a different path/environment than when you run on the command line
- Apache B runs from a different directory than when you run on the command line