Step-by-Step: Import to Local WordPress Environment Using Lando
Sometimes, importing an existing WordPress site into my local environment using Docker or Local by Flywheel can be a pain. So, I decided to give Lando a try as I had used it before for a non-WordPress site and found it very easy to use. Of course, initially, using Lando was a pain—but not much of one. Within an hour, I had everything set up and working smoothly.
Why Import to Local WordPress Environment?
Importing to a local WordPress environment is an essential step for developers and site owners looking to test updates, plugins, themes, or customizations without risking the live site. Working locally offers faster performance and eliminates the reliance on internet speed or hosting server loads, making development more efficient.
Developing WordPress locally using Lando on an M1 Mac can make your life easier, especially when you need to import to a local WordPress environment with an existing site that contains many plugins. Here’s a complete guide based on my experience, covering everything from setting up the correct PHP version to fixing plugin-specific issues like Solid Security Pro.
1. Setting Up a Local WordPress Environment for Importing
To avoid compatibility issues with Composer dependencies and other PHP requirements, it’s crucial to set the correct PHP version in your lando.yml file from the beginning:
name: my-website
recipe: wordpress
config:
webroot: .
database: mariadb
services:
appserver:
type: php:8.0 # Update to PHP 8.0 or higher as required by your project
build_as_root:
- apt-get update -y && apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev
pma:
type: phpmyadmin
image: phpmyadmin:latest # Ensure this version supports ARM, or find an ARM-compatible version
hosts:
- database
platform: linux/arm64
database:
type: mariadb
image: mariadb:10.5.8 # Replace with a specific ARM-compatible version if necessary
platform: linux/arm64
tooling:
npm:
service: appserver
composer:
service: appserver
wp:
service: appserver
proxy:
appserver:
- my-website.lndo.site
After setting the PHP version, run:
lando rebuild -y
This ensures your environment uses the specified PHP version.
2. Importing the Database and Updating URLs
To import your existing WordPress database into your local WordPress environment:
lando db-import backup.sql
After importing, perform a search and replace to update URLs for your local environment:
lando wp search-replace 'https://www.my-website.com' 'https://my-website.lndo.site' --skip-columns=guid
lando wp search-replace 'localhost:10039' 'my-website'
lando wp search-replace 'https://www.my-website.com' 'https://my-website.lndo.site'
If you prefer using phpMyAdmin to update URLs:
UPDATE wp_options SET option_value = REPLACE(option_value, 'https://www.my-website.com', 'https://my-website.lndo.site') WHERE option_name = 'siteurl' OR option_name = 'home';
UPDATE wp_posts SET guid = REPLACE(guid, 'https://www.my-website.com', 'https://my-website.lndo.site');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'https://www.my-website.com', 'https://my-website.lndo.site');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'https://www.my-website.com', 'https://my-website.lndo.site');
This ensures that all references to the production URL are correctly replaced for local development. The –skip-columns=guid flag prevents GUID changes.
3. Adjusting the Table Prefix (If Needed)
If your database uses a non-standard table prefix (e.g., ds_ instead of wp_), update your wp-config.php file:
领英推荐
$table_prefix = 'ds_';
Ensure that any related usermeta entries and options in your database reflect this prefix correctly.
4. Creating a Fresh wp-admin Experience
If you encounter issues logging in or accessing wp-admin, you can create a fresh wp-admin user via the WordPress CLI:
lando wp user create newadmin [email protected] --role=administrator --user_pass=securepassword
Adjust the username, email, and password as needed.
5. Saving Permalinks
After completing the database import and adjustments, visit Settings > Permalinks in the WordPress admin area and click Save Changes. This regenerates .htaccess rules and ensures URLs function correctly.
6. Handling Plugin-Specific Issues
Some plugins may require special handling or adjustments for local development. For example:
Solid Security Pro: Ensure that constants like DISALLOW_FILE_EDIT and FORCE_SSL_ADMIN are defined correctly in wp-config.php. Wrap them in conditional checks to prevent redefinition warnings:
if (!defined('DISALLOW_FILE_EDIT')) {
define('DISALLOW_FILE_EDIT', true);
}
if (!defined('FORCE_SSL_ADMIN')) {
define('FORCE_SSL_ADMIN', false); // Set to false for local development
}
Caching Plugins: Temporarily disable caching plugins during development to avoid issues with stale data.
7. Final Troubleshooting Tips
If you continue to encounter issues:
Enable Debugging: Add the following to wp-config.php to log errors:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 1);
Check File Permissions: Ensure directories have 755 permissions and files have 644 permissions.
Review Logs: Check the wp-content/debug.log file and lando logs for more details.
?
By following these steps, you can successfully set up and troubleshoot a Lando WordPress environment on an M1 Mac, making it simple to import to your local WordPress environment and create a smooth development workflow.
The full article including FAQs can be found by following this link. https://www.darkstarmedia.net/web-design-coding/import-to-local-wordpress/