Resolve urls within the server

Jake M asked:

My problem is urls within my PHP scripts are not resolving correctly. Ie, the domain name I am using in a PHP script doesn’t resolve back to the server when accessed from within the server.

For context; I have a php script that is generating a PDF (uses mpdf library). The PDF is built from a HTML template that has images in it. The image urls are in the format src="/images/foo.png". The PDF generation library complains that:

mPDF error: IMAGE Error ( Could not find image file

I know its an internal server domain resolution issue because if I place that above image url into my browser the image appears.

What do I need to configure on my Cent OS 6.8 VPS to resolve these urls internally? I have added an entry to /etc/hosts but it’s still not resolving (maybe I need to restart some services on the server to enable the change?). My server is with GoDaddy and all of the below was already in the file. I just added to               localhost.localdomain localhost
::1             localhost localhost.localdomain localhost6 localhost6.localdomain6
XX.XX.XXX.222  sXXX-XXX-XX-71 ip-XX-XX-XXX-222

My answer:

You need to place the correct IP address and hostname in /etc/hosts and remove the wrong one.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.