Skip to content

Deployment

Philipp Heuer edited this page Jan 30, 2018 · 5 revisions

Deployment - Local

Before you begin make sure you have installed the project dependencies locally with the following command:

composer install

If you want to test your wordpress instance locally, then create a .env file in the directory root.

You need to provide your own database in CUSTOM_DB_URL.

# DB Connection
CUSTOM_DB_URL=mysql://user:password@host:3306/databaseName

# WP Settings 
WP_ENV=development
WP_HOME=http://localhost
WP_SITEURL=${WP_HOME}/wp

# Generate your keys here: https://roots.io/salts.html
AUTH_KEY='generateme'
SECURE_AUTH_KEY='generateme'
LOGGED_IN_KEY='generateme'
NONCE_KEY='generateme'
AUTH_SALT='generateme'
SECURE_AUTH_SALT='generateme'
LOGGED_IN_SALT='generateme'
NONCE_SALT='generateme'

Now you can start a local webserver using the WordPress CLI Tool.

php wp-cli.phar server --host=0.0.0.0 --port=80 --path=web

Deployment - Heroku - Manual

Deploy using Heroku CLI (suggested for customization)

If you want to deploy it yourself, please make sure that your environment is installed and configured. Check out the wiki on installing your development environment.


Creation

If you want to deploy to Heroku, you are required to use git as version-control-system (VCS). Therefore you can clone this repository onto your local drive.

$ git clone https://github.com/PhilippHeuer/wordpress-heroku.git

Using Heroku CLI you can create a new application in the dashboard and link it to the git repository.

$ heroku create
Creating app... done, weird-name-12345
https://weird-name-12345.herokuapp.com/ | https://git.heroku.com/weird-name-12345.git

Configuration (Required)

You need to generate secrets to make your WordPress installation more secure: You can generate random values using the wordpress secret key api.

  • On Windows
$ heroku config:set ^
    AUTH_KEY='SECRET' ^
    SECURE_AUTH_KEY='SECRET' ^
    LOGGED_IN_KEY='SECRET' ^
    NONCE_KEY='SECRET' ^
    AUTH_SALT='SECRET' ^
    SECURE_AUTH_SALT='SECRET' ^
    LOGGED_IN_SALT='SECRET' ^
    NONCE_SALT='SECRET'
  • On Linux
$ heroku config:set \
    AUTH_KEY='SECRET' \
    SECURE_AUTH_KEY='SECRET' \
    LOGGED_IN_KEY='SECRET' \
    NONCE_KEY='SECRET' \
    AUTH_SALT='SECRET' \
    SECURE_AUTH_SALT='SECRET' \
    LOGGED_IN_SALT='SECRET' \
    NONCE_SALT='SECRET'
Addons

SendGrid (Optional)

You need an extension to send emails, since Heroku doesn't support this by default. Please be aware that you need to provide Heroku with your credit card information to use SendGrid. This does not cause any costs, you can still use this addon free of charge!

$ heroku addons:create sendgrid:starter

Worker (Optional)

You can improve performance by scheduling wp-cron instead of running it while a user waits for the site to load.

$ heroku addons:create scheduler:standard
$ heroku config:set DISABLE_WP_CRON='true'
$ heroku addons:open scheduler

The last command opens the scheduler configuration in your browser. Create a new task with the following options:

Option Value
Dyno Size Free
Frequency Every 10 minutes
Command bin/cron/wordpress.sh

Database (Required)

You can pick one of the following three options:

  • Maria Db
$ heroku addons:create jawsdb-maria:kitefin
  • MySQL
$ heroku addons:create jawsdb:kitefin
or
$ heroku addons:create cleardb:ignite
  • Custom Database

To use your own private database, you can provide a connection string in environment variables. You need to open your Application in the Heroku Dashboard and visit Settings -> Reveal Config Vars. You need to set the Key to "CUSTOM_DB_URL" and provide a connection string in the following format:

mysql://user:password@host:port/databaseName

Persistent Storage (Optional)

The Heroku Filesystem is not persistent, which means that all media uploads will be gone after a while. Therefore you need to configure a persistent storage, if you plan to upload files.

  • Amazon S3

You need create a Amazon S3 bucket and access credentials. Those access credentials are provided using the Heroku Dashboard -> App -> Settings -> Config vars.

AWS_S3_URL=s3://ACCESS_ID:[email protected]/bucketName

Cache (Optional)

Redis caching can improve your application performance by x20 or even more. It saves the results of sql queries in ram memory, therefore reducing loading times.

You only need to attach the Heroku Redis addon to your application.

$ heroku addons:create heroku-redis:hobby-dev

Logging (Optional)

Papertrail is an add-on providing hosted log aggregation and management, including real-time tail, search, and alerts on application and platform logs.

Adding log management to an application provides truly realtime app visibility, faster troubleshooting, elegant alerting optimized for Heroku, and painless archives. Papertrail is accessible via Web browser, command-line client, and HTTP API.

$ heroku addons:create papertrail:choklad

Deploy / Update

Now you can deploy your project to heroku (or when you update your application):

$ git push heroku master

Open Application

Now you can open your app using the following command. This will open a new window in your browser.

$ heroku open

Congratulations, you have successfully installed WordPress on Heroku. Please read the WIKI on how to customize your installation.

If you had any problems, you are welcome to join the Discord Server to talk about your issues.