Laravel Forge is a service that handles creating servers on popular cloud hosting providers. I use it to host my WordPress sites with DigitalOcean and to handle auto deployments from a git push.
Installing WordPress on a cloud server you need to plan for failure. Typically there is no guarantee that you will not wake up one morning and find the server just gone. I’ve personally ran into that with AWS in the past and now I always plan for it.
I like to do all my testing locally and to handle this I create a wp-config-local.php1 file for all my database settings. This file should be added to .gitignore as you do not want to commit it.
Next modify the wp-config.php file with a simple if/else so it will pull the local file in if it exists.
Also notice the
getenv calls which I setup as environmental variables in Forge. This prevents you from committing them and makes your app easy to switch to different servers. It’s not shown in this file but I create environmental variables for all the keys as well.
I’m not a huge fan of plugins. I try to keep the number installed to a bare minimum and only use them if I have a very specific use case.
Since WordPress stores attachment on the disk we need to move those over to s3. I use the following two plugins for this which work together:
This is a good time to review your database backups. Jetpack has VaultPress which is a commercial backup system but others exist. So you should do you research and figure out what suits you best.
Setting up email on a server is never fun. To make it easy I use the wpMandrill plugin which integrates with their mail service. This way if I need to change servers I will not have to setup email again.
Caching isn’t required but if you choose a small server then it will help performance and not overload when you get a spike in traffic. I’m currently using WP Super Cache and have been happy with it.
With these simple plugins and settings your WordPress install will not be dependent on the server for it’s data. You can easily and safely move to different providers or bigger servers without worry.
13 thoughts on “ How to setup WordPress with Forge and DigitalOcean ”
Had a look at the Themosis-project?
If so would be nice to hear your thoughts. 🙂
I’ve looked and bookmarked on my other site (https://laravel-news.com/2014/10/laravel-wordpress-themosis-framework/) for the future when I decide to undergo a redesign. 🙂
It looks promising with my only initial concern is it might be overkill for just theming.
Hi Eric, How well does VaultPress work? I have been using BackWPupt to back my WordPress install to S3. I have yet to have a need to pull a backup back, but it seems like it will happen sometime. I suspect that VaultPress is probably the better of the two options. Is it worth the upgrade? Thanks!
Sorry for the delay in responding. For some reason, I missed your comment. I haven’t used the plugin you are using so I’m not positive on any differences or anything. I’d imagine since VaultPress is official it will always be the safer bet, but I honestly don’t know.
Eric how did you get wpMandrill to work? I can’t get my box to send any emails using the plugin
Anthony, Since this post I switched to using an SMTP plugin. I don’t remember running into issues wpMandrill but I also don’t remember why I switched. 🙂
My recommendation is try one of those if you have issues with it.
Few questions… Forge builds an nginx server, not Apache. WordPress has a whole page dedicated to optimizing your WordPress installation for nginx. I don’t know much about nginx (well, nothing really) and I do realize that the Forge nginx config apparently works out of the box with WordPress, but it is setup differently than how WordPress suggests. I guess I’m wondering if it is better to use the WordPress prescribed nginx config, or keep the default Forge config?
Also, is WP Super Cache the best choice for caching when using Forge? We aren’t on Apache, so the plugin will use a file-based cache (if I’m not mistaken). Once of the benefits of setting up a server on Forge is that we have memcache installed. Should’t we use a plugin (like W3 Total Cache, or other) that takes advantage of memcache, instead of a slower mechanism like file based caching?
If I’m not mistaken, when you deploy WordPress via Forge, doesn’t the default deploy script throw an error, because it is setup for Laravel and runs both composer and artisan commands which are not in the WordPress project? Don’t you need to remove those lines from your deploy script?
Thanks for the comments. One of the great things about Forge is you still have complete access to fine tune any of this as you’d like. For example, you could change the nginx config right from the forge UI and then restart the server and be good to go. To answer your first question, yes if WordPress has an official config recommendation then I would use that.
I’m not certain on WP super cache vs the alternatives. That is the one I went with and so far on a $10 digital ocean box it’s stood up well to being on the front page of HN three different times. Those are my biggest traffic days and it looks like JetPack stats is reporting around 26k views on those. So basically all I’m saying is it held up well under that load and I have no idea how that will compare to the traffic you are expecting.
Yes, you will need to remove those lines. Basically I have mine set to just do the auto deploy with a git pull and nothing more. I’m also not worried about if that could cause a moment or two of downtime but if you are worried about then I would go with Envoyer which handles symlinking everything and ensuring deployments complete before being swapped over.
I hope this helps!
How do you handle updating plugins and database state?
I’ve been doing all updates locally first, then committing, and running again on the server. Unfortunately, I’ve not found an ideal workflow for that yet.
I am using getenv() in wp-config file and also added environment variables in forge, but when I print $_ENV array it does not have any of the variable which I defined in forge. Also getenv() returns false.
Sorry about that. It appears Forge expects you to use the php dotenv package for that. It would need to be installed through composer and here is an example post I found for after it’s included:
Hi eric, have you tried http://runcloud.io ?
I would like to hear your comment regarding this service. Maybe a blog post too? 😀
It’s look like a good service tho.