Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

How to use Vultr Managed Databases for MySQL with WordPress on Ubuntu 20.04

Author: Francis Ndungu

Last Updated: Mon, Oct 31, 2022
Managed Databases Ubuntu

Introduction

WordPress is a popular Content Management System (CMS) for creating blogs, corporate websites, and portals. It's powered by PHP and MySQL, and the open-source CMS powers over one-third of all websites. Today, it is convenient to deploy WordPress on managed MySQL databases to take advantage of point-in-time recovery, automatic backups, and off-site replication.

Vultr offers highly-available managed database solutions that you can use to deploy, scale, and run your WordPress sites without any risk of losing data. This guide shows you how to install WordPress with Vultr's managed database on Ubuntu 20.04 server.

Prerequisites

To proceed with this guide:

1. Install and Enable Dependency Packages

WordPress requires several PHP extensions and Apache modules to function. Follow the steps below to install the extensions and enable the modules.

  1. Update the Ubuntu server's package information index.

    $ sudo apt update 
    
  2. Ensure your system is up to date.

    & sudo apt -y upgrade
    
  3. Install the following PHP extensions.

    $ sudo apt install -y php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
    
  4. Enable the Apache mod_rewrite module. WordPress requires the module to craft human-friendly URLs.

    $ sudo a2enmod rewrite
    
  5. Restart Apache to load the new changes.

    $ sudo systemctl restart apache2
    

2. Set Up a MySQL Database For WordPress

The WordPress application requires different database tables to function including: posts, users, comments, options, and more. These tables are directly related and share a single database. Follow the instructions below to create a database for your WordPress site:

  1. Install the MySQL client on your server. Remember, because you're using Vultr's managed database, you don't have to install MySQL server on your server. You only need the MySQL client application to run SQL commands on the managed database from your server.

    $ sudo apt install mysql-client-core-8.0 
    
  2. Issue the following command to log in to your Vultr's managed database server. Replace test_server.vultrdb.com and 16751 with the correct host and port for your managed database server.

    $ mysql -h test_server.vultrdb.com -P 16751 -u vultradmin -p 
    
  3. Enter your MySQL password (For instance, TEST_PASSWORD) and press ENTER to proceed. Then, issue the following command to set up a wordpress database and a wordpress_user account. Replace EXAMPLE_PASSWORD with a secure password.

    mysql> CREATE DATABASE wordpress;
    
           CREATE USER 'wordpress_user'@'%' IDENTIFIED WITH mysql_native_password BY 'EXAMPLE_PASSWORD';
    
           GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress_user'@'%';
    
           FLUSH PRIVILEGES;
    

    Output.

    ...
    
    Query OK, 1 row affected (0.00 sec)
    
  4. Log out from Vultr's managed database server.

    mysql> QUIT;
    

3. Create a WordPress Directory and Set Up a Virtual Host File

To separate your WordPress site from the rest of the system files, you must create a new directory for your site. Then, to keep things organized, you need a separate virtual host file for WordPress. Follow the steps below to carry out those tasks:

  1. Create a new wordpress directory under your web server's root directory (/var/www/).

    $ sudo mkdir /var/www/wordpress
    
  2. Take ownership of the new wordpress directory.

    $ sudo chown -R $USER:$USER /var/www/wordpress
    
  3. Use a text editor to open a new virtual host configuration file (wordpress.conf) for the WordPress site under the /etc/apache2/sites-available/ directory.

    $ sudo nano /etc/apache2/sites-available/wordpress.conf
    
  4. Enter the following information into the /etc/apache2/sites-available/wordpress.conf file. Replace 172.16.0.1 with your server's public IP address or domain name.

    <VirtualHost *:80>
    
    
    
        ServerName 172.16.0.1
    
        DocumentRoot /var/www/wordpress
    
    
    
        <Directory /var/www/wordpress>
    
            Options Indexes FollowSymLinks MultiViews
    
            AllowOverride All
    
            Order allow,deny
    
            allow from all
    
        </Directory>
    
    
    
    </VirtualHost>
    
  5. Save and close the /etc/apache2/sites-available/wordpress.conf file.

  6. Enable the new /etc/apache2/sites-available/wordpress.conf configuration file.

    $ sudo a2ensite wordpress.conf
    
  7. Disable the default virtual host configuration file.

    $ sudo a2dissite 000-default.conf
    
  8. Restart Apache to load the new changes.

    $ sudo systemctl restart apache2
    

4. Download and Configure WordPress

WordPress maintains an up-to-date online repository where you can download the latest version. Execute the following steps to download WordPress:

  1. Navigate to the /var/www/wordpress directory.

    $ cd /var/www/wordpress
    
  2. Use the Linux curl command to download the latest WordPress package.

    $ curl -O https://wordpress.org/latest.tar.gz
    
  3. Unzip the latest.tar.gz archive file to your working directory.

    $ tar xzvf latest.tar.gz
    
  4. Copy the content of the extracted wordpress directory to the /var/www/wordpress directory.

    $ sudo rsync -rtv wordpress/ /var/www/wordpress
    

5. Configure WordPress and Finish the Installation

After downloading WordPress to your server, the last step is configuring the application to use the externally managed Vultr database. The steps below take you through the process:

  1. Create a new copy of the WordPress configuration file.

    $ sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
    
  2. Set up an upgrade directory under var/www/wordpress/wp-content. WordPress requires this directory to upgrade your site when a new version is available.

    $ sudo mkdir /var/www/wordpress/wp-content/upgrade
    
  3. Assign the ownership of the /var/www/wordpress directory to www-data and set the appropriate permissions. Apache runs under the www-data user and requires permissions to manage the files.

    $ sudo chown -R www-data:www-data /var/www/wordpress
    
    $ sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
    
    $ sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;
    
  4. Generate new salts and keys using the official WordPress secret-key API.

    $ curl -s https://api.wordpress.org/secret-key/1.1/salt/
    

    Copy the generated values in a safe place.

    define('AUTH_KEY',         'g,W6>~F)N:``)08a1v-NofzX K; #?vgE=9Un[TOn,jCqa?m!aF#18%#lz{D|$k:');
    
    define('SECURE_AUTH_KEY',  '5bIx_wR-^yVzX_t|9vw3z-L,1~#7E39*@-ZEjU{WV||m3|g-)Yv?(bu*X1~B5#kA');
    
    define('LOGGED_IN_KEY',    'BP0T|(eicO[Fc*&,k/4/Fk$/A+[6Ci9d391b)jp1%E|Y||-i@Ef)Qs!@)60?u{ >');
    
    define('NONCE_KEY',        '{>JGt8!97%LPOkV J)Rv-I =#rah2|)S5p}F8twtZho$:>OuF5$zu7xTz@||PpKv');
    
    define('AUTH_SALT',        '^G4Z8C3)y8~w#0=mm|+|&O]v16:z-[zvG~`,hxIs27C>Q9_=>KyKG=L/c~WU|@>`');
    
    define('SECURE_AUTH_SALT', '`yDrZ}CBp[VF5T2?oGa-q@&7]z)PJaPq9y~7],On11gUgx57hY-ZoA{?z8-~Q/Jq');
    
    define('LOGGED_IN_SALT',   '~;TGD[1#ct8lbTU-AR+dFL[Fl<I1:lgP-:f,.zZHnighvSZ@paNdp$7gb08[ S1*');
    
    define('NONCE_SALT',       'W6Vs!S]P1$*/)4Lu[/>|]$dX*?6@}%?c-pHI`!0:3Q&_lIl}-nqol+>;*`/DD@NU');
    
  5. Open the WordPress configuration file that you created earlier.

    $ sudo nano /var/www/wordpress/wp-config.php
    
  6. Locate the following section in the configuration file and paste the values you've retrieved from the WordPress secret-key API.

    ...
    
    define('AUTH_KEY',         'g,W6>~F)N:``)08a1v-NofzX K; #?vgE=9Un[TOn,jCqa?m!aF#18%#lz{D|$k:');
    
    define('SECURE_AUTH_KEY',  '5bIx_wR-^yVzX_t|9vw3z-L,1~#7E39*@-ZEjU{WV||m3|g-)Yv?(bu*X1~B5#kA');
    
    define('LOGGED_IN_KEY',    'BP0T|(eicO[Fc*&,k/4/Fk$/A+[6Ci9d391b)jp1%E|Y||-i@Ef)Qs!@)60?u{ >');
    
    define('NONCE_KEY',        '{>JGt8!97%LPOkV J)Rv-I =#rah2|)S5p}F8twtZho$:>OuF5$zu7xTz@||PpKv');
    
    define('AUTH_SALT',        '^G4Z8C3)y8~w#0=mm|+|&O]v16:z-[zvG~`,hxIs27C>Q9_=>KyKG=L/c~WU|@>`');
    
    define('SECURE_AUTH_SALT', '`yDrZ}CBp[VF5T2?oGa-q@&7]z)PJaPq9y~7],On11gUgx57hY-ZoA{?z8-~Q/Jq');
    
    define('LOGGED_IN_SALT',   '~;TGD[1#ct8lbTU-AR+dFL[Fl<I1:lgP-:f,.zZHnighvSZ@paNdp$7gb08[ S1*');
    
    define('NONCE_SALT',       'W6Vs!S]P1$*/)4Lu[/>|]$dX*?6@}%?c-pHI`!0:3Q&_lIl}-nqol+>;*`/DD@NU');
    
    ...
    
  7. Find the following database settings. Replace EXAMPLE_PASSWORD with the correct password. Remember, you're using an externally managed database and you must replace test_server.vultrdb.com:16751 with the correct host and port combination.

    ...
    
    
    
    /** The name of the database for WordPress */
    
    define( 'DB_NAME', 'wordpress' );
    
    
    
    /** MySQL database username */
    
    define( 'DB_USER', 'wordpress_user' );
    
    
    
    /** MySQL database password */
    
    define( 'DB_PASSWORD', 'EXAMPLE_PASSWORD' );
    
    
    
    /** Database hostname */
    
    define( 'DB_HOST', 'test_server.vultrdb.com:16751' );
    
    
    
    ...
    
  8. Save and close the /var/www/wordpress/wp-config.php file.

  9. Enter your server's public IP address or domain name on a web browser to complete the WordPress Installation.

  10. Select a language and on the next screen, fill up the form that appears and click Install WordPress to finish the installation.

    WordPress Installation Page.

Conclusion

This guide shows you how to install WordPress with Vultr's managed MySQL database on Ubuntu 20.04 server. After installing WordPress, you can customize your site with new themes and plug-ins. Vultr's managed database works right out of the box and automates all demanding aspects of database administration so that you stay focused on bettering your WordPress site.

Want to contribute?

You could earn up to $600 by adding new articles.