Here is an easy way to test a local site on your mobile devices (or any computers on your network for that matter), thanks to xip.io.
- You will need your local machine ‘s IP address
- A local website with a local domain name (you can easily set these up via Mamp Pro or Anvil).
What is xip.io?
xip.io is a magic domain name that provides wildcard DNS for any IP address. Say your LAN IP address is 10.0.0.1. Using xip.io:
10.0.0.1.xip.io resolves to 10.0.0.1 www.10.0.0.1.xip.io resolves to 10.0.0.1 mysite.10.0.0.1.xip.io resolves to 10.0.0.1 foo.bar.10.0.0.1.xip.io resolves to 10.0.0.1
- Fetch your local server’s IP address. For instance, mine is 192.168.1.39. It might be wise to make it a Fixed ip address. You can do this through the router config options. If you’re not sure how, just search for “[your router make/model] assign IP to computer” or something similar. This isn’t strictly necessary but it will save a lot of hassle down the line if you reboot your router and all the local IPs change.
- Set up your local domain in Mamp. When that is done, your website is now accessible locally (on your local dev machine) via the URL http://my-local-site.dev
- add an alias that you create using this scheme:
At this point, your website is now accessible locally (via
http://my-local-site.dev) and externally (via
- If your site uses a database (like WordPress does), you may need to make sure it recognizes both urls. How to do that depends on your codebase. Here is how to do it for a WordPress instance: edit your local wp-config.php file and use the Alias domain instead of the local domain, and you’re all set!
define('WP_HOME', 'http://my-local-site.dev.192.168.1.39.xip.io'); define('WP_SITEURL', 'http://my-local-site.dev.192.168.1.39.xip.io');