Using DigitalOcean App Platform to host WordPress – Part 2

In the first part, we managed to set up a Mysql 8 database using Digital Ocean Managed databases, then WordPress as a Digital Ocean app. If you do not have a digital ocean account, Use this link to create an account and earn trial credits.


In this guide we are going to set up WordPress. If you didn’t check the first part, you can find it here.

We left WordPress initial configuration page shown below:

Citizix DigitalOcean - WordPress Install
Citizix DigitalOcean – WordPress Install

Please fill in the details requested. After the setup is complete, you can log into the WordPress administration dashboard with the username and password entered in the previous step. You can now login to the admin portal with the username and password. When completed, you should see this success screen:

Citizix - WordPress welcome
Citizix – WordPress welcome

WordPress is now running in the Digital Ocean App Platform! Congratulations on gettng to this point.

# Processing Images

For WordPress thumbnail functionality to work, we need extra php extentions that are always installed on OS level. You can use either GD or ImageMagick. In this guide we are going with ImageMagick, it is more feature complete.

DO App Platform uses Composer to manage PHP extensions. You can install ImageMagick with the following command in the project:

composer require ext-imagick:* --ignore-platform-reqs

This will add the ImageMagick requirement in composer.json and DO App Platform will automatically enable ImageMagick for us.

You’ll probably want to install the optional-but-recommended mbstring and exif PHP extensions with the following command:

composer require ext-mbstring:* ext-exif:* --ignore-platform-reqs

# Persisting Media and files

Digital ocean Apps are running as stateless containers. This means that the file system is ephimeral. If the app restarts for any reason all the data will be lost.
Every time we deploy the app, a restart happens so all data is lost. To fix this, we can use a plugin to upload our files to cloud storage like DigitalOcean Spaces.
The plugin WP Offload Media Lite will be used to upload media to DigitalOcean Spaces.

To install the plugin, use the following command in the project:

composer require wpackagist-plugin/amazon-s3-and-cloudfront

Then push to updated composer.json and composer.lock to git. That should trigger a new deployment.

The next thing we want to do is create a new DigitalOcean space. Choose the region, give it unique name then select project and click Create Space. Check the image below:

Citizix Create Digital Ocean Space.
Citizix Create Digital Ocean Space.

Then create access keys that will be used to access the space by going to Spaces -> Manage Keys -> Generate New Token:

Citizix Digital Ocean Space access keys
Citizix Digital Ocean Space access keys

On the WordPress side, go to plugins, activate the WP Offload Media plugin and enter the access keys on the plugin options page:

Citizix - WordPress Digital Ocean Media
Citizix – WordPress Digital Ocean Media

Select the data center and enter the Space name.

Citizix - DO WordPress Offload Media Lite
Citizix – DO WordPress Offload Media Lite

Congratulations, now your files will be uploaded to Spaces and will persist between deployments. Just make sure to configure the CDN for the Spaces afterwards.

Citizix - Offload media lite done
Citizix – Offload media lite done

# Tweaking App configuration

Since we are using Nginx to serve traffic, it is possible to update its configuration.

The maximum file upload size is set to 2 megabytes. We could increase it to 200mb In nginx.conf in the root of our repo with this:

client_max_body_size 100M;

For PHP, we need to create a custom php.ini. We need to create a file called .user.ini in the document root of our repository. Add the following content:

post_max_size = 100M
upload_max_filesize = 100M

After the app has re-deployed itself, you will be able to upload a file up to 100 megabytes.

# Conclusion

Up to this point, we have managed to set up wordpress to process images and upload to Digital Ocean Spaces. Digital Ocean Apps is reasonably priced and scaling the servers horizontally and vertically is simple and its easy to work with.

Since the Digital Ocean App is a serverless platform please keep in mind that:

  • If you need to install a theme, we probably also need to run some commands to build the theme, like composer install, npm install, or webpack -p, these will go in the build commands box in the DO apps configuration
  • You could replace the WordPress Cron with a real Cron job. Since the DO App Platform doesn’t support Cron, we could use a Docker container with cURL installed to call /wp-cron.php every minute.
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy