How to set up a local development environment for WordPress with docker and migrate to live hosting
This guide walks you through creating a local WordPress development environment using Docker, building and testing your site, and then migrating it to live hosting. It focuses on practical steps you can complete in a few hours, with configuration choices that keep development fast and deployments reliable. Follow the sequence to avoid common pitfalls and ensure a smooth go-live.
Step 1: Install prerequisites
Install Docker Desktop (or Docker Engine + Docker Compose) and Git on your machine; expect 10–30 minutes depending on downloads. Ensure Docker has at least 2 GB RAM allocated and that ports 80 and 3306 are free to avoid conflicts during container startup.
[Illustration: computer desktop showing Docker whale icon and terminal window with git clone command]
Step 2: Create project skeleton
Make a project folder and create docker-compose.yml, a Dockerfile for custom PHP if needed, and a .env file with passwords. Keep passwords simple for local use (e.g., DB_PASSWORD=localpass123) and store files under a projects directory so volume mounts are predictable.
[Illustration: file explorer view with project folder and files docker-compose.yml .env Dockerfile]
Step 3: Define services in Compose
Write docker-compose.yml defining services: wordpress (official image), mysql:5.7 or mariadb:10.3, and optionally phpmyadmin and traefik or nginx reverse proxy. Set volumes for ./wordpress:/var/www/html and ./db_data:/var/lib/mysql, expose ports like 8080:80 and 3307:3306 for local access and isolation.
[Illustration: text editor showing docker-compose.yml with services wordpress and mysql and port mappings]
Step 4: Start containers and complete install
Run docker-compose up -d and wait 30–90 seconds for containers to initialize. Visit http://localhost:8080 and complete the WordPress setup (site title, admin user with strong password). Verify DB connectivity and that the site loads without errors.
[Illustration: browser window loading local WordPress setup page on localhost:8080]
Step 5: Develop and test locally
Install themes and plugins, add sample content, and test functionality for 1–3 hours or as needed. Use WP_DEBUG=true in wp-config.php for development logging, and run automated tests or manual checks across 3 browsers to catch issues early.
[Illustration: developer editing WordPress theme files in code editor with browser preview on the right]
Step 6: Prepare for migration
Export the database using WP-CLI or phpMyAdmin and copy the wp-content folder; produce a zip and an SQL file. Replace local URLs (e.g., http://localhost:8080) with the live URL in the SQL using search-replace tools and create a checksum or note file sizes and modified dates for verification.
[Illustration: terminal showing wp export command and file archive.zip being created with wp-content and database.sql]
Step 7: Deploy to live hosting
On the live host, upload wp-content zip and import SQL into the remote database, then update wp-config.php with production DB credentials and set correct file permissions (chown www-data:www-data and chmod 755/644). Test the site on the live domain, clear caches, and monitor logs for 24–48 hours after go-live.
[Illustration: server control panel showing file upload and database import progress]
- Use volumes for code so edits are instant; bind mount ./wordpress to /var/www/html for 1:1 editing.
- Commit theme/plugin code to Git and tag releases; keep the database out of version control.
- Use WP-CLI for repeatable tasks: export/import takes 10–60 seconds for typical sites under 50 MB.
- Keep a staging environment that mirrors production with identical PHP and MySQL versions. 1:1 parity reduces surprises.
- Automate backups: schedule daily DB dumps and weekly full backups; keep at least 14 days of retention.
- Use environment variables for secrets and never hardcode production passwords into Docker images or public repos.
- Do not expose local containers directly to the public internet without a proper firewall and TLS; local setups are for development only.
- Never commit production credentials or database dumps containing user data to public repositories; remove or anonymize sensitive data before sharing.
- When replacing URLs in SQL, use a serialized-aware tool (like WP-CLI search-replace) to avoid corrupting theme or plugin data.
- Always test file permissions on the live server; incorrect permissions (e.g., 777) create security risks and can break updates.
Was this guide helpful?
More Computers & Electronics guides
How to set up Git, create a repository, and commit code locally
Setting up Git and committing code locally is a small, reliable skill that pays off immediately. In about 10–20 minutes you can install Git, create a repository, and make your first commits so your work is tracked and easy to manage. Follow these clear steps to get a solid local workflow going.
How to migrate email from one provider to another without losing folders or contacts
Migrating email between providers can feel risky, but with a plan you can preserve folders, labels, and contacts while minimizing downtime. This guide walks you through a careful, step-by-step transfer you can complete in a few hours to a couple days depending on mailbox size. Follow the checklist and you’ll keep structure and address data intact.
How to clean dust and replace a laptop fan to fix overheating and throttling
Overheating and CPU/GPU throttling are often caused by dust buildup or a failing fan. This guide walks you through safely cleaning dust and replacing a laptop fan to restore cooling performance and reduce temperature spikes. Read through all steps, gather basic tools, and work in a well-lit, static-safe area.