{"id":2059,"date":"2021-06-15T08:18:40","date_gmt":"2021-06-15T05:18:40","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/set-up-upcloud-managed-databases\/"},"modified":"2021-06-15T08:18:40","modified_gmt":"2021-06-15T05:18:40","slug":"set-up-upcloud-managed-databases","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/set-up-upcloud-managed-databases\/","title":{"rendered":"How to set up UpCloud Managed Databases"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Setting up UpCloud Managed Databases is your carefree solution to database hosting at any scale. It allows users to deploy professional-grade database services on UpCloud without a moment spent in a manual installation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Taking advantage of the expert-managed cluster setups brings huge advantages with minimal effort when comparing the work required to deploy a similar system from the ground up. In this tutorial, we\u2019ll show you how to effortlessly set up Managed Databases and how to connect your application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deploying Managed Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/upcloud.com\/global\/products\/managed-databases\">UpCloud Managed Databases<\/a> are offered in 2 and 3-node clustered configurations with options to scale the services as needed with zero interruption. Unclustered single-node databases are also available which are great for testing and development before effortlessly scaling up to production.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To get started, go to your UpCloud Control Panel and find the Databases section in the main menu.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/upcloud-managed-databases.png\" alt=\"UpCloud Managed Databases\" class=\"wp-image-21341\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Deploy your first Managed Database by clicking the Create Database button. This will open up the database configuration options. Make the following selections according to your requirements.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Select the location<\/li><li>Choose your database type<\/li><li>Pick your database plan\n<ul>\n<li>Select how many database nodes you want, 1-3<\/li>\n<li>Select the resources for each node<\/li>\n<\/ul>\n<\/li><li>Check your connection access options<\/li><li>Set your Allowed IP addresses<\/li><li>Enter your database service name<\/li><li>Enter hostname<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Once finished, click the Create Database Service button to deploy!<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/upcloud-managed-database-deploying.png\" alt=\"UpCloud Managed Database deploying\" class=\"wp-image-21392\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then sit back and relax while your new database service is built.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connecting to the Managed Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Managed Databases offer a carefree approach to installation and management while still providing many of the same features as self-hosted databases. After deploying your first Managed Database, you are all set to begin using it like any other database with common database clients.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this example, we are using the <tt>mycli<\/tt> command-line database client. Install the client on your computer or Cloud Server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Ubuntu and Debian\nsudo apt install mycli\n# CentOS\nsudo yum install mycli<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using the client, you can easily connect to the Managed Database with the authentication details as shown in your UpCloud Control Panel.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mycli --user <span style=\"color: #ff0000;\">&lt;username&gt;<\/span> --password=<span style=\"color: #ff0000;\">&lt;password&gt;<\/span> --host <span style=\"color: #ff0000;\">&lt;dbname-id&gt;<\/span>.db.upclouddatabases.com --port 11550 <span style=\"color: #ff0000;\">&lt;databse-name&gt;<\/span><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also use the connection string which includes all the necessary authentication details. Below is an example of the connection string.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mycli mysql:\/\/upadmin:no76c30yomvf6ado@example-mctapmghasah.db.upclouddatabases.com:11550\/defaultdb?ssl-mode=REQUIRED<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the Private connection is only available to Cloud Server which is connected to the Utility network and is located within the same data centre as the database. Also, if you\u2019ve disabled the Allow all from the Utility network, you will need to add the Utility network IP address of your Cloud Server to the list of Allowed IP addresses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For accessing the database from an external location, you will need to enable Public access to the database details. Remember to add your IP address to the list of Allowed IP addresses.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/upcloud-managed-databases-public-connection.png\" alt=\"Enabling public connection on UpCloud Managed Database\" class=\"wp-image-21459\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then use the Connection string which includes the \u201c<tt>public-<\/tt>\u201d identifier in the database hostname.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mycli mysql:\/\/upadmin:no76c30yomvf6ado@<span style=\"color: #ff0000;\">public-<\/span>example-mctapmghasah.db.upclouddatabases.com:11550\/defaultdb?ssl-mode=REQUIRED<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all you need, you should now be connected to your Managed Database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Quick install WordPress on Cloud Server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A great benefit of utilising Managed Databases is how the database is run independently from the applications that use it. This approach allows you to make use of the high availability and scalability of the Managed Databases without worrying about downtime of your applications themselves.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we are deploying a WordPress website to demonstrate the process of connecting to the Managed Database. For this purpose, we will install a simple web server to run WordPress which will then utilise the Managed Database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Deploy a new Cloud Server or use any existing server within the same zone as your Managed Database. Configure the server as you prefer, for example by using either Ubuntu or Debian operating system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once deployed, log in using SSH and install the following packages.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install apache2 php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then download the latest version of WordPress.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">wget https:\/\/wordpress.org\/latest.tar.gz -P $HOME\/<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Unpack the WordPress site, for example in <em>\/var\/www\/html<\/em> using the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tar -zxvf $HOME\/latest.tar.gz -C \/var\/www\/html<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, change the DocumentRoot in the Apache default configuration to point to the WordPress directory. The command below should handle that in one go.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo sed -i 's\/html\/html\/wordpress\/' \/etc\/apache2\/sites-available\/000-default.conf<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then update the file permissions to ensure the site will be accessible.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo find \/var\/www\/html\/wordpress -type d -exec chmod 755 {} ;\nsudo find \/var\/www\/html\/wordpress -type f -exec chmod 644 {} ;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Afterwards, restart the webserver to apply all changes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl restart apache2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the web service side of our WordPress demo ready, continue in the next section on how to connect it with the Managed Database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring WordPress to use the database service<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Connecting an application to a Managed Database works just like with any self-hosted database. To do so, you first need to create a database for your application, WordPress in this example, and create a username with the required permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that you should create separate users and databases for each application. To do so, you can use the mycli command-line client.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Connect to your database from a terminal, for example using the mycli tool and your connection string as displayed in your UpCloud Control Panel.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mycli mysql:\/\/upadmin:no76c30yomvf6ado@example-mctapmghasah.db.upclouddatabases.com:11550\/defaultdb?ssl-mode=REQUIRED<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once connected, you will be greeted by the default database command prompt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new database by the name <tt>wordpress<\/tt>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE DATABASE wordpress;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new username defined by the Utility network IP address of your Cloud Server that is hosting your WordPress instance.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE USER 'wordpress'@'<span style=\"color: #ff0000;\">&lt;utility-ip-address&gt;<\/span>' IDENTIFIED BY '&lt;password&gt;';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then grant the <tt>wordpress<\/tt> user all permissions to the new database. Make sure to include the Utility IP address in the user details to restrict access to the database solely for your own Cloud Server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">GRANT ALL ON wordpress.* TO 'wordpress'@'<span style=\"color: #ff0000;\">&lt;utility-ip-address&gt;<\/span>';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, flush the grant table to make the changes take effect.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">FLUSH PRIVILEGES;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When done, exit the database command prompt and close the connecting.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">EXIT;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should now be able to connect to the new database table with the user you just created.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mycli --user wordpress --password=&lt;password&gt; --host &lt;dbname&gt;.db.upclouddatabases.com --port 11550 wordpress<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, configure the same database connection details on your WordPress instance by setting up the wp-config.php file by making a copy of the sample and then editing it as indicated below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp \/var\/www\/html\/wordpress\/wp-config-sample.php \/var\/www\/html\/wordpress\/wp-config.php\nnano \/var\/www\/html\/wordpress\/wp-config.php<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set the database and username as shown below and replace the <tt style=\"color: #ff0000;\">&lt;password&gt;<\/tt> and <tt style=\"color: #ff0000;\">&lt;hostname&gt;<\/tt> with your own.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ ** MySQL settings - You can get this info from your web host ** \/\/\n\/** The name of the database for WordPress *\/\ndefine( 'DB_NAME', 'wordpress' );\n\n\/** MySQL database username *\/\ndefine( 'DB_USER', 'wordpress' );\n\n\/** MySQL database password *\/\ndefine( 'DB_PASSWORD', '<span style=\"color: #ff0000;\">&lt;password&gt;<\/span>' );\n\n\/** MySQL hostname *\/\ndefine( 'DB_HOST', '<span style=\"color: #ff0000;\">&lt;hostname&gt;<\/span>.db.upclouddatabases.com:11550' );<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When done, save the file and exit the editor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should now be able to take WordPress through its initial setup. Open the public IP address of your Cloud Server on your web browser to check. You should see the following configuration screen.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/upcloud-wordpress-welcome.png\" alt=\"WordPress deployment using UpCloud Managed Database\" class=\"wp-image-21460\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Connecting your application or service after setting up UpCloud Managed Databases is as easy as one, two, three! With quick deployment, you can easily begin developing your next idea without a single worry about maintenance. And when you are ready to unveil your creation, zero-downtime scalability will help you take it to the next level! If you want to learn more, check out our <a href=\"https:\/\/upcloud.com\/global\/resources\/docs\/managed-databases\">documentation for Managed Databases.<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","community-category":[226,268],"class_list":["post-2059","tutorial","type-tutorial","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2059","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2059"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2059\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2059"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}