How do I create a WP sandbox for development on localhost (raspberry pi 4) without being redirected to the live site?

I bought a WordPress website through Flippa and I need to set up a development area that will let me test changes and updates before I put them on the live site. I am brand new to this so I want to make sure I don't break the existing site. I have set up a raspberry pi 4 with a LAMP setup. The Linux is Buster with Apache2, MariaDB, and PHP 7.3.

I finally figured out how to attach the database to a new WordPress install using PHPMyAdmin to import the existing database into a blank one. I merged the existing source code with the WordPress install in the /var/www/html folder using the following command. (5469-6696 is the name of the flash drive)

sudo cp -RT /media/pi/5469-6696 /var/www/html

I deleted the wp-config.php file and started the WP installation. I attached the database to the setup of WordPress and it tells me "You appear to have already installed WordPress. To reinstall please clear your old database tables first."

If I delete the database tables I don't have anything to test with but if I click the login button it takes me to the live site and reentering the IP address of the Pi does the same thing. I want to use the Pi as a local testing server. How do I stop the install from connecting to the live site?

Topic sandbox localhost Wordpress

Category Web


You need to change the url of the copied website to not have a redirection

Assuming your live url is https://oldurl.com and your sandbox url is http://mysandboxurl.com (replace the values with your actual urls)

You can do so with either a define in your wp-config.php

define( 'WP_HOME', 'http://mysandboxurl.com' );
define( 'WP_SITEURL', 'http://mysandboxurl.com' );

Or changing the option_value of siteurl and home to http://mysandboxurl.com in your wp_options table

Or using wp cli

wp search-replace https://oldurl.com http://mysandboxurl.com --all-tables

To replace all links in your content as well to avoid being redirected via your menu to the live website

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.