How do I make my PHP Source installation use the libraries inside of /usr/local/programname/lib instead or /usr/local/lib?
The system default convention is used in so many places that you are creating big overhead for yourself by using different directories.
The easiest way is to use Docker containers for your testing. That way you can use default system locations inside the container.