简体   繁体   中英

Use MAMP to open website on another pc - only see db content

I'm trying to make access to my MAMP localhost from my mobile phone and other Windows PC. I'm currently using a Mac.

While I can see the database content but the website doesn't render as usual (no images, stylesheet, etc…).

Therefore I assume the other PC can access the database but can't use the files. Maybe the PHP files are not processed?

Does anyone have a suggestion on what could be the cause and how to fix it?

However I can see the database content but the website doesn't render as usual (no images, stylesheet, etc)

Does your site on the MAMP install use hardcoded URLs for CSS, images & JavaScript? Something like this:

http://localhost/images/a_great_image.png

If so, when a remote host accesses your site, they will not be able to see the content on URLs like that since they will be pointing to localhost and localhost is an address directly connected to the local machine. Meaning that any machine will only see localhost as their actual machine; never a remote machine. It's a loopback hostname for testing & restricted local access.

The two solutions you have is to do the following:

  • Change the localhost address to be the IP address of your computer on the network. So if your computer is reached via the IP 10.0.1.3 , then the URL would be: http://10.0.1.3/images/a_great_image.png .
  • Change the URLs to be relative URLs such as /images/a_great_image.png and maybe use base tag like this <base href="http://10.0.1.3/" target="_blank"> on each page. That way all your links in URLs are relative, but the base is set once & is always http://10.0.1.3/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM