Skip to content

Instantly share code, notes, and snippets.

@samstoller
Last active April 3, 2020 03:53
Show Gist options
  • Save samstoller/3f080f65d4126fe5b9c5 to your computer and use it in GitHub Desktop.
Save samstoller/3f080f65d4126fe5b9c5 to your computer and use it in GitHub Desktop.
WordPress install as git submodule
# Create the basic site structure
# Web server points to public/ keeping configuration outside of webroot
$ mkdir site && cd site
$ mkdir conf/ public/
# Init repo
$ git init && git add . && git commit -m 'Init commit'
# Install WP as submodule to public/
$ git submodule add git://github.com/WordPress/WordPress.git public/wp-core
# Make copies of the WP elements we need as to not modify the submodule
# Copy wp-content/, index.php and the config file
$ cp -R public/wp-core/wp-content public
$ cp public/wp-core/index.php public
$ cp public/wp-core/wp-config-sample.php conf/wp-conf.php
# Make a new config file that points to the one outside of public/
$ echo "<?php"$'\n'$'\n'"require dirname(__DIR__) . '/conf/wp-conf.php';" > public/wp-config.php
# Now you should have a site structure that looks something like this:
├── conf
│   └── wp-conf.php
├── .git
├── .gitignore
├── .gitmodules
├── public
│   ├── index.php
│   ├── wp-config.php
│   ├── wp-content
│   └── wp-core
└── wp-cli.yml
# The YML file for wp-cli defines the path to the core
path: public/wp-core
# Good idea to commit the repo again
$ git add -A && git commit -m "Installed WordPress as submodule"
# Last step is to configure files
# Configure public/index.php by replacing path to file
$ sed -i 's/wp-blog-header.php/wp-core\/wp-blog-header.php/' public/index.php
# Configure conf/wp-config.php like normal
# Add the following constants
define( 'APP_ROOT', dirname(__DIR__) );
define( 'WP_HOME', 'http://siteurl.com' );
define( 'WP_SITEURL', WP_HOME . '/wp-core' );
define( 'WP_CONTENT_URL', WP_HOME . '/wp-content' );
define( 'WP_CONTENT_DIR', APP_ROOT . '/public/wp-content' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment