Skip to main content

Set Up WordPress on DigitalOcean

Steps

  1. Register a new domain (e.g. NameCheap) and set the domain name servers to:

    ns1.digitalocean.com
    ns2.digitalocean.com
    ns3.digitalocean.com
  2. Connect to the droplet with PuTTY.

  3. Log into MySQL:

    mysql -u root -p
  4. Create the database and user.

    Database should be named like exampledomain_wp. User should be like exampledo_wpuser — MySQL usernames have a 16-char limit, so abbreviate the domain (exampledomainexampledo) to leave room for the _wpuser suffix.

    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;
  5. Quit MySQL:

    exit
  6. Create a new folder for the WordPress site:

    cd /var/www
    mkdir domain.com
    cd domain.com
  7. Download the latest WordPress package and rename the output folder to public_html:

    wget http://wordpress.org/latest.tar.gz
    tar xzvf latest.tar.gz
    mv wordpress public_html
    rm latest.tar.gz
  8. Edit the WordPress config:

    cd public_html
    cp wp-config-sample.php wp-config.php
    nano wp-config.php
  9. Set values for DB_NAME, DB_USER, DB_PASSWORD, and DB_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');
  10. 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.)

  11. Close and save (Ctrl+X, Y, Enter).

  12. Create the uploads folder and grant ownership of wp-content to www-data:

    mkdir /var/www/domain.com/public_html/wp-content/uploads
    sudo chown -R www-data:www-data /var/www/domain.com/public_html/wp-content
  13. Configure Apache for the new domain by copying an existing conf:

    cd /etc/apache2/sites-available
    cp example.com.conf domain.com.conf
    sudo nano domain.com.conf
  14. Remove any Redirect Match lines if present (Ctrl+K deletes a line).

  15. Change or add config entries as needed:

    ServerAdmin admin@domain.com
    DocumentRoot /var/www/domain.com/public_html
    ServerName domain.com
    ServerAlias www.domain.com
  16. Close and save (Ctrl+X, Y, Enter).

  17. Enable the new site and restart Apache:

    sudo a2ensite domain.com.conf
    sudo service apache2 restart
  18. Edit /etc/hosts:

    sudo nano /etc/hosts
  19. Add a new line for the domain:

    127.0.0.1 domain.com
  20. Close and save (Ctrl+X, Y, Enter).

  21. Add the domain to the DigitalOcean Name Server control panel and point it to the droplet: https://cloud.digitalocean.com/networking/domains

  22. Open the domain "More" menu and add a new CNAME entry for www pointing to domain.com.

  23. Complete the WordPress setup by pointing your browser to www.domain.com:

    1. Enter the site title, username, and email.
    2. Save the generated password in a password manager.
    3. Click the Install WordPress button.
  24. 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/.)

    1. Download the file:

      wget https://downloads.wordpress.org/plugin/ssh-sftp-updater-support.0.7.1.zip
    2. 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
    3. Log into the WordPress admin and activate the plugin.

    4. 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.
  25. Create a cert and enable HTTPS using certbot:

    sudo certbot --apache
  26. Done!

Sources