# Platform.sh
- Guide: Create a new standard project on Platform
- Guide: Backup and restore environment
- Guide: Migration from staging to main
- Useful / General commands
# Guide: Create a new standard project on Platform
Create a new project in Platform
- Log in to Platform using the 'done@dusted.com' account.
- Click the blue 'create Project' button.
- For project type, choose the 'create from scratch' template.
- Add the project name (use the name of the client).
- Keep the 'Production environment' as the default.
- 'Region' should be United Kindom and Google Cloud Platform.
- Add yourself as a user in Project Settings > Access.
Deploy code to the production environment
- Switch to your Platform account.
- Download the platform-wordpress file template - https://bitbucket.org/dusted/platform-wordpress/get/HEAD.zip - and unzip it into your local repos folder.
- Rename the unzipped folder to the name of the project.
- Rename the
custom/themes/site-themefolder to the name of the project (all lowercase, no spaces) and change the theme name incustom/themes/[project]/style.css - Update the credentials in the
.lando.ymlfile (you can find the project info in Platform). cdinto the project directory and rungit initandplatform project:set-remote [project ID]- Run
git pushto deploy this initial set-up on PSH. This will also confirm that you have everything set up correctly to this point. - Run
platform branch staging main --type stagingto create a staging branch to work on
Get up and running locally
- Build the project locally:
lando start. - Check the
composer.jsonfile in the root to make sure you have the desired version of Wordpress set - Run
lando composer updateto ensure everthing is up to date - Run
lando composer installto make sure everything is installed - 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:
Export the DB from staging:
platform db:dump -e stagingDownload all of the files stored in mounts to the local system:
platform mount:download -e staging --all --target .List all of the mounts*:
platform mount:listEnsure 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
Checkout the master branch:
git checkout masterMake sure the master branch is up to date:
git pullMerge all of the changes from staging into master:
git merge stagingPush up all new commits:
git pushBelow 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
- 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.
- SSH to the
mainenvironment*. - 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
- 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.