WordPressBP
WordPress Boilerplate
The WordPress Boilerplate is a starting base for development of any WordPress based web project. It provides all the files and most common code patterns — the bare essentials needed to get started quickly without wasting time setting up directory and file structure, importing CSS resets, setting up the functions.php
file etc.
WordPressBP is meant for developers developing a WordPress site from scratch using a scalable and modern approach.
It is not:
- an end-user template
- a WordPress Plugin Boilerplate
- a WordPress Widget Boilerplate
If you need a stripped down version to manage WordPress installations with 3rd-party themes and plugins and an automated deployment process, check out my other project ManagedWP.
Index:
- System requirements
- Installation
-
Development
<li> <a rel="nofollow noopener" target="_blank" href="#back-end">Back-end</a></p> <ul dir="auto"> <li> <a rel="nofollow noopener" target="_blank" href="#wordpress-config">WordPress config</a> </li> <li> <a rel="nofollow noopener" target="_blank" href="#including-free-plugins-and-themes">Including free plugins and themes</a> </li> <li> <a rel="nofollow noopener" target="_blank" href="#including-non-free-plugins-and-themes">Including non-free plugins and themes</a> </li> <li> <a rel="nofollow noopener" target="_blank" href="#including-languages">Including languages</a> </li> </ul> </li> </ul>
- Sync from staging or production
- Deployment
- Recommended plugins
- Contributors
- License
System requirements
WordPressBP has been extensively tested on Linux but will probably work with any Unix environment (macOS, BSD,…). It does not work on Windows in which case you should use a Linux VM for development.
- LEMP stack (Linux, Nginx, MySQL, PHP 7+)
- Git
-
NodeJS (
node
) and NPM (npm
) - Composer
- WP-CLI
-
gettext utilities (
msgfmt
) for i18n
Read this Gist on how to correctly set these tools up on your development environment.
Installation
Quick-start guide:
- Clone this repository and move into it
-
Run the setup script
./setup.sh mywebsite /srv/http/mywebsite.dev
-
Set up the web server to serve
mywebsite.dev
from/srv/http/mywebsite.dev/web
-
Map the server IP to
mywebsite.dev
in your local hosts file (/etc/hosts
) -
Login at
http://mywebsite.dev/wp/wp-login.php
(login: dev / dev) -
Initialize Git in
/srv/http/mywebsite.dev/
and start developing
Continue reading for details.
Setup script
$ ./setup.sh
Usage:
./setup.sh <namespace> <project_path> [<branch>]
Params:
<namespace>: Lowercase alphanumeric name for your project. Must not start with a number. Must be file system and URL friendly.
<project_path>: Path to directory where the project structure will be set up.
<branch>: Branch from which to create the project structure. Defaults to 'master'.
Example:
./setup.sh mything /srv/http/mything.dev
The script will create the directory at project_path
if it doesn’t exist. Make sure the parent directory (or project_path
if exists) is writable by the user running this script. Do not run the setup script as root unless you’re doing everything as root on your dev environment.
The script will use composer, npm and wp (WP-CLI) to install dependencies and setup WordPress. Make sure these tools are installed as explained here.
If you don’t have or don’t want to use a root MySQL account, you’ll be asked to manually create a database and user for it.
Nginx web server
Lets assume your project_path
is /srv/http/mywebsite.dev
and namespace
is mywebsite
.
Create /etc/nginx/sites-enabled/mywebsite.dev.conf
with the following content and restart Nginx:
# If you have SSL enable this redirect
#server {
# listen [::]:80;
# listen 80;
# server_name mywebsite.dev;
# return 301 https://mywebsite.dev$request_uri;
#}
server {
# If no SSL:
listen [::]:80;
listen 80;
# Else if SSL:
#listen [::]:443 ssl http2;
#listen 443 ssl http2;
#include /etc/nginx/conf.d/ssl.conf; # https://gist.github.com/andrejcremoznik/f0036b58398cafaa9b14ff04030646da#file-ssl-conf
#ssl_certificate /srv/http/mywebsite.dev.crt;
#ssl_certificate_key /srv/http/mywebsite.dev.key;
server_name mywebsite.dev;
root /srv/http/mywebsite.dev/web;
index index.html index.php;
access_log off;
client_max_body_size 20m;
# Rewrite URLs for uploaded files to production - no need to sync uploads from production
#location /app/uploads/ { try_files $uri @production; }
#location @production { rewrite ^ https://production.site/$request_uri permanent; }
location ~ .php$ {
try_files $uri =404;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock; # Arch
#fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # Ubuntu
}
location / { try_files $uri $uri/ /index.php$is_args$args; }
}
Read up on how to create self signed certificates for development. If you do create SSL certs, enable them in the Nginx config (above) and change the URLs in .env
.
To be able to access http://mywebsite.dev
you need to map the server IP to mywebsite.dev
domain in /etc/hosts
. If you’re running the server on your local machine, the IP is 127.0.0.1
, if you are using a virtual environment, then use the IP of…