If you have ever wondered how practical it is to set up and run more than one WordPress site on a Digital Ocean droplet, then this is the article for you.
As my managed WordPress services business becomes larger I have been slowly adding more VPS servers. I prefer to spread my eggs over multiple baskets so use different hosts and servers with a few sites on each.
In the past I have always used VPS’s that include CPanel as I am very familiar with running sites through that interface.
It has become more efficient (SSDs!) however to use VPS servers like the ones from Digital Ocean.
To save others time this is how I went about setting up multiple WordPress sites, handling the domain names, and what I used for a control panel.
About Digital Ocean
Digital Ocean has an amazing set up. They use what they call “Droplets” which are basically VPS’s that you can quickly spin up.
Just to join you get $10 free credit which is enough to spin up a few droplets, and have a play around. If you destroy the droplets they stop charging you.I went about 6 months on 22 cents before starting to use them for my production websites.
If you are not comfortable with linux and words like apache, mysql and php scare you then this is not the path for you and you are better off getting hosting from somewhere like bluehost that has an easy to use interface.
Creating a Droplet
There are a number of templates and different linux versions that you can use to create a droplet with. For myself I normally choose the latest Ubuntu distribution.
Setting up CSF
One of the first things I like to do is get the firewall configured, and for that I use CSF. Don’t forget to take it out of test mode!
Follow this tutorial to set up CSF.
Setting up PHPMyAdmin
I set this up manually however have since noticed it is under the install options of Virtualmin. Recommendation install virtualmin first!
Here is a tutorial to set up Virtualmin on DO.
Before you get to far down the path you should install Virtualmin which is like a poor persons version of CPanel. It is not as flash or intuitive however for the most part does what you need. E.g set up new domains, configure the firewall, easy GUI for apache config files etc.
To set up a new domain they are called “virtual servers” inside Virtualmin, just go ahead and set one up, transfer all your files over and set up your database.
Transferring Domain Names
DNS is a two step process.
- Set your your domain names servers to ns1.digitalocean.com and ns2.digitalocean.com
- Go into your droplet settings (networking | domains) and assign the domain name to the droplet
Traps and Lessons Learned
There are a number of traps you can fall into when doing this kind of stuff.
- One I fell into was not allowing the port for virtualmin inside CSF.
- I needed to manually add a CNAME record for the domains (prior to that www.mydomain.com didn’t work only mydomain.com worked)
- I needed to install this module otherwise photo resizing inside WordPress doesn’t work – # apt-get install php5-gd (then restart apache)
- Make sure you add a swap file, my 1GB of memory was not enough and mysql crashed due to out of memory errors on the first night.
Under services in Virtualmin, Webmin there is an option called “preview website”. You can use this to check your site is basically up and running before changing over your DNS.
Moving Sites To New VPS from CPanel VPS
Over a few attempts I managed to get this down to a pretty quick process.
This is not what I would describe as in depth explanations, more a quick guide of the steps I take to move a site. If you need more help feel free to ask.
On New Server
Create the new virtual server using the domain name. (this will create the folder and database)
On Old Server
Firstly we need to grab the directory of files from the old server and move them to the new server. I used to download onto my PC at home, then ftp up to the new server, however found a much easier way.
Make a zip backup of the home directory. Place this zipe file (temporarily) into an accessible folder. (make sure you delete it after you have copied it!)
- zip -r backtfs /home/mydomainname/public_html/tfs
- Either use the CPanel backup to make a copy of your database SQL file, or use the export functionality of PHPMyadmin, this you will need to download to your home PC
On new Server
Extract the zip file.
In the examples below the folder TFS contains the site files, first they are downloaded, then extracted.
- wget mydomainname.com/backtfs.zip
- unzip backtfs.zip -d /home/tfs/public_html/
- Use the file manager in Virtualmin to place into the correct folder (cut and paste)
- Now use PHPMyadmin to import the SQL file
- Update your WP-Config.php to use the database details of the new server/database (you can use virtualmin to edit any database details)
- This was a last minute gotcha you also need to change the owner of the files in the directory your WordPress is installed in. Navigate to one folder up and run this.
chown -R tfs:tfs public_html – in this case tfs is the virtualdirectory name which is the apache user that you need to change the files to.
Now you can preview the site and everything should be basically working.
The next thing to do is to add the domain and a cname record in Digital Ocean, then finally change the nameservers with your domain provider.
Don’t forget to add the CNAME record!
Other things you might want to think about are any email addresses that you have set up with the site, however that is beyond the scope of this article.
Enjoy your new server, ask away if you have any questions.