# Platform.sh

# Guide: Create a new standard project on Platform

Create a new project in Platform

  1. Log in to Platform using the 'done@dusted.com' account.
  2. Click the blue 'create Project' button.
  3. For project type, choose the 'create from scratch' template.
  4. Add the project name (use the name of the client).
  5. Keep the 'Production environment' as the default.
  6. 'Region' should be United Kindom and Google Cloud Platform.
  7. Add yourself as a user in Project Settings > Access.

Deploy code to the production environment

  1. Switch to your Platform account.
  2. Download the platform-wordpress file template - https://bitbucket.org/dusted/platform-wordpress/get/HEAD.zip - and unzip it into your local repos folder.
  3. Rename the unzipped folder to the name of the project.
  4. Rename the custom/themes/site-theme folder to the name of the project (all lowercase, no spaces) and change the theme name in custom/themes/[project]/style.css
  5. Update the credentials in the .lando.yml file (you can find the project info in Platform).
  6. cd into the project directory and run git init and platform project:set-remote [project ID]
  7. Run git push to deploy this initial set-up on PSH. This will also confirm that you have everything set up correctly to this point.
  8. Run platform branch staging main --type staging to create a staging branch to work on

Get up and running locally

  1. Build the project locally: lando start.
  2. Check the composer.json file in the root to make sure you have the desired version of Wordpress set
  3. Run lando composer update to ensure everthing is up to date
  4. Run lando composer install to make sure everything is installed
  5. You should see the default WordPress login page at the your local lndo.site domain

# Guide: Backup and restore environment

Use this before any potentially risky updates on the site.

Create a full backup of environment (files, database, mounts): platform backup:create

Restore the backup (select the backup on the terminal prompt): platform backup:restore

# Guide: Migration from staging to master (i.e. pre-launch)

Part 1. Backup all files and DB from staging branch:

  1. Export the DB from staging: platform db:dump -e staging

  2. Download all of the files stored in mounts to the local system: platform mount:download -e staging --all --target .

  3. List all of the mounts*: platform mount:list

  4. Ensure you have the latest commit locally: git pull

* Keep a copy as you'll need this for the upload process.

Part 2. Upload backups to the master branch

  1. Checkout the master branch: git checkout master

  2. Make sure the master branch is up to date: git pull

  3. Merge all of the changes from staging into master: git merge staging

  4. Push up all new commits: git push

  5. Below are the most commonly used mounts. Upload all the ones you need *:

platform mount:upload -e master --mount wordpress/wp-content/acf-json --source ./wordpress/wp-content/acf-json
platform mount:upload -e master --mount wordpress/wp-content/cache --source ./wordpress/wp-content/cache
platform mount:upload -e master --mount wordpress/wp-content/uploads --source ./wordpress/wp-content/uploads
platform mount:upload -e master --mount wordpress/wp-content/webp-express --source ./wordpress/wp-content/webp-express
  1. Import the DB**:
platform sql -e master < volvh45mum32y--staging-5em2ouy--db--main--dump.sql

* Each mount has to be uploaded individually, so use the list from earlier as a reference. Run this command for each mount, replacing the mount and source each time.

** Replace the .sql filename with the original backup from staging

Part 3. Perform a Search and Replace and clear the cache on the Main environment

After you've imported all of the data, you'll need to clear the redis cache to see the changes.

You'll also need to perform a search and replace on the database.

  1. SSH to the main environment*.
  2. Perform a search and replace of the staging URL for the main URL**:
wp search-replace https://the-staging-subdomain.platformsh.site https://the-main-subdomain.platformsh.site
  1. Clear the Redis cache: redis-cli -h redis.internal FLUSHDB

* The command to connect via SSH can be copied from the project’s main environment page on https://console.platform.sh (opens new window) under the "SSH" dropdown, top right.

** Replace with the full domain if going live straight away.

Note: most links will just work as they are stored as post relationships rather than a URL string, but it isn’t always the case, particularly with links in WYSIWYG content fields.

Keep up to date with Platform's documentation for databases (opens new window) [22]

# Useful / General Commands

Synchronize data (i.e synchronize from main when on staging):

platform environment:synchronize

Use scp to copy files to and from remote environments

For example, to download the example.png file from the wordpress/wp-content/uploads/2022/06 directory (relative to the app root), run the following command (replacing <PROJECT_ID> and <ENVIRONMENT_NAME> with appropriate values):

scp "$(platform ssh --pipe -p <PROJECT_ID> -e <ENVIRONMENT_NAME>)":wordpress/wp-content/uploads/2022/06/example.png .

The file is copied to the current local directory.

To copy files from your current local directory to the Platform.sh environment, reverse the order of the parameters:

scp example.png "$(platform ssh --pipe -p <PROJECT_ID> -e <ENVIRONMENT_NAME>)":wordpress/wp-content/uploads/2022/06

Consult the scp documentation for other options.