Set Up WordPress on DigitalOcean
Steps
-
Register a new domain (e.g. NameCheap) and set the domain name servers to:
ns1.digitalocean.comns2.digitalocean.comns3.digitalocean.com -
Connect to the droplet with PuTTY.
-
Log into MySQL:
mysql -u root -p -
Create the database and user.
Database should be named like
exampledomain_wp. User should be likeexampledo_wpuser— MySQL usernames have a 16-char limit, so abbreviate the domain (exampledomain→exampledo) to leave room for the_wpusersuffix.CREATE DATABASE domain_wp;CREATE USER domain_wpuser@localhost IDENTIFIED BY '<strong-password>';GRANT ALL PRIVILEGES ON domain_wp.* TO domain_wpuser@localhost;FLUSH PRIVILEGES; -
Quit MySQL:
exit -
Create a new folder for the WordPress site:
cd /var/wwwmkdir domain.comcd domain.com -
Download the latest WordPress package and rename the output folder to
public_html:wget http://wordpress.org/latest.tar.gztar xzvf latest.tar.gzmv wordpress public_htmlrm latest.tar.gz -
Edit the WordPress config:
cd public_htmlcp wp-config-sample.php wp-config.phpnano wp-config.php -
Set values for
DB_NAME,DB_USER,DB_PASSWORD, andDB_HOST:/** The name of the database for WordPress */define('DB_NAME', 'domain_wp');/** MySQL database username */define('DB_USER', 'domain_wpuser');/** MySQL database password */define('DB_PASSWORD', '<strong-password>');/** MySQL hostname */define('DB_HOST', '127.0.0.1'); -
Set the KEY and SALT values by overwriting the values generated at https://api.wordpress.org/secret-key/1.1/salt/. (Hint: Ctrl+K deletes a line in nano.)
-
Close and save (Ctrl+X, Y, Enter).
-
Create the uploads folder and grant ownership of
wp-contenttowww-data:mkdir /var/www/domain.com/public_html/wp-content/uploadssudo chown -R www-data:www-data /var/www/domain.com/public_html/wp-content -
Configure Apache for the new domain by copying an existing conf:
cd /etc/apache2/sites-availablecp example.com.conf domain.com.confsudo nano domain.com.conf -
Remove any
Redirect Matchlines if present (Ctrl+K deletes a line). -
Change or add config entries as needed:
ServerAdmin admin@domain.comDocumentRoot /var/www/domain.com/public_htmlServerName domain.comServerAlias www.domain.com -
Close and save (Ctrl+X, Y, Enter).
-
Enable the new site and restart Apache:
sudo a2ensite domain.com.confsudo service apache2 restart -
Edit
/etc/hosts:sudo nano /etc/hosts -
Add a new line for the domain:
127.0.0.1 domain.com -
Close and save (Ctrl+X, Y, Enter).
-
Add the domain to the DigitalOcean Name Server control panel and point it to the droplet: https://cloud.digitalocean.com/networking/domains
-
Open the domain "More" menu and add a new CNAME entry for
wwwpointing todomain.com. -
Complete the WordPress setup by pointing your browser to
www.domain.com:- Enter the site title, username, and email.
- Save the generated password in a password manager.
- Click the Install WordPress button.
-
This is no longer needed — WordPress should use the "direct" update method by default. (Previously: install the "SSH SFTP Updater Support" plugin from https://wordpress.org/plugins/ssh-sftp-updater-support/.)
-
Download the file:
wget https://downloads.wordpress.org/plugin/ssh-sftp-updater-support.0.7.1.zip -
Unzip it to the site's plugins folder:
unzip ssh-sftp-updater-support.0.7.1.zip -d /var/www/domain.com/public_html/wp-content/plugins -
Log into the WordPress admin and activate the plugin.
-
Install something (update, theme, whatever) to configure the connection settings:
- Hostname:
domain.com - SSH/FTP User:
root - SSH/FTP Password: (leave blank)
- Select the private key file to upload:
DO-private.txt - Select SSH2 as the method.
- Hostname:
-
-
Create a cert and enable HTTPS using certbot:
sudo certbot --apache -
Done!