You run an agency with a dozen or more client WordPress sites, and you want every one of them built, updated and deployed the same way, with Bedrock and Composer. Today each site is a one-off, with plugins installed from the dashboard at whatever version was current, credentials in wp-config.php, and a security advisory that means logging in to every site to check. Bedrock, a WordPress project layout from Roots, and Composer, the dependency manager for PHP, fix that together. Every site gets one layout, each plugin version is pinned in that site’s composer.lock (the exact versions Composer resolved), and secrets live in a .env file git never sees. You will have a layout you can copy, a procedure to convert an existing site, and a deploy that comes down to composer install plus moving one symlink, the pointer from one path to another.
What you’ll accomplish
- Every client site uses the same Bedrock layout, so anyone on the team can open any site and know where things are.
- Each site pins its plugin and theme versions in its own
composer.lock, reviewable in a pull request and searchable with onegrepacross the portfolio. - Database credentials, salts and URLs live in a per-server
.envfile outside git. - A repeatable procedure converts a vanilla site to Bedrock without touching its content or URLs.
- Deploys run
composer install --no-dev --optimize-autoloaderinto a dated release directory, then swap a symlink, with.envand uploads shared across releases.
Prerequisites
- PHP 8.1 or newer on the workstation and on every server. Current Bedrock releases require PHP 8.1 or newer; the
phpconstraint in the generatedcomposer.jsonis the authority for your version. - Composer 2.x (
composer --version). Thecomposer auditcommand needs Composer 2.4 or newer. - WP-CLI 2.x, the WordPress command line, on each server. Bedrock ships a
wp-cli.ymlthat pointswpatweb/wp, so commands run from the project root. - Git and a remote (GitHub, GitLab or Bitbucket). One repository per site is the shape used here; a template repository seeds new ones.
- SSH to each server as the user that owns the site directory. You also need a way to set the document root: an Nginx or Apache vhost (the server block for one domain), or the cPanel Domains screen for an addon domain.
- A staging server. Run the conversion there first, then repeat it on production.
- The database stays where it is. Bedrock changes files and configuration, not tables.
The examples keep each git checkout at ~/sites/<client>/ on the workstation and each deployed site at /srv/sites/<client>/ on the server. On cPanel the server side fits under /home/<user>/sites/<client>/.
How it works
A Bedrock project has three kinds of files, and the deploy layout keeps them apart.
Git tracks what your team wrote: composer.json and composer.lock, the config/ directory, your own themes under web/app/themes/, your own must-use plugins under web/app/mu-plugins/, web/index.php and .env.example. The document root is web/, not the project root, so composer.json, vendor/ and .env are never reachable over HTTP.
Composer installs the rest on every deploy. WordPress core lands in web/wp/ through the roots/wordpress package, PHP libraries in vendor/, and plugins in web/app/plugins/ from WordPress Packagist, a Composer mirror of the wordpress.org plugin and theme directories. web/app/ plays the role of wp-content/, so the public media path becomes /app/uploads/ instead of /wp-content/uploads/.
Two things belong to the server and must survive a deploy: .env and web/app/uploads/. The deploy layout keeps them in a shared/ directory next to releases/, and every release gets a symlink to each. A current symlink names the live release, and the vhost’s document root is current/web. Switching releases is one ln -sfn, and rolling back is the same command pointed at the previous directory.
Configuration loads in a fixed order. web/wp-config.php requires config/application.php, which reads .env with the phpdotenv library and then includes config/environments/<WP_ENV>.php, where WP_ENV is development, staging or production. Per-environment settings such as WP_DEBUG live in those files and are committed; secrets never are. The Bedrock documentation covers each constant.
Step-by-step
-
Create the template project. Composer downloads the Bedrock skeleton, resolves its dependencies and writes the first lockfile.
cd ~/sites composer create-project roots/bedrock acme-dentalExample output:
Creating a "roots/bedrock" project at "./acme-dental" Installing roots/bedrock (1.26.1) - Downloading roots/bedrock (1.26.1) - Installing roots/bedrock (1.26.1): Extracting archive Created project in /home/ana/sites/acme-dental Loading composer repositories with package information Updating dependencies Lock file operations: 14 installs, 0 updates, 0 removals - Locking roots/wordpress (6.9.1) - Locking roots/wordpress-no-content (6.9.1) - Locking vlucas/phpdotenv (v5.6.2) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 14 installs, 0 updates, 0 removals - Installing roots/wordpress-no-content (6.9.1): Extracting archive Generating optimized autoload files > php -r "copy('.env.example', '.env');"The last line is Bedrock’s own post-install script copying
.env.exampleto.env. If Composer stops with aphpversion error, the server or workstation is below the constraint incomposer.json; upgrade PHP before going further. -
Fill in
.env. The file belongs to one machine and is never committed. Open~/sites/acme-dental/.env, setWP_ENV='development'and your local database there.WP_SITEURLmust end in/wpbecause core lives there. The production copy, which step 6 places atshared/.envon the server, looks like this:DB_NAME='acme_dental' DB_USER='acme_dental' DB_PASSWORD='kR8v!m2Qz7Lp' DB_HOST='127.0.0.1' DB_PREFIX='wp_' WP_ENV='production' WP_HOME='https://acme-dental.example' WP_SITEURL="${WP_HOME}/wp"The eight salts below those lines (
AUTH_KEYthroughNONCE_SALT) can be generated athttps://roots.io/salts.htmland pasted in. With theaaemnnosttv/wp-cli-dotenv-commandpackage installed throughwp package install,wp dotenv salts generatewrites them for you. Quote every value that contains#,$or spaces, as in the password above. -
Add plugins and themes as dependencies. WordPress Packagist mirrors every plugin and theme on wordpress.org under the same slug. Pin with a caret range so patch and minor releases are allowed and major ones are not.
composer require wpackagist-plugin/wordpress-seo:^26.0 wpackagist-plugin/redis-cache:^2.6 wpackagist-theme/twentytwentyfive:^1.3Example output:
./composer.json has been updated Running composer update wpackagist-plugin/wordpress-seo wpackagist-plugin/redis-cache wpackagist-theme/twentytwentyfive Loading composer repositories with package information Updating dependencies Lock file operations: 3 installs, 0 updates, 0 removals - Locking wpackagist-plugin/redis-cache (2.6.4) - Locking wpackagist-plugin/wordpress-seo (26.2) - Locking wpackagist-theme/twentytwentyfive (1.3) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 3 installs, 0 updates, 0 removals - Installing wpackagist-plugin/redis-cache (2.6.4): Extracting archive - Installing wpackagist-plugin/wordpress-seo (26.2): Extracting archive - Installing wpackagist-theme/twentytwentyfive (1.3): Extracting archive Generating optimized autoload filescomposer/installersplaces each package by type: plugins inweb/app/plugins/, themes inweb/app/themes/, must-use plugins inweb/app/mu-plugins/. Bedrock’scomposer.jsonalready declares those paths. ACould not find a matching version of package wpackagist-plugin/<slug>error means the plugin is not on wordpress.org; see Troubleshooting for premium plugins. -
Commit the template and seed each client from it. Run
git initandgit add -Ain the project;git statusmust not listweb/wp/,vendor/,.envor anything underweb/app/plugins/. Bedrock’s.gitignorealready excludesweb/wp/,vendor/,.env, and everything underweb/app/plugins/andweb/app/uploads/. It also ignoresweb/app/mu-plugins/*, so add a negation line such as!/web/app/mu-plugins/acme-*/for plugins your agency writes. Push the project aswp-site-template, and start each client site as a copy of it with its owncomposer.lock. Branch rules for the per-site repositories are in WordPress and Git workflows. -
Convert an existing vanilla site: build its repository. Work on the staging copy first. On the old server, export the plugin list, then turn it into a
composer requireline that pins the exact versions running today, so the first deploy changes no code.cd /var/www/acme-dental.example wp plugin list --fields=name,status,version --format=csvExample output:
name,status,version akismet,inactive,5.5 redis-cache,active,2.6.4 wordpress-seo,active,26.2 wp-mail-smtp,active,4.6.1Build the require line from the active rows and run it inside the new project:
wp plugin list --status=active --fields=name,version --format=csv | tail -n +2 | awk -F, '{printf "wpackagist-plugin/%s:%s ", $1, $2}'Example output:
wpackagist-plugin/redis-cache:2.6.4 wpackagist-plugin/wordpress-seo:26.2 wpackagist-plugin/wp-mail-smtp:4.6.1Any slug Composer cannot find is premium or custom. Custom plugins and the client’s theme move into the repository with
rsync, run from the workstation; premium ones follow the Troubleshooting entry.rsync -a deploy@web1.example:/var/www/acme-dental.example/wp-content/themes/acme-dental/ ~/sites/acme-dental/web/app/themes/acme-dental/Commit and push. Then copy the database values from the old
wp-config.phpinto the production.envfrom step 2 (wp config get DB_NAMEprints each one). Copy the eight existing keys and salts too if you want logged-in sessions to survive the switch; fresh salts log every user out once. -
Lay out the server and deploy a release. Create the directories once per server, then run the same commands on every deploy. Dated release names make rollback obvious. The production
.envfrom step 2 is copied to the server first, here as~/acme-dental.production.env.mkdir -p /srv/sites/acme-dental/releases /srv/sites/acme-dental/shared/web/app/uploads cp ~/acme-dental.production.env /srv/sites/acme-dental/shared/.env chmod 600 /srv/sites/acme-dental/shared/.envEach deploy:
TS=$(date +%Y%m%d-%H%M) cd /srv/sites/acme-dental git clone --depth 1 --branch main git@github.com:acme-agency/acme-dental.git releases/$TS cd releases/$TS composer install --no-dev --optimize-autoloader --no-interaction ln -sfn /srv/sites/acme-dental/shared/.env .env rm -rf web/app/uploads && ln -sfn /srv/sites/acme-dental/shared/web/app/uploads web/app/uploads cd /srv/sites/acme-dental && ln -sfn releases/$TS currentExample output of the
composer installline:Installing dependencies from lock file Verifying lock file contents can be installed on current platform. Package operations: 17 installs, 0 updates, 0 removals - Downloading roots/wordpress-no-content (6.9.1) - Downloading wpackagist-plugin/wordpress-seo (26.2) - Installing roots/wordpress-no-content (6.9.1): Extracting archive - Installing wpackagist-plugin/wordpress-seo (26.2): Extracting archive Generating optimized autoload files--no-devskips test tooling fromrequire-dev, and--optimize-autoloaderwrites a class map so PHP does not search the filesystem per class. If Nginx hands PHP-FPM (the PHP process manager) the path through thecurrentsymlink, OPcache (PHP’s cache of compiled scripts) keeps serving the old release after the swap. Setfastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;so each release has its own real path. Keep the last five release directories and delete older ones. Wiring these commands into a pipeline is covered in WordPress deployment automation. -
Switch the converted site over. With the first release deployed, copy the media into the shared directory. The old site and the new layout sit on the same server here; across servers, add the
user@host:prefix to the source path.rsync -a /var/www/acme-dental.example/wp-content/uploads/ /srv/sites/acme-dental/shared/web/app/uploads/Point the vhost or the cPanel Domains document root at
/srv/sites/acme-dental/current/weband reload the web server. A primary cPanel domain cannot change its root from the user interface; it needs the host.The media path inside post content still says
/wp-content/uploads/, and Bedrock serves media from/app/uploads/. Rewrite it in the database right after the switch, and rewrite the site URL only if the domain changed:cd /srv/sites/acme-dental/current wp search-replace '/wp-content/uploads/' '/app/uploads/' --skip-columns=guid --dry-runExample output:
+-----------------+--------------+--------------+------+ | Table | Column | Replacements | Type | +-----------------+--------------+--------------+------+ | wp_options | option_value | 3 | PHP | | wp_postmeta | meta_value | 118 | SQL | | wp_posts | post_content | 241 | SQL | +-----------------+--------------+--------------+------+ Success: 362 replacements to be made.Run it again without
--dry-runonce the table list looks right. The dashboard is now at/wp/wp-admin/; tell the client’s editors. -
Update the whole portfolio. With every site checked out under one directory, Composer answers the two questions you ask most: what is outdated, and who runs a given version.
cd ~/sites for d in */; do echo "== $d"; (cd "$d" && composer outdated --direct --no-ansi); doneExample output:
== acme-dental/ Direct dependencies required in composer.json: wpackagist-plugin/wordfence 8.1.0 ! 8.1.2 == northside-law/ Direct dependencies required in composer.json: wpackagist-plugin/wordfence 8.0.3 ! 8.1.2!marks a patch or minor release inside your range and~marks a major release outside it. When an advisory names a plugin version, the lockfiles answer in one command:grep -A1 '"name": "wpackagist-plugin/wordfence"' */composer.lock | grep versionExample output:
acme-dental/composer.lock- "version": "8.1.0", northside-law/composer.lock- "version": "8.0.3",Update one site at a time, review the lockfile diff, commit and deploy:
cd ~/sites/northside-law composer update 'wpackagist-plugin/*' --with-all-dependencies git diff --stat composer.lock git commit -am "Plugins: wordfence 8.0.3 -> 8.1.2"Example output of the
git diff --statline:composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)After the deploy, run
wp core update-dbon the server fromcurrentso a core update’s schema changes are applied before an editor hits the dashboard. Running that step across many servers is the subject of WP-CLI batch operations across a fleet.
Validate it works
On the server, confirm the live release, the shared paths and the running versions:
cd /srv/sites/acme-dental
readlink current
ls -l current/.env current/web/app/uploads
cd current && wp core version && wp eval 'echo WP_ENV, PHP_EOL;'
Example output:
releases/20261026-1430
lrwxrwxrwx 1 deploy deploy 37 Oct 26 14:31 current/.env -> /srv/sites/acme-dental/shared/.env
lrwxrwxrwx 1 deploy deploy 50 Oct 26 14:31 current/web/app/uploads -> /srv/sites/acme-dental/shared/web/app/uploads
6.9.1
production
Then prove that the deployed plugin set matches the lockfile and that the site answers:
wp plugin list --fields=name,status,version --format=csv
curl -sI https://acme-dental.example/ | head -1
curl -sI https://acme-dental.example/app/uploads/2026/10/hero.jpg | head -1
Example output:
name,status,version
redis-cache,active,2.6.4
wordpress-seo,active,26.2
wp-mail-smtp,active,4.6.1
HTTP/2 200
HTTP/2 200
Each plugin version must equal its entry in composer.lock. A 404 on the upload means the symlink or the search-replace step was skipped. Finally run composer audit in the project; No security vulnerability advisories found. is the clean result. It checks the PHP libraries that come from Packagist, such as phpdotenv. WordPress Packagist does not publish advisories, so plugin vulnerabilities still come from your plugin security feed plus the grep in step 8.
Troubleshooting
- A plugin is not on WordPress Packagist. It is premium or private. Some vendors run their own Composer repository: ACF PRO, for example, documents one that takes your licence key in
auth.json, a file git ignores. For a vendor without one, add apackageentry torepositoriesincomposer.jsonwith"type": "wordpress-plugin"and adistURL to a zip you host on a private server. For several such plugins, a Satis or Private Packagist repository keepscomposer.jsontidy. - A plugin’s files disappear after each deploy. The plugin writes into its own directory under
web/app/plugins/, which Composer recreates per release. Find the culprit withfind web/app/plugins -newer composer.lock -type fin the old release. Point the plugin atweb/app/uploads/if it has such a setting; if not, move that one path intoshared/and symlink it like uploads. - Redirect loop or wrong links after the switch.
WP_HOMEandWP_SITEURLdisagree with each other or with the scheme the proxy sends.WP_SITEURLmust beWP_HOMEplus/wp, and both must usehttpswhen the site is served over TLS. The constants overridewp option get siteurl, so change.env, not the database. - Media uploaded yesterday is missing today. The uploads symlink was not created, so files went into the release directory and the next deploy left them behind.
readlink web/app/uploadsmust print the shared path. Recover the files from the previous release directory, then fix the deploy script. - “Error establishing a database connection” on a fresh release. The
.envsymlink is missing orshared/.envis empty, so everyDB_constant is null. If.envexists but lacks a key, the site shows a critical error instead and the PHP log readsOne or more environment variables failed assertions: DB_PASSWORD is missing. Fix the file and reload.
When this is the wrong approach
One or two sites gain nothing from this and lose the ability to update from the dashboard. Keep them vanilla, or stop at a single composer.json without the Bedrock layout, as described in when Composer is worth the switch. Hosting with no shell access and no way to change the document root cannot run the deploy in step 6. Clients whose editors install and update plugins from wp-admin will fight the lockfile every week; either move that job to your team or leave their site out of the portfolio. A site built on several premium plugins with no Composer source means maintaining private packages for each, which can cost more than the standardization saves.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.