Testing local server with MAMP/wordpress on mobile device? [closed]

I use xip.io for this.

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

Use a static IP address for DHCP:

static dhcp IPv4 Address 192.168.1.101

In MAMP PRO, select the host1 you want to use (wp99.dev in this example), and in the Advanced tab use the following as ServerAlias for the general settings:
1 instructions for Apache too in the linked article

ServerAlias wp99.*.xip.io

Before applying the changes and restarting the servers in MAMP, change the settings of the site:

http://wp99.192.168.1.101.xip.io

Save the changes in WordPress, restart the servers in MAMP, login to the site.
Test on any device/computer of the local network.


Instead of changing the site settings, an interesting technique to use in wp-config.php:

require_once('/path/to/Browser-Detection/b5f-browsers.php');
if( b5f_browser_check( 'mobile' ) )
{ 
    define( 'WP_HOME', "http://wp99.{$_SERVER['SERVER_ADDR']}.xip.io");
    define( 'WP_SITEURL',"http://wp99.{$_SERVER['SERVER_ADDR']}.xip.io");
}

This way, the desktop version keeps the nice address, and when viewing in mobile the xip.io address is served.

Here’s a Gist for the file b5f-browsers.php, which uses Chris Schuld’s Browser.php class.


Related:

Leave a Comment