Support Online
Skip to main content

Improving WordPress Performance with Ubuntu 18.04 Remote MySQL Installation

What will you learn in this guide?

In this guide, you will learn how to separate the database from the web server to improve performance in applications that use MySQL, such as WordPress.
We will make MySQL accessible only from a specific IP and secure the connections with SSL/TLS.

🧠 Technical Summary

Main topic: MySQL remote database configuration on Ubuntu 18.04
Purpose: Increase performance and scalability by separating web server and database load
Approach:

  • Opening MySQL to remote connections
  • Providing secure communication with SSL/TLS
  • IP based user authorization
  • Connecting WordPress to remote database

🛠 Requirements

  • 2 Ubuntu 18.04 Cloud Servers
    • tr1-db01: Database Server (MySQL)
    • tr1-web01: Web Server (Nginx + PHP)
  • On both servers:
    • non-root user with sudo authority
    • UFW firewall active
  • Nginx and PHP installed on the web server
  • MySQL is installed on the database server
  • (Recommended) Domain name and Let's Encrypt SSL on the web server

1️⃣ Opening MySQL to Remote Connections (Database Server)

MySQL only accepts local connections by default.
We need to change this setting.

1.1 Open the MySQL configuration file

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
  • This file contains MySQL server settings.

  1. Set the IP address to listen on

[mysqld]
bind-address = db_sunucu_ip
  • This setting allows MySQL to accept connections from an external network.

  1. Force SSL/TLS connection

require_secure_transport = on
  • This setting blocks unencrypted connections.

  1. Generate SSL certificates

sudo mysql_ssl_rsa_setup --uid=mysql
  • This command generates the required SSL keys for MySQL.

  1. Restart MySQL service

sudo systemctl restart mysql
  • This action activates the new settings.

  1. Check if MySQL is listening

sudo netstat -plunt | grep mysqld
  • db_server_ip:3306 should appear in the output.

  1. Allow MySQL on firewall

sudo ufw allow mysql

-This step allows connections from the web server.


2️⃣ Creating WordPress Database and Users

2.1 Login to MySQL


sudo mysql
  • This command opens the MySQL instance.
  1. Create WordPress database

CREATE DATABASE wp_site;
  • This database will be used by WordPress.

  1. Create local user

CREATE USER 'wp_local_user'@'localhost' IDENTIFIED BY 'guclu_sifre';
GRANT ALL PRIVILEGES ON wp_site.* TO 'wp_local_user'@'localhost';
  • This user can only access from the database server.

  1. Create remote user

CREATE USER 'wp_remote_user'@'web_sunucu_ip' IDENTIFIED BY 'guclu_sifre';
GRANT ALL PRIVILEGES ON wp_site.* TO 'wp_remote_user'@'web_sunucu_ip';
  • This user can only connect from the web server.

  1. Activate permissions and exit

FLUSH PRIVILEGES;
exit
  • This action applies the authorizations immediately.

3️⃣ Testing Remote Connection (Web Server)

  1. Connect to the web server

ssh kullanici@web_sunucu_ip
  • This command connects to the web server via SSH.

  1. Install MySQL client

sudo apt update
sudo apt install mysql-client
  • This tool is required for remote MySQL connection.

  1. Connect to remote database

mysql -u wp_remote_user -h db_sunucu_ip -p
  • If the connection is successful, the MySQL prompt opens.

  1. Verify SSL connection

status
  • The SSL: Cipher in use line should appear in the output.

4️⃣ WordPress Installation and Configuration

4.1 Download and extract WordPress


cd ~
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
  • This process downloads WordPress files.

  1. Prepare the configuration file

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
  • This file contains WordPress settings.

  1. Generate security keys

curl -s https://api.wordpress.org/secret-key/1.1/salt/
  • These keys increase WordPress security.

  1. Enter database information

define('DB_NAME', 'wp_site');
define('DB_USER', 'wp_remote_user');
define('DB_PASSWORD', 'guclu_sifre');
define('DB_HOST', 'db_sunucu_ip');
define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);
  • These settings connect WordPress to remote MySQL.

  1. Move files to web directory

sudo cp -a ~/wordpress/* /var/www/html
sudo chown -R www-data:www-data /var/www/html
  • This process prepares WordPress for publication.

5️⃣ Completing the Setup Via the Web Interface

  1. Navigate to your domain from the browser:

https://ornek-domain.com
  • Select the language and complete the installation. After installation, you can log in to the WordPress administration panel.

❓ Frequently Asked Questions (FAQ)

1. Why should I move the database to a separate server? Provides performance and scalability.

2. Why is SSL/TLS mandatory? It increases security by encrypting data traffic.

3. Should I use private or public IP? If in the same region, private IP is recommended.

4. Why did we use IP restriction instead of %? Reduces the risk of unauthorized access.

5. Does it work on Ubuntu 20.04 or 22.04? Yes, the steps are largely the same.

🎯 Result

With this guide, you have opened MySQL to remote connections safely. You have established a more performant architecture by separating the web and database load.

👉 You can install this structure in minutes on the GenixNode platform and immediately observe the performance difference of your application.