Bringing a Bedrock WordPress site live
Obligatory reminder to plan for the unexpected and give ourselves that peace of mind knowing we can restore what we messed up.
From your project repository, ensure that what is on production is up-to-date.
bundle exec cap production deploy
This ensures when your site does go live it doesn't serve a cached copy with old URL's in your markup.
Update wpcli_remote_url
in your config/deploy/production.rb
to the production site UR. This allows subsequent deploys to correctly change all occurances in the database from your dev url (domain.local) to production URL (www.domain.com).
We need to replace all occurrances of the IP address, which is originally how we accessed production, to the new domain. To do this we'll use the WP-CLI tool we already have installed. You'll have to cd /var/www/domain.com/current/web
to have it properly read WordPress configuration. Once there, run:
wp search-replace '166.78.62.108' 'domain.com' --skip-columns=guid
Note: If we are routing traffic to www, you should normalize all URL's in the database. If we simply replaced "domain.com" with "www.domain.com", we could end up with a few "www.www.domain.com" in your database. So first:
wp search-replace 'www.domain.com' 'domain.com' --skip-columns=guid # Normalizes URL's to non-www
wp search-replace 'domain.com' 'www.domain.com' --skip-columns=guid # Convert all to www
The shared/.env
file on production, which defines the base of the permalink structure, must be updated to our new www.domain.com from:
WP_HOME=http://168.1.1.1
WP_SITEURL=http://168.1.1.1/wp
to:
WP_HOME=http://www.domain.com
WP_SITEURL=http://www.domain.com/wp
Update your /etc/hosts
file to point www.domain.com to the IP address of the production server. So, if our production server was 168.1.1.1, add:
168.1.1.1 www.domain.com
This will route traffic from www.domain.com to 168.1.1.1 and give an accurate representation of how the site would work live.
Because of Step 7, visiting www.domain.com will actually route to our production server. From here, you can start general QA. Ensure that:
- All pages load properly
- All media files load properly
- You can log into the Admin at http://www.domain.com/wp/wp-admin
- You can save/edit Posts and settings
After ensuring everything is working properly, remove the overriding 168.1.1.1 line in your /etc/hosts
and point your domain to the production server 168.1.1.1.