A WordPress project based off the Common Knowledge WordPress Starter.
This folder structure uses the Bedrock pattern, a modern WordPress stack.
- Docker installed
- PHP and Composer installed locally. If not, you can use them in containers provided, prefixing all Composer commands below with
docker compose run composer <command>
- Copy
.env.exampleto.env. There should be no need to change this file. - Start the docker containers with
docker compose up -d. - Wait for the mysql container to be running (check with
docker compose logs -f mysql) then import the seed SQL:mysql -uroot -ppassword -P 3308 < platform.sql - Install JS/CSS requirements:
cd web/app/themes; npm i - While still in the
themedirectory, start the CSS processor:npm run watch - The site should now be up at http://localhost:8082.
- The admin system is at http://localhost:8082/wp/wp-admin and the default login/password is admin/admin.
- Update WordPress in the
composer.jsonfile by increasing the version on theroots/wordpress-no-contentline. - Run
composer update roots/wordpress. This will update thecomposer.lockfile as needed. - Push the change to GitHub.
WP-CLI is installed in the wordpress container.
docker compose run wordpress wp --allow-root <command>
Note WP-CLI will not work on the host machine, as WordPress configuration refers to databases within the Docker network, not the host machine.
Run docker compose run composer require wpackagist-plugin/plugin-name.
Documentation for Bedrock is available at https://roots.io/bedrock/docs/.
The following are instructions on how to setup a new site on Kinsta.
You will need to have "Company developer" or above permissions in order to create a site.
These are exhaustive manual instructions, but should not be required after initial setup.
- Create a new site on Kinsta. You want to select "Don't install WordPress" and choose the London data centre. It will provision after around ten minutes.
- On Kinsta we have a Live environment and a staging environment. Start with the Live environment for a new build. Then after, you can create a staging environment as needed.
- For the next steps, you will need to add your SSH key to Kinsta. This is to allow you to log into Kinsta over SSH.
- You will also need to add a SSH key to GitHub. This is so you can check out the theme from GitHub over SSH when logged into Kinsta.
- Kinsta needs to be set up to forward you GitHub SSH key to it when you connect to it over SSH and checkout the theme with Git. You can look up the precise SSH details on Kinsta under the "SFTP/SSH" in the live environment section of the admin panel. You can then add them to a
~/.ssh/configblock to look something like this.host <your site>_live User <see "SFTP/SSH" details for Live Environment> Hostname <see "SFTP/SSH" details for Live Environment> Port <see "SFTP/SSH" details for Live Environment> IdentityFile <Location on your local machine of the SSH key> ForwardAgent yes - Add you GitHub SSH key to
ssh-agentfollowing these instructions. The command will be something likessh-add ~/.ssh/gitlab_key_rsa - We are going to begin with the staging environment. SSH onto Kinsta staging environment using this command
ssh nurses_united_staging. - Test GitHub works by running the command
ssh -T git@github.com. After accepting the authenticity of the host you should see a friendly message from GitHub. - Remove the
publicdirectory withrm -r public. Clone the code into thepublic/directiory:git clone git@github.com:commonknowledge/pluto-press.git public. cd public && composer install. 11 Return to thepublicdirectory,cd ~/public. If this is the first time, copy.env.exampleto.envwithcp .env.example .envand modify details appropriately as per the Bedrock documentation. You can use Vim on the server. The details of the database are on the Kinsta admin panel under the site itself then "Database Access". TheWP_HOMEcan behttp://localhost.- You need to create database tables for WordPress. Run
wp core install --url=<URL from Primary domain in Kinsta admin panel> --title=<site name> --admin_user=<desired username> --admin_email=<desired password>. This will output the password for the user you have just created to the terminal. Save it for when you need to login. - Ask Kinsta to update NGINX to point at
public/webon Intercom chat inside the Kinsta control panel. Note, notpublic/current/web, which is the directory if you are deploy Bedrock with Trellis. This installation does not use Trellis. - You can now point the domains to this installation of WordPress following Kinsta's instructions.
- Head to Tools for the site in the live environment. Use "SSL certificate" to generate a new Let's Encrypt SSL certificate and wait for this to complete.
- Still on the tools page, setup Force HTTPS by clicking on Modify and dollowing your nose, selecting "Force all traffic to the primary domain" along the way. Edit the
.envfile created in step 12, to haveWP_HOMEincludehttpsnothttp. - In Domains, change the DNS pointed domain to your primary one selecting "Make primary".
- WordPress should now work at the site URL. You can login to the administration dashboard with the password you just created.
- Repeat steps 7 through 20, but creating a development environment.
WordPress core and plugins update themselves on the server (minor versions, see
web/app/mu-plugins/enable-minor-auto-updates.php) and can be updated from the admin, so the live
versions are usually newer than composer.lock. composer install puts the locked versions back,
so only run it when composer.json or composer.lock changed:
cd ~/public
before=$(git rev-parse HEAD) && git pull && { git diff --quiet "$before" HEAD -- composer.json composer.lock || composer install --no-dev; }
Before changing composer.lock, update the WordPress and plugin versions in it to at least what the live site runs.
web/app/mu-plugins/ck-rate-limit.php limits how fast pages can be requested, to stop crawlers running up
the hosting bill. It only sees requests that reach PHP (Kinsta serves cached pages and static files first).
Each request counts against its IP, its IP range (/24 or /48) and, if the user agent names one, its crawler
(e.g. every PetalBot request, whatever the IP). Going over a limit is a strike:
| Strike | Response | For |
|---|---|---|
| 1 | 429 Too Many Requests | 10 minutes |
| 2 | 429 | 1 hour |
| 3 | 429 | 24 hours |
| 4+ | 403 Forbidden | 30 days |
Strikes are forgotten after 7 days without a new one. Logged-in users, WP-Cron and Googlebot/Bingbot (checked against their published IP ranges, refreshed daily) are never limited.
Default limits (per minute / per hour): IP 20 / 120, range 40 / 240, crawler 10 / 120. Override them in
.env with RATE_LIMIT_IP_PER_MINUTE, RATE_LIMIT_IP_PER_HOUR, RATE_LIMIT_RANGE_PER_MINUTE,
RATE_LIMIT_RANGE_PER_HOUR, RATE_LIMIT_CRAWLER_PER_MINUTE and RATE_LIMIT_CRAWLER_PER_HOUR.
RATE_LIMIT_ENABLED=false turns it off.
Each new strike is written to the PHP error log as [ck-rate-limit]. On the server:
wp ck-ratelimit top # busiest IPs, ranges and crawlers this hour
wp ck-ratelimit blocked # everything blocked now
wp ck-ratelimit unban 203.0.113.5
wp ck-ratelimit unban range:203.0.113.0/24
wp ck-ratelimit ban crawler:examplebot --days=30
Locally, requests come from a private Docker address and are not limited. To test, send
-H 'X-Test-Client-IP: 203.0.113.5' (only honoured when WP_ENV=development).