Setup your WordPress Projects with GitHub
An Easy Way to Work with Local and Production Environments for WordPress Through GIT. This made working with multiple developers in WordPress.
While I was working with a couple of developers I was struggling with version control and WordPress sometimes makes it difficult to work with a couple in a team.
So I found a cool article on the web about .env files: https://erikpoehler.com/2020/12/30/using-an-env-file-for-database-and-other-credentials/
What this article showed me is that you can use specific .env files for development.
So I created a Ploi instance which allowed me to create a specific environment with .env I also opened up database access for remote so all the developers can have a unified database.
So here are the steps I took to make this happen.
1. Started with a New GIT Repo and a New WordPress Installation
2. I then installed the composer package for the phpdotenv
composer require vlucas/phpdotenv
3. Then I modified the wp-config.php
<?php
/** @desc this loads the composer autoload file */
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
/** @desc this instantiates Dotenv and passes in our path to .env */
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
$dotenv->load();
4. In the wp-config.php variables. You can use the variables from your .env file. Try no to store the .env file on GIT this should be local and server-specific.
defined('WORDPRESS_ENV') or define('WORDPRESS_ENV', $_ENV['WORDPRESS_ENV']);
defined('WP_HOME') or define('WP_HOME', $_ENV['WP_HOME']);
defined('DB_NAME') or define('DB_NAME', $_ENV['DB_NAME']);
defined('DB_USER') or define('DB_USER', $_ENV['DB_USER']);
defined('DB_PASSWORD') or define('DB_PASSWORD', $_ENV['DB_PASSWORD']);
5. Here is a sample .env file you can use.
#--------------------------------------------------------------------------------------------------#
# ENVIRONMENT SETTING #
# It can be anything, but "development", "staging" and "production" are supported out of the box. #
# Do not use "development" on production and viceversa, because it has effect on debug settings. #
#--------------------------------------------------------------------------------------------------#
WORDPRESS_ENV=development
#--------------------------------------------------------------------------------------------------#
# MANDATORY DATABASE SETTINGS #
#--------------------------------------------------------------------------------------------------#
DB_NAME="my-project"
DB_USER="my-project"
DB_PASSWORD="my-password"
#--------------------------------------------------------------------------------------------------#
# HOME PAGE URL #
# Optional, but If not set current server name will be used, e.g. http://www.example.com #
#--------------------------------------------------------------------------------------------------#
WP_HOME="http://localhost:8080"
####################################################################################################
# #
# Most of the times you do NOT need to edit further. #
# Below there's a cheat sheet of all the available settings, all are optional, feel free to delete #
# unused settings when you are done with editing. #
# Note that settings are commented (prefixed with #). Remove comment to be able to use a setting. #
# Edit with care. Do nothing if in doubt. Double check before save. #
# For help see http://codex.wordpress.org/Editing_wp-config.php #
# #
# Table of Contents: #
# - OTHER DATABASE SETTINGS #
# - MULTISITE #
# - CACHE #
# - DEBUG #
# - OTHER PATHS & URLS #
# - WP AUTO-UPDATES #
# - POST & MEDIA SETTINGS #
# - PERFORMANCE #
# - COOKIE #
# - SECURITY #
# - FILESYSTEM #
# - CRON #
# - LANGUAGES #
# - PROXY #
# - MISCELLANEOUS #
# #
####################################################################################################
#--------------------------------------------------------------------------------------------------#
# OTHER DATABASE SETTINGS #
#--------------------------------------------------------------------------------------------------#
#DB_HOST
#DB_CHARSET
#DB_COLLATE
#DB_TABLE_PREFIX
#DO_NOT_UPGRADE_GLOBAL_TABLES
#WP_ALLOW_REPAIR
#CUSTOM_USER_TABLE
#CUSTOM_USER_META_TABLE
#--------------------------------------------------------------------------------------------------#
# MULTISITE #
# As of WP 3.0, you have the ability to create a network of sites by using the multisite feature. #
# See http://codex.wordpress.org/Create_A_Network #
#--------------------------------------------------------------------------------------------------#
#WP_ALLOW_MULTISITE=false
#MULTISITE=false
#MU_BASE=/
#ALLOW_SUBDIRECTORY_INSTALL=false
#SUBDOMAIN_INSTALL=true
#DOMAIN_CURRENT_SITE
#PATH_CURRENT_SITE=/
#SITE_ID_CURRENT_SITE=1
#BLOG_ID_CURRENT_SITE=1
#NOBLOGREDIRECT={$WP_SITEURL}
#UPLOADBLOGSDIR=blogs.dir
#UPLOADS=files
#BLOGUPLOADDIR=files
#WPMU_ACCEL_REDIRECT=false
#WPMU_SENDFILE=false
#--------------------------------------------------------------------------------------------------#
# CACHE #
#--------------------------------------------------------------------------------------------------#
#WP_CACHE
#--------------------------------------------------------------------------------------------------#
# DEBUG #
# If you set WORDPRESS_ENV, default debug values are used based on that. #
#--------------------------------------------------------------------------------------------------#
#WP_DEBUG=true
#WP_DEBUG_LOG=false
#WP_DEBUG_DISPLAY=true
#SAVEQUERIES=true
#SCRIPT_DEBUG=true
#ERRORLOGFILE=/log/error.log
#DIEONDBERROR=true
#--------------------------------------------------------------------------------------------------#
# URLS & PATHS #
# If WP_HOME above is set, all other urls are set properly in the great majority of the cases. #
# For very custom installations you may need to set some of the following. Do nothing if in doubt. #
#--------------------------------------------------------------------------------------------------#
#WP_SITEURL
#WP_CONTENT_DIR=./../wp-content
#WP_CONTENT_URL={$WP_SITEURL}/wp-content
#WP_PLUGIN_DIR={$WP_CONTENT_DIR}/plugins
#WP_PLUGIN_URL={$WP_CONTENT_URL}/plugins
#WPMU_PLUGIN_DIR={$WP_CONTENT_DIR}/mu-plugins
#WPMU_PLUGIN_URL={$WP_CONTENT_URL}/mu-plugins
#WP_TEMP_DIR=tmp
#--------------------------------------------------------------------------------------------------#
# WP AUTO-UPDATES #
#--------------------------------------------------------------------------------------------------#
#AUTOMATIC_UPDATER_DISABLED=false
#WP_AUTO_UPDATE_CORE=false
#CORE_UPGRADE_SKIP_NEW_BUNDLED=true
#--------------------------------------------------------------------------------------------------#
# POST & MEDIA SETTINGS #
#--------------------------------------------------------------------------------------------------#
#AUTOSAVE_INTERVAL=60
#EMPTY_TRASH_DAYS=30
#WP_POST_REVISIONS=true
#MEDIA_TRASH=false
#IMAGE_EDIT_OVERWRITE=true
#--------------------------------------------------------------------------------------------------#
# PERFORMANCE #
#--------------------------------------------------------------------------------------------------#
#COMPRESS_CSS=false
#COMPRESS_SCRIPTS=false
#CONCATENATE_SCRIPTS=false
#ENFORCE_GZIP=false
#--------------------------------------------------------------------------------------------------#
# COOKIE #
#--------------------------------------------------------------------------------------------------#
#COOKIEHASH
#PASS_COOKIE
#LOGGED_IN_COOKIE
#AUTH_COOKIE
#SECURE_AUTH_COOKIE
#USER_COOKIE
#TEST_COOKIE
#COOKIE_DOMAIN
#COOKIEPATH
#SITECOOKIEPATH
#ADMIN_COOKIE_PATH
#PLUGINS_COOKIE_PATH
#--------------------------------------------------------------------------------------------------#
# SECURITY #
#--------------------------------------------------------------------------------------------------#
#DISALLOW_FILE_MODS=false
#DISALLOW_FILE_EDIT=false
#DISALLOW_UNFILTERED_HTML=true
#ALLOW_UNFILTERED_UPLOADS=false
#FORCE_SSL_LOGIN=false
#FORCE_SSL_ADMIN=false
#WP_HTTP_BLOCK_EXTERNAL
#WP_ACCESSIBLE_HOSTS
#--------------------------------------------------------------------------------------------------#
# FILESYSTEM & FTP #
#--------------------------------------------------------------------------------------------------#
#FS_CHMOD_DIR=0755
#FS_CHMOD_FILE=0644
#FS_METHOD
#FS_TIMEOUT=30
#FS_CONNECT_TIMEOUT=30
#FTP_USER
#FTP_PASS
#FTP_HOST
#FTP_SSL
#FTP_SSH
#FTP_BASE
#FTP_CONTENT_DIR
#FTP_PLUGIN_DIR
#FTP_PUBKEY
#FTP_PRIKEY
#--------------------------------------------------------------------------------------------------#
# CRON #
#--------------------------------------------------------------------------------------------------#
#ALTERNATE_WP_CRON=false
#DISABLE_WP_CRON=false
#WP_CRON_LOCK_TIMEOUT=60
#--------------------------------------------------------------------------------------------------#
# LANGUAGES #
# WPLANG is deprecated since WP 4, use only for backward compatibility issues #
#--------------------------------------------------------------------------------------------------#
#WPLANG=en_EN
#WP_LANG_DIR={$WP_CONTENT_DIR}/tmp
#--------------------------------------------------------------------------------------------------#
# MEMORY #
#--------------------------------------------------------------------------------------------------#
#WP_MEMORY_LIMIT=64M
#WP_MAX_MEMORY_LIMIT=256M
#--------------------------------------------------------------------------------------------------#
# PROXY #
#--------------------------------------------------------------------------------------------------#
#WP_PROXY_HOST
#WP_PROXY_PORT
#WP_PROXY_USERNAME
#WP_PROXY_PASSWORD
#WP_PROXY_BYPASS_HOSTS
#WP_ACCESSIBLE_HOSTS
#WP_HTTP_BLOCK_EXTERNAL
#--------------------------------------------------------------------------------------------------#
# MISCELLANEOUS #
#--------------------------------------------------------------------------------------------------#
#WP_MAIL_INTERVAL=300
#WP_DEFAULT_THEME=twentyfifteen
After that you should be ready to roll and have local environments and production environments for WordPress in GIT.