Sign inSign up

levelupify/wordpress

By levelupify

•Updated over 7 years ago

Levelup base WordPress Dockerfiles

Image
0

338

levelupify/wordpress repository overview

⁠Docker WordPress

This is the base Dockerfiles for hosted Levelup projects.

⁠Using this image

⁠1. wp-config.php

Make sure your wp-config.php file are set up like this. Further changes can be done to the file, but be careful and consult Levelup if you are not 100% confident with the changes you want to do.

<?php

define( 'WP_HOME', $_ENV["WP_HOME"] );
define( 'WP_SITEURL', $_ENV["WP_SITEURL"] );

define('DB_NAME', $_ENV["DB_NAME"]);
define('DB_USER', $_ENV["DB_USER"]);
define('DB_PASSWORD', $_ENV["DB_PASSWORD"]);
define('DB_HOST', $_ENV["DB_HOST"]);
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

$table_prefix  = 'wp_';

define('FORCE_SSL_ADMIN', false);

define('WP_DEBUG', $_ENV["WP_DEBUG"]);

define( 'WP_AUTO_UPDATE_CORE', false );

if ( !defined('ABSPATH') )
  define('ABSPATH', dirname(__FILE__) . '/');

require_once(ABSPATH . 'wp-settings.php');
⁠2. Dockerfile

Place this file in the root of your repository:

FROM levelupify/wordpress:php5.6-apache

# Copy the project files into the default "hosted" area in
COPY . /var/www/html/.

# Create folder for uploads if it does not already exist
RUN mkdir -p /var/www/html/wp-content/uploads

# Make sure the default mount is the uploads folder
VOLUME /var/www/html/wp-content/uploads


# Make sure the right access is set
RUN chown -R www-data:www-data /var/www/html/

EXPOSE 80
⁠3. The WordPress installation

Make sure you place the WP install in the root of your repository alongside the Dockerfile etc.

⁠4. Environment variables
Env nameDescription
WP_SITEURLWP CORE url: Ex: http://localhost:8080/
WP_HOMEWhat you want your visitors to type: Ex: http://localhost:8080/
WP_DEBUGDebug on or of? 1 for true or 0 for false
DB_NAMEThe name of your DB
DB_USERThe username for your DB
DB_PASSWORDThe password for your DB
DB_HOSTThe host of your DB
⁠5. .htaccess

Make sure you have a .htaccess file located in the root of your repository.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
⁠6. .gitignore
node_modules/

.DS_Store
*.sublime-workspace

config/local.js

*.log

# Uploads folder 
wp-content/uploads
⁠7. important notice
  1. Be sure to mount a volume to store the persistent files

  2. Make sure to always place "persistent" data/media inside the /var/www/html/wp-content/uploadsfolder

⁠8. Disable "update" nag

It's very important that WordPress is not updated "in production" with the "auto update" logic built into WordPress. This is because of how Docker works. On next deployment, the update will be gone.

Read more about updating WordPress further down in this document.

Make sure to add this to your functions.php file

function remove_core_updates(){
  global $wp_version;return(object) array('last_checked'=> time(),'version_checked'=> $wp_version,);
}
add_filter('pre_site_transient_update_core','remove_core_updates');
add_filter('pre_site_transient_update_plugins','remove_core_updates');
add_filter('pre_site_transient_update_themes','remove_core_updates');
⁠8. Running the project locally
version: '3.2'
services:

  wordpress:
    build: .
    restart: always
    ports:
      - 8080:80
    volumes: 
      - .:/var/www/html/
    environment:
      WP_SITEURL: http://localhost:8080/
      WP_HOME: http://localhost:8080/
      WP_DEBUG: 1
      DB_HOST: db
      DB_USER: exampleuser
      DB_PASSWORD: examplepass
      DB_NAME: exampledb

  db:
    image: mysql:5.7
    restart: always
    ports:
      - 3306:3306
    volumes:
      - mysql-volume:/var/lib/mysql
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_ROOT_PASSWORD: foobar

volumes:
  mysql-volume:
  1. docker-compose up
  2. Wait
  3. Go to http://localhost:8080⁠

⁠Development

⁠tags

The general idea is to build the tags like this:

php5.6-apache

Where php6.5 is the php version, and apache is the HTTP server

⁠Docker HUB

Tags and master is automatically built with Docker HUB

⁠Deploying updates

Make sure to push to the right branch (based on tags)

Master should always be the "latest".

⁠Updates
  1. Make sure to update the WordPress core locally, and then push the updated source code to production.

  2. Go to the site and finish up the database changes if necessary.

Nb: DO NOT update WordPress core files in production. These changes will be lost in the next deployment.

Tag summary

Content type

Image

Digest

Size

125.9 MB

Last updated

over 7 years ago

docker pull levelupify/wordpress