I have setup MAMP on Windows 10 successfully. I want to work on WordPress sites locally and commit changes to the live site via Git. (Update: I've answered my own question below.)
I get that a common workflow is to run a SQL query to edit all the absolute links from www.mysite/internal-link/sample.html to localhost/internal-link/sample.html and back, but isn't it (a) safer not to touch the database and (b) faster simply to comment/uncomment a few lines in a .conf file each time one works on the site?
Assuming the answer to question (1) is yes, how do I get the hosts, httpd.conf, httpd-vhosts.conf, and .htaccess files working so that if I go to "www.mysite" in the browser, it finds the WP installation in the corresponding local folder (e.g. c:/MAMP/htdocs/mysite-dev/*) so that the local WordPress "thinks" it's the live site?
I'm running PHP 7.4.1 in MAMP 4.2 (not pro). Currently, when I go to localhost
in my browser with Apache and MySQL servers on, it shows the site in c:/MAMP/htdocs/example1-local-folder-name/
. If I go to /
it goes to the live site. My MAMP configuration is as follows:
drivers\etc\hosts:
127.0.0.1 example1
::1 example1
httpd.conf:
ServerName example1
DocumentRoot "C:\MAMP\htdocs"
<Directory /> # "default" configuration unchanged
Options FollowSymLinks ExecCGI
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory "C:\MAMP\htdocs"> # This is the only line I changed
Options Indexes FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example1
ServerAlias www.example1 *.example1
DocumentRoot "C:/MAMP/htdocs/example1-local-folder-name"
ServerAdmin [email protected]
ErrorLog "example1-error_log"
CustomLog "example1-access_log" common
</VirtualHost>
.htaccess (in c:/MAMP/htdocs/example1-local-folder-name/):
# I don't know what to put here aside from the standard WP rewrite block.
# For now I have this file commented out
Thanks for any pointers & apologies if this question has been asked before.
I have setup MAMP on Windows 10 successfully. I want to work on WordPress sites locally and commit changes to the live site via Git. (Update: I've answered my own question below.)
I get that a common workflow is to run a SQL query to edit all the absolute links from www.mysite.org/internal-link/sample.html to localhost/internal-link/sample.html and back, but isn't it (a) safer not to touch the database and (b) faster simply to comment/uncomment a few lines in a .conf file each time one works on the site?
Assuming the answer to question (1) is yes, how do I get the hosts, httpd.conf, httpd-vhosts.conf, and .htaccess files working so that if I go to "www.mysite.org" in the browser, it finds the WP installation in the corresponding local folder (e.g. c:/MAMP/htdocs/mysite-dev/*) so that the local WordPress "thinks" it's the live site?
I'm running PHP 7.4.1 in MAMP 4.2 (not pro). Currently, when I go to localhost
in my browser with Apache and MySQL servers on, it shows the site in c:/MAMP/htdocs/example1-local-folder-name/
. If I go to https://example1.org/
it goes to the live site. My MAMP configuration is as follows:
drivers\etc\hosts:
127.0.0.1 example1.org
::1 example1.org
httpd.conf:
ServerName example1.org
DocumentRoot "C:\MAMP\htdocs"
<Directory /> # "default" configuration unchanged
Options FollowSymLinks ExecCGI
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory "C:\MAMP\htdocs"> # This is the only line I changed
Options Indexes FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example1.org
ServerAlias www.example1.org *.example1.org
DocumentRoot "C:/MAMP/htdocs/example1-local-folder-name"
ServerAdmin [email protected]
ErrorLog "example1-error_log"
CustomLog "example1-access_log" common
</VirtualHost>
.htaccess (in c:/MAMP/htdocs/example1-local-folder-name/):
# I don't know what to put here aside from the standard WP rewrite block.
# For now I have this file commented out
Thanks for any pointers & apologies if this question has been asked before.
By default, Windows does not allow DNS redirection!
There is no set of commands within hosts, httpd.conf, etc that will cause 127.0.0.1 sample.com
in your hosts file to redirect all requests for sample.com
to localhost.
(That said, I experimented with various configurations of the standard hosts line and determined that (on Win 10 and MAMP), if you use 127.0.0.1 sample-com
in the hosts file, and ServerName sample-com
in the httpd-vhosts.conf file, you will get the local site by typing sample-com
in the browser (without the word "localhost"). However, this is useless, as it would still require you to run UPDATE commands to change the live url throughout your WordPress database.)
In addition to no redirection, if you have 127.0.0.1 *.sample.com
in your Windows hosts file, the wildcard does nothing -- unless you have a "helper" program to add functionality to the internal TCP/IP engine.
One such helper program is here: https://coredns.io/ or https://github.com/coredns/coredns
I will post an update when I have time to test that setup.
Credit goes to this post for the needle in the haystack that led me to Coredns.