在移动设备上使用 MAMP/wordpress 测试本地服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16385547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:14:11  来源:igfitidea点击:

Testing local server with MAMP/wordpress on mobile device?

wordpresslocalhostmamp

提问by Adam

I am currently developing a wordpress site locally using MAMP PRO, which obviously involves using a local database.

我目前正在使用 MAMP PRO 在本地开发一个 wordpress 站点,这显然涉及使用本地数据库。

I would like to test this site on my iPhone via a remote link. I have managed to do this by typing the following into my mobile phone URL...

我想通过远程链接在我的 iPhone 上测试这个网站。我设法通过在我的手机 URL 中键入以下内容来做到这一点...

192.234.2.32:8888 

(IP Address : Port number)

(IP 地址:端口号)

The problem is the index page is displayed but with no CSS styling. Then when I click on another page, it says the page cannot be found

问题是显示了索引页但没有 CSS 样式。然后当我点击另一个页面时,它说找不到该页面

It seems it has connected to the server properly, but not to the wordpress database. (at least I think this is the problem)

它似乎已正确连接到服务器,但未连接到 wordpress 数据库。(至少我认为这是问题所在)

Does anyone have any information on how to get this working or point me in the right direction? Do you need another application to do this, or can it be done with mamp/IP address etc?

有没有人有任何关于如何让这个工作或指向正确方向的信息?您是否需要其他应用程序来执行此操作,还是可以使用 mamp/IP 地址等来完成?

Thanks in advance

提前致谢

采纳答案by Adam

Have answered my own question, found this great article which did the trick http://www.designshifts.com/view-local-wordpress-website-on-your-iphone-or-ipad-with-mamp/

已经回答了我自己的问题,找到了这篇很棒的文章,它可以解决问题http://www.designshifts.c​​om/view-local-wordpress-website-on-your-iphone-or-ipad-with-mamp/

回答by Jaap Nauta

  • In general settings WordPress; Change The WordPress address from
    localhost to the IP address of your desktop pc/mac (URL)
  • In the MAMP PRO general tab; Check; via Xip.io (LAN only)and copy that address
  • In general settings WordPress Paste the Xip.io addres in Site Address (URL)
  • you can acces the mobile devices via; http://localhost.IPAddressOfYourLocalComputer.xip.io
  • 在一般设置 WordPress; 将 WordPress 地址从
    localhost更改为桌面 pc/mac 的 IP 地址(URL)
  • 在 MAMP PRO 常规选项卡中;查看; 通过 Xip.io(仅限 LAN)并复制该地址
  • 在一般设置中 WordPress 将 Xip.io 地址粘贴到站点地址 (URL) 中
  • 您可以通过以下方式访问移动设备; http://localhost.IPAddressOfYourLocalComputer.xip.io

screenshot Wordpress enter image description here

截图 WordPress 在此处输入图片说明

回答by bobzIlla

I've been able to make a LAN + IOS testing scheme work on OS 10.11 without changing Mamp Pro (4.5) default ports, or change the domain settings in WP admin. Here's all the relevant bits:

我已经能够使 LAN + IOS 测试方案在 OS 10.11 上运行,而无需更改 Mamp Pro (4.5) 默认端口,或更改 WP admin 中的域设置。这是所有相关的位:

  • In Finder set up root folder inside "sites" folder i.e. ~/sites/MAMP-hosted/yourdomain.com
  • Ensure your mac is using a static IP address, launch Mamp Pro and in the General tab, select that static IP for yourdomain.comin the IP address drop down. localhostshould remain the default: *
  • In the yourdomain.com> Databases tab, select the database for yourdomain.com(localhost doesn't need to be assigned one)
  • All remaining General tab settings are default including name resolution, only etc/hosts option checked
  • at the bottom, the localhost > document root should point to the "MAMP-hosted" folder, and yourdomain.com> document root should point to the yourdomain.comfolder.
  • 在 Finder 中,在“sites”文件夹中设置根文件夹,即 ~/sites/MAMP-hosted/yourdomain.com
  • 确保您的 mac 使用静态 IP 地址,启动 Mamp Pro 并在常规选项卡中,yourdomain.com在 IP 地址下拉列表中选择该静态 IP 。localhost应保持默认:*
  • yourdomain.com> Databases 选项卡中,选择数据库yourdomain.com(不需要为localhost 分配)
  • 所有剩余的常规选项卡设置均为默认设置,包括名称解析,仅选中 etc/hosts 选项
  • 在底部,本地主机 > 文档根目录应指向“MAMP 托管”文件夹,而yourdomain.com> 文档根目录应指向该yourdomain.com文件夹。

then adjust wp-config to look like this:

然后调整 wp-config 看起来像这样:

define('DB_NAME', 'name-of-your-database');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'root');

/** MySQL hostname */
define('DB_HOST', 'localhost');

define( 'WP_SITEURL', 'http://your-static-IP' );
define( 'WP_HOME', 'http://your-static-IP' );

http://your-static-IPshould bring up the site on any device on your local network, and http://your-static-IP/wp-loginfor admin access.

http://your-static-IP应该在本地网络上的任何设备上打开该站点,并http://your-static-IP/wp-login进行管理员访问。

If you write to the database (publish posts, etc) with wp-admin in that state you may need to do some post migration clean up with a plugin like Velvet Blue to remove that IP address.

如果您在该状态下使用 wp-admin 写入数据库(发布帖子等),您可能需要使用 Velvet Blue 之类的插件进行一些迁移后清理以删除该 IP 地址。

I haven't experimented with this particular scheme and MAMP on-board SSL, however it's not difficult to switch back once the site is ready to migrate to its dedicated host.

我还没有尝试过这个特定的方案和 MAMP 板载 SSL,但是一旦站点准备好迁移到其专用主机,切换回并不困难。

回答by quickshiftin

I prefer to use DNSto deal with local development for mobile. This way you can still use the same IP address for all your local sites, but have a different name for each one (NameBasedVirtualHosts)

我更喜欢使用 DNS来处理移动设备的本地开发。通过这种方式,您仍然可以对所有本地站点使用相同的 IP 地址,但每个站点使用不同的名称 ( NameBasedVirtualHosts)

回答by Rich

you can do this by simply editing the hosts file on your mac.

您可以通过简单地编辑 Mac 上的主机文件来完成此操作。

Or use a tool like https://www.macupdate.com/app/mac/40003/hosts

或者使用像https://www.macupdate.com/app/mac/40003/hosts这样的工具

Point all your domains to the IP of the MAMP host computer, and put the mamp web service on port 80.

将所有域指向 MAMP 主机的 IP,并将 mamp Web 服务放在端口 80 上。

use www.domain.dev or similar for the domain names.

使用 www.domain.dev 或类似域名作为域名。