If you are utilizing a Fastly CDN in conjunction with your Platform.sh project that employs WordPress, the Fastly team has developed a WordPress plugin that facilitates the integration of your application with Fastly services. This plugin is crucial for ensuring that the WordPress application is configured correctly to avoid caching authenticated users or any requests directed to the WordPress backend. Additionally, the plugin allows for certain settings to be adjusted within the WordPress administration interface without the necessity of logging into the Fastly Dashboard.
For managed Fastly CDN, access to the Fastly dashboard is not available.
Installation
#composer.json
"wpackagist-plugin/fastly": "^1.2"
#wp-config.php
define('FS_METHOD', 'direct');
Note that the Fastly WordPress Plugin saves service connections in the WordPress `wp-options` table, which may cause issues if the database syncs with other environments. Be sure to set 2 environment variables to override the Fastly credentials.
platform variable:create -y --level environment --inheritable false --sensitive false -p $PROJECT_ID -e $ENVIRONMENT --name env:FASTLY_API_SERVICE --value $FASTLY_SERVICE_ID --no-wait
platform variable:create -y --level environment --inheritable false --sensitive false -p $PROJECT_ID -e $ENVIRONMENT --name env:FASTLY_API_TOKEN --value $FASTLY_API_TOKEN --no-wait
You can verify your current environment's Fastly general connection settings by executing the following SQL query.
select * from wp_options where option_name = "fastly-settings-general";
Currently, the Fastly event history can only be accessed through the Fastly API.
FASTLY_SERVICE_ID=<FASTLY_SERVICE_ID>
curl -sH "Fastly-Key: $FASTLY_API_TOKEN" -X GET "https://api.fastly.com/events?filter\[service_id\]=${FASTLY_SERVICE_ID}&page\[size\]=100" | jq -j -r '.data[] | "ID: ", .id, " Date: ", .attributes.created_at, " Type: ", .attributes.event_type, " Description:", .attributes.description, "\n"'
If you observe that your WordPress content is not being purged, it is advisable to verify that your Fastly service credentials are accurate.
You can clear the Fastly cache by clicking the `Purge All` button in the `Advanced` settings.