How to set the Apache parameters for a photo website?


From the photo website, the user can visit the photos of his friends, however he could not visit others’. For example:
User A
His photos:;
His friends: user B, D

The user B, he can see the photos of his friend User A when he typed the URL of the photos in the browser.however,When user C(not A’ friend) typed the same links of the photos of A in the browser, he could not open those URL and can not view those photos.

How to set the apache with the connection to the table information of the database?