1

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 (https://mywebsite.com/images/foo.png): 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 mywebsite.com to 127.0.0.1.

127.0.0.1               localhost.localdomain localhost mywebsite.com
::1             localhost localhost.localdomain localhost6 localhost6.localdomain6
XX.XX.XXX.222           mywebsite.com sXXX-XXX-XX-71.secureserver.net sXXX-XXX-XX-71 ip-XX-XX-XXX-222.ip.secureserver.net ip-XX-XX-XXX-222
XXX.XXX.XX.71           mywebsite.com
3
  • Could it be due to using https instead of just using http ?
    – MikeD
    Commented Mar 11, 2017 at 1:28
  • @MikeD This github issue seems to suggest it shouldn't affect it. github.com/mpdf/mpdf/issues/135
    – sazr
    Commented Mar 11, 2017 at 1:30
  • Is the website resolving when tried using ping from command line? Does the image actually exist in that location? What does curl -v https://mywebsite.com/images/foo.png say?
    – Sreeraj
    Commented Mar 11, 2017 at 4:46

1 Answer 1

0

Php paths act just like unix paths. (The cd command)
Here you are using relative paths.
.. to go up a folder.
. to stay into the current folder.
~ should be the home folder.
Nothing on the beginning will actually look into the root folder, on your case this is the server path as you defined it in your server config.

Some examples:
src="../images/foo.png"
src="./images/foo.png"
src="~/images/foo.png"
src="../../../images/foo.png"

You may otherwise try to use absolute paths.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .