https://github.com/alfiosalanitri/wordpress-local-tunnel
This repository contains a Docker project that allows you to expose your locally WordPress site online using Cloudflare Tunnel via TryCloudflare. Useful when you want to share a preview of the site under development with a client.
https://github.com/alfiosalanitri/wordpress-local-tunnel
cloudflared tunnel wordpress
Last synced: 4 months ago
JSON representation
This repository contains a Docker project that allows you to expose your locally WordPress site online using Cloudflare Tunnel via TryCloudflare. Useful when you want to share a preview of the site under development with a client.
- Host: GitHub
- URL: https://github.com/alfiosalanitri/wordpress-local-tunnel
- Owner: alfiosalanitri
- License: mit
- Created: 2024-09-04T19:25:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-03T08:53:55.000Z (about 1 year ago)
- Last Synced: 2025-04-03T09:33:11.621Z (about 1 year ago)
- Topics: cloudflared, tunnel, wordpress
- Language: Shell
- Homepage:
- Size: 52.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WordPress Local Tunnel with Docker and Cloudflare Argo
This repository contains a Docker Compose file that allows you to expose your locally developed WordPress site online using Cloudflare Tunnel via TryCloudflare.
Useful when you want to share a preview of the site under development with a client.
## Prerequisites
Before using this script, ensure you have the following installed:
- [Docker and Docker Compose](https://www.docker.com/)
## Features
- **Cloudflare Tunnel:** Exposes your local WordPress site securely over the internet using Cloudflare's `cloudflared` service.
- **Custom WordPress Installation:** Mounts the WordPress installation directory specified in the `.env` file into the Docker container.
- **Database Copy & URL Replacement:**
- Automatically extracts the database credentials from your `wp-config.php` or import the custom dump.sql file inside the `import` directory (placed manually).
- Creates a copy of your local WordPress database (or use the provided dump file) and imports it into the Docker MySQL instance.
- Uses the [Search Replace DB](https://github.com/interconnectit/search-replace-db) script to replace the local URL (specified in `WORDPRESS_LOCAL_URL` in the `.env` file) with the dynamic URL generated by Cloudflare Tunnel.
## Important Note
Make sure that the two variables in the .env file `WORDPRESS_MYSQL_HOST` and `WORDPRESS_MYSQL_PORT` are correct and that the MySQL server is reachable, or alternatively, manually place the previously exported dump.sql file into the import folder.
## Local vs. Online Access
- **Local Access:** Your WordPress site is accessible only from your local machine at the URL specified in your `.env` file, for example: `https://www.example.local`.
- **Online Access:** Once the script is run, Cloudflare Tunnel will provide a dynamic public URL that exposes your site online, such as: `https://dynamic-random-string.trycloudflare.com`. This URL allows anyone to access your WordPress site from anywhere on the internet.
## Getting Started (how to use)
1. **Clone the Repository:**
```bash
git clone https://github.com/alfiosalanitri/wordpress-local-tunnel.git #or download the package zip from latest release
cd wordpress-local-tunnel
```
2. **Configure Your Environment:**
Copy the `.env.example` file to `.env` and modify it according to your setup:
```bash
cp .env.example .env
```
Edit the `.env` file to set the following configurations:
- `COMPOSE_PROJECT_NAME`: Prefix for Docker container names (e.g., `example_preview`).
- `WORDPRESS_LOCAL_URL`: The local URL of your WordPress site (e.g., `https://www.example.local`).
- `WORDPRESS_INSTALL_DIR`: Path to your local WordPress installation directory (e.g., `/var/www/www.example.local/public_html`).
- `WORDPRESS_MYSQL_HOST`: Local MySQL server host from which to export the WordPress installation dump.
- `WORDPRESS_MYSQL_PORT`: Local MySQL server port from which to export the WordPress installation dump.
- `DB_DUMP_ARGS`: Custom dump export options like --column-statistics=0
- `WORDPRESS_DEBUG`: true or false to enable or disable WORDPRESS_DEBUG
- `WORDPRESS_DEBUG_LOG`: true or false to enable or disable WORDPRESS_DEBUG_LOG
- `WORDPRESS_DEBUG_DISPLAY`: true or false to enable or disable WORDPRESS_DEBUG_DISPLAY
- `WEB_DOCKER_PORT`: Port that exposes Apache in Docker (e.g., `8081`).
- `WEB_DOCKER_USER`: User that runs the application inside the Docker container (e.g., `www-data`).
- `MYSQL_DOCKER_PORT`: Port for MySQL in Docker (e.g., `3310`).
- `MYSQL_DOCKER_ROOT_USER`: Root user for the MySQL instance (e.g., `root`).
- `MYSQL_DOCKER_ROOT_PASSWORD`: Root password for the MySQL instance (e.g., `root`).
- `MYSQL_DOCKER_DATABASE`: Name of the database used in Docker (e.g., `${COMPOSE_PROJECT_NAME}`).
3. **Database (optional):**
Place the `dump.sql` file into the **import** folder if you prefer or if the automatic dump from the first step fails for any reason.
4. **Start the Tunnel:**
```bash
./go.sh
```
This will:
- Export your local WordPress database (or use the provided dump file inside import directory) and import it into the Docker MySQL instance.
- Create a backup of the wp-config.php file.
- Create the wp-config.php file with Docker credentials.
- Start MySQL, Apache, and PHP using Docker.
- Mount your WordPress directory into the Docker container.
- Run `cloudflared` to expose your local WordPress site online.
- Replace the old url WORDPRESS_LOCAL_URL with the new Cloudflare url https://...trycloudflare.com
5. **Visit the Site:**
The script will output a URL provided by Cloudflare, such as `https://dynamic-random-string.trycloudflare.com`, which you can use to access your WordPress site from anywhere.
## Stopping the Tunnel and clear all
To stop the running Docker containers and the Cloudflare Tunnel, use:
```bash
./go.sh --stop
```
## Troubleshooting
- **Port Conflicts:** Make sure the ports used in the Docker containers (e.g., 3310 for MySQL, 8081 for Apache) are not in use by other services on your machine.
- **Cloudflare Errors:** If you encounter issues with Cloudflare, ensure you have a stable internet connection and that Cloudflare's service is not down.
- **Database dump issue:** If the first step database_dump fails because it cannot connect to the database for the automatic dump, make sure that the host WORDPRESS_MYSQL_HOST and the user saved in wp-config.php are allowed remote access. On the host machine that houses the Wordpress database, access MySQL and create the user if not already present. Example:
```
# replace with the correct values
CREATE USER ''@'' IDENTIFIED WITH mysql_native_password BY '';
# grant permissions to all or a specific database if preferred
GRANT ALL ON *.* TO ''@'';
```
Alternatively, export the database manually and copy it to the import folder.
## Contributing
Contributions are welcome! Feel free to submit issues, fork the repository, and create pull requests.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- Thanks to [Cloudflare](https://www.cloudflare.com/) for providing the tunneling service.
- This project uses [Docker](https://www.docker.com/) to manage the local WordPress environment.
- Special thanks to [Search Replace DB](https://github.com/interconnectit/search-replace-db) for the URL replacement script used in this project.
## Tested Environments
This script has been tested in a Linux environment. Compatibility with other operating systems may vary.