Before you start, check out the Upsun demo app
and the main Getting started guide.
These resources provide all the core concepts and common commands you need to know before using the following materials.
Assumptions
There are many ways you can set up a WordPress site or Upsun project. The instructions on this page were designed based on the following assumptions:- You are building a composer-based WordPress site using John P Bloch’s WordPress Composer Fork.
- You do not have a
composer.jsonfile, or are comfortable making changes to your existing version. - You selected PHP as your runtime, and MariaDB as a service during the Getting Started guide. It’s also assumed that while using the Getting Started guide you named the project
myapp, which you will notice is the top-level key in all configuration below.
1. Add required files
To ensure you have all the required files and directories in your project, follow these steps:-
Copy the following files from the WordPress Composer Example Snippets
and add them to the root of your project:
- The composer.json file declares project dependencies and specifies project settings and metadata for Composer to use
- The wp-cli.yml file contains the configuration values, related to your site, for the WordPress CLI to use
- The .environment file maps and creates environment variables to be used in
wp-config.php - The wp-config.php file contains your site’s base configuration details, such as database connection information
-
Optional: To support non-public plugins, add a
pluginsdirectory to your project. To ensure Git tracks empty folders, add aplugins/.gitkeepfile as well. -
Add and commit your changes.
Terminal
2. Configure your root location
Now that we have added the initial set of files to our repository, we need to make some additional modifications to the Upsun configuration, so Upsun knows how to handle certain requests. Locate theweb:locations section in the
.upsun/config.yaml file and update the root (/) location as follows:
If you’re migrating your site, you may already have a
If so, you may also have added a
In this case, set
composer.json file.
You may even have generated your own instead of starting from the Upsun Fixed template version.If so, you may also have added a
wordpress-install-dir property for extras in your composer.json file.In this case, set
root: to the name of the directory where you are installing WordPress.3. Set up a location for uploads
WordPress needs a writable location to store uploaded media. To set one up, follow these steps:- Create the location.
To do so, add a/wp-content/uploadslocation as follows:
- To make the location writable, set up a mount.
To do so, locate themounts:section that is commented it out, and update it as follows:
If you have designated a different directory through the
wordpress-install-dir property in your composer.json file, update the
mount location accordingly.4. Install the WP-CLI
To ensure we are able to perform tasks later in the deployment stage (e.g. updating the database, flushing cache, etc.) we need to make sure the wp-cli utility is a dependency of the application container. While still in the.upsun/config.yaml file, locate the dependencies.php section, and add the following:
It is possible the
dependencies section is commented out. When uncommenting, pay attention to the indentation and that
the dependencies key aligns with other sibling keys (e.g. build, hooks, etc.)5. Install dependencies during the build hook
To ensure your Composer dependencies are installed during the build stage, locate thebuild: section (below the hooks: section).Update the
build: section as follows:
You can adjust the composer install command to meet your specific requirements.
If you aren’t using the plugins directory to manage non-public plugins, remove the rsync command.
5. Launch tasks during the deploy hook
Some tasks need to be performed after the images for our application are built, but before the newly built application can receive requests. Therefore, the best time to launch them is during the deploy hook. Such tasks include:- Flushing the object cache, which might have changed between current production and newly deployed changes
- Running the WordPress database update procedure, in case core is being updated with the newly deployed changes
- Running any due cron jobs
deploy: section (below the build: section).Update the
deploy: and post_deploy: sections as follows:
6. Configure your default route
Next, instruct the router how to handle requests to your WordPress app. To do so, locate theroutes: section, and beneath it, the "https://{default}/": route.
Update the route as follows:
Matching the application name myapp with the upstream definition myapp:http is the most important setting to ensure at this stage.
If these strings aren’t the same, the WordPress deployment will not succeed.
7. Add your crons
Under your application configuration you can now add a cron.8. Update the .environment file
We need to add a few environment variables that will be used inside the wp-config.php file we added previously.
Open the .environment file. Just after the other database-related variables, add a blank line or two and add the
following:
.environment
9. Commit and push
You can now commit all the changes made to.upsun/config.yaml and .environment and push to Upsun.
Terminal
10. Install WordPress
Once Upsun has completed building and deploying your project, it will provide the list of routes assigned to your project. You can now visit your site and complete the WordPress installation as you normally would.11. Routinely run WP Cron (optional)
If your site does not receive enough traffic to ensure WP Cron jobs run in a timely manner, or your site uses caching heavily such that WP Cron isn’t being triggered, you might consider adding a cron job to your project’s configuration to have WP CLI run those scheduled tasks on a routine basis. To do so, locate thecrons: section that is commented out, and update it
as follows:
The above example will trigger the wp-cli every 15th minute to run WP Cron tasks that are due. Feel free to adjust based
on your individual requirements.
When uncommenting, pay attention to the indentation and that the
crons key aligns with other sibling keys (e.g. hooks, dependencies, etc.)