To connect your WordPress site on Forge with a GitHub repository and clone it to your local environment, you can follow these steps:
-
Create a GitHub Repository: If you haven't already, create a new repository on GitHub to store your WordPress site's code.
-
Initialize a Git Repository on Forge: Connect to your server via SSH where your WordPress site is hosted. Navigate to the root directory of your WordPress site and initialize a Git repository if you haven't done so already.
cd /path/to/wordpress git init git add . git commit -m "Initial commit" -
Link the GitHub Repository: Add the GitHub repository as a remote to your local Git repository.
git remote add origin https://github.com/your-username/your-repository.gitReplace
https://github.com/your-username/your-repository.gitwith the actual URL of your GitHub repository. -
Push to GitHub: Push your WordPress files to the GitHub repository.
git push -u origin masterYou might need to set up SSH keys or use a personal access token for authentication, depending on your GitHub settings.
-
Clone the Repository Locally: On your local machine, clone the GitHub repository to the desired directory.
git clone https://github.com/your-username/your-repository.git -
Set Up Local Environment: To run WordPress locally, you'll need a local server environment that supports PHP and MySQL. You can use tools like MAMP, XAMPP, or Local by Flywheel to set this up.
-
Import Database: Export the database from your Forge server and import it into your local database server. You can use tools like phpMyAdmin or command-line utilities like
mysqldumpandmysqlfor this. -
Update WordPress Configuration: Update the
wp-config.phpfile in your local WordPress directory to connect to your local database.define('DB_NAME', 'local_database_name'); define('DB_USER', 'local_database_user'); define('DB_PASSWORD', 'local_database_password'); define('DB_HOST', 'localhost');Replace
local_database_name,local_database_user, andlocal_database_passwordwith your local database details. -
Update URLs: Since your local environment will have a different URL than your live site, you'll need to update the site URL and home URL in the database. You can use a plugin like WP Migrate DB or run SQL queries to replace the URLs.
-
Run Your Local Site: After setting up your local server and updating the configuration, you should be able to access your local WordPress site by visiting the local server's URL in your web browser.
Remember to exclude sensitive files like wp-config.php and the wp-content/uploads directory from your Git repository by adding them to a .gitignore file. This will prevent sensitive information and large media files from being stored in version control.