=======
This is the master repo for setting up a new Wordpress site locally.
You must have the following installed on your Mac OS X system in order to use this repository:
- Composer - installation
- Vagrant - installation
- Vagrant Triggers plugin -
vagrant plugin install vagrant-triggers - Ansible - installation
- Virtualbox - docs
- Git - derp of course
- Node/NPM
- Bower
=======
Setting up a new WP site with this repo as a starting point:
- Clone this repo
git clone git@github.com:gianthat/bedrock.git yourprojectname - Delete the project's .git folder with
cd yourprojectname && rm -rf .git - Delete the .git folder, run
git initand add new git remote for wherever your git repo is hostedgit remote add origin git@github.com:gianthat/yourprojectname.git - Edit
yourprojectname/provisioning/hostsfile and change theansible_ssh_hostandapplication_namesettings. The ssh host should ideally be a local IP address that doesn't match any other local IP's in use on your system (in/etc/hostsfolder). Should be something like 192.168.33.##. Double-check this against the Local Dev IPs spreadsheet and update it with whichever IP you choose. - Go to the
yourprojectname/Vagrantfileand set the IP address to the same address used above. - Edit your local
/etc/hostsfile and add a line for192.168.33.## yourprojectname.dev - Install Ruby gems for Capistrano deployment with
bundle install(we've already done acap installso all the files are there) - Update
config/deploy.rb,config/deploy/staging.rb, andconfig/deploy/production.rbto suit. - Go to
web/app/themesfolder and download theme from https://github.com/roots/sage - Rename folder from
sageto yourprojectname. - Go to
web/app/themes/yourprojectname/assets/manifest.jsonfolder and set the devURL parameter tohttp://yourprojectname.dev - Edit the style.css file and change the theme name and other details to suit your project
- Make sure you are in
web/app/themes/yourprojectname/and install npm modules withnpm install. - Install bower components
bower install --save. - Go to the theme folder
.gitignorefile and delete the line withdistin it. - Now read sections below on running Composer, Vagrant, Gulp, and PHPMyAdmin.
=======
- Better folder structure
- Dependency management with Composer
- Easy WordPress configuration with environment specific files
- Environment variables with Dotenv
- Autoloader for mu-plugins (use regular plugins as mu-plugins)
- Enhanced security (separated web root and secure passwords with wp-password-bcrypt)
Use Trellis for additional features:
- Easy development environments with Vagrant
- Easy server provisioning with Ansible (Ubuntu 16.04, PHP 7.1, MariaDB)
- One-command deploys
See a complete working example in the roots-example-project.com repo.
- PHP >= 5.6
- Composer - Install
From the project root (not theme root), you need to run composer install locally (not in the vagrant shell). Your PHP version must be at least 5.4.
After initial setup you'll periodically use Composer to add plugins and update the version of Wordpress core.
- Create a new project in a new folder for your project:
composer create-project roots/bedrock your-project-folder-name
- Copy
.env.exampleto.envand update environment variables:
DB_NAME- Database nameDB_USER- Database userDB_PASSWORD- Database passwordDB_HOST- Database hostWP_ENV- Set to environment (development,staging,production)WP_HOME- Full URL to WordPress home (http://example.com)WP_SITEURL- Full URL to WordPress including subdirectory (http://example.com/wp)AUTH_KEY,SECURE_AUTH_KEY,LOGGED_IN_KEY,NONCE_KEY,AUTH_SALT,SECURE_AUTH_SALT,LOGGED_IN_SALT,NONCE_SALT
If you want to automatically generate the security keys (assuming you have wp-cli installed locally) you can use the very handy wp-cli-dotenv-command:
wp package install aaemnnosttv/wp-cli-dotenv-command
wp dotenv salts regenerate
Or, you can cut and paste from the Roots WordPress Salt Generator.
-
Add theme(s) in
web/app/themesas you would for a normal WordPress site. -
Set your site vhost document root to
/path/to/site/web/(/path/to/site/current/web/if using deploys) -
Access WP admin at
http://example.com/wp/wp-admin
To add a new plugin from Wordpress's wpackagist repo, use composer require wpackagist-plugin/plugin-slug-here.
To remove a plugin from this project, use composer remove wpackagist-plugin/plugin-slug-here.
The base box has been set up with only basic libraries. We're using Ansible to provision it with other requirements on vagrant up which will allow for some flexibility.
# One-time only
$ vagrant box add ubuntu/trusty64
# Later if there are updates to the box
$ vagrant box outdated # check to make sure
$ vagrant box update # update it - this will take a long time
# Each time you want to spin it up
$ vagrant up # this will also provision if first time
# ssh into it
$ vagrant ssh
# Suspend it
$ vagrant halt
# Provision it (after it's "up"). If you make changes to the Ansible playbook, Ansible will run tasks that haven't been run before and ignore tasks that are already done.
$ vagrant provision
# Kill it
$ vagrant destroy # doing this will cause all of the Ansible provisioning tasks to run again next time you vagrant up.
In your theme folder, run gulp build (locally) the first time you set this up. Thereafter, when you are actively working on the theme, run gulp watch (locally) which will watch for file changes and recompile assets into the dist folder. It also spins up the site at localhost:3000 and updates CSS there automatically. To stop gulp from watching, hit Ctrl+C.
You should be able to login at http://192.168.33.##/phpmyadmin (or http://yourprojectname.dev/phpmyadmin with the following credentials:
Username: wp_db_u Password: password
Provided you have pulled and replaced your SQL dump, vagrant's provisioning should have sourced your databases. If you want to source a database outside of the normal startup procedure, use PHPMyAdmin or use the commands below (substituting the appropriate database name and folder name, of course):
$ vagrant ssh
$ mysql -u wp_db_u -ppassword
mysql> use projectname_dev;
mysql> source /var/www/web/mysqldumps/output.sql
OR
$ mysql -u wp_db_u -ppassword projectname_dev < /var/www/web/mysqldumps/output.sql
- Participate on the Roots Discourse
- Follow @rootswp on Twitter
- Read and subscribe to the Roots Blog
- Subscribe to the Roots Newsletter
- Listen to the Roots Radio podcast