Remote SQL for CyberPanel

At the release of version 2.0.1, CyberPanel asked it’s users to vote the most need feature and the overwhelming majority voted for the option to use Remote SQL server in CyberPanel. In 2.0.2, remote SQL has been added. This feature is best intended for the people who want to host the database separately from the webserver. If you choose this option during installation, then:

  1. CyberPanel database (which hosts all information about CyberPanel) will be created remotely and not locally.
  2. Any database you create on CyberPanel will also be created there, so make sure in your applications you use the right hostname.

In this guide, we will see the step by step procedure to configure a remote MySQL/MariaDB server.


1. Setting up a remote MariaDB server

1.1 Using Remotely-hosted database service

In case you are using Amazon’s RDS or Google’s Cloud SQL or Azure’s SQL services, you need to make sure that your SQL user has the permission to create new databases. Once that is confirmed, please make sure you have the following information and skip to step 2

  • Host Name
  • Port
  • Username
  • Password
  • Schema Table Name ( usually its MySQL )

1.2 Installing and configuring remote MariaDB for CyberPanel

Login to your clean server that you want to use for hosting your database.

1.2.1 Adding latest MariaDB repository

Run the following command to add the latest version of MariaDB repo to your Linux system irrespective of your OS

sh <(curl https://downloads.mariadb.com/MariaDB/mariadb_repo_setup || wget -O - https://downloads.mariadb.com/MariaDB/mariadb_repo_setup)

1.2.2 Installing latest MariaDB

For Ubuntu 18/20 use the following command

apt install mariadb-server mariadb-client

For Centos 7

yum install mariadb-server mariadb-client

For Centos 8

dnf install mariadb-server mariadb-client

1.2.3 Securing the installation and allowing remote root login

After the installation is complete, please enable MariaDB so it starts with bootup using the following command

systemctl enable mariadb

Run the following command to secure the installation

sudo mysql_secure_installation

Please set a root password, remove the anonymous account, remove the test database but don’t disallow remote root access.

1.2.4 Binding MariaDB to the main server

Edit /etc/my.cnf or included configuration files from a sub-directory and change the line with starting with keyword bind to this

bind-address=<your_main_server_IP_here>

1.2.5 Allow firewall access

Add a firewall rule to allow access to port 3306 from your main server’s IP.

1.2.6 Testing the installation

Login to your main server ( the server where CyberPanel is to be installed ) and run the following command

mysql -u user_name -h mysql_server_ip -p

Enter the password you selected and it should log you into remote MariaDB installation


2. Installing CyberPanel with remote SQL

Run the installation command here

  • Choose 1 to install CyberPanel at the first step

  • Choose whether you want to install CyberPanel with OLS or LS Enterprise
  • Choose if you want to install FTP, Mail and other service or not

Now you will be presented with an option on whether you want to install Cyberpanel with Remote MySQL or not, please select Yes by entering Y.

Enter all the details you received or set up in the first part of this tutorial

Continue the installer and it will install CyberPanel with remote MySQL, and all the databases for the websites will be hosted remotely too.

In less than 20 minutes, CyberPanel will be installed on a remote database server.

2 Likes

I have trouble with remote database via bash script… Have anyone have the same issue?

On a clean (8GB-4vIntelCPU) droplet: ubuntu 22.04 LTE with cluster (external) database, i get the following error:

[10.15.2022_09-42-12] [ERROR] We are not able to run groupadd -g 2001 ftpgroup return code: 9. Fatal error

And stops the install process completely.

[ERROR] We are not able to run mount -o loop,rw,nodev,nosuid,noexec,nofail /usr/.tempdisk /tmp return code: 1.

[ERROR] We are not able to run cp /usr/local/lsws/lsphp71/bin/php /usr/bin/ return code: 1.

Any way to migrate from local database to remote database after install? I have already backup and put database in remote server, but looking where to change settings.

Thanks

This tutorial does not work anymore. This is because a cyberpanel database user requests access to remote cyberpanel DB

File “/usr/local/CyberPanel/lib/python3.10/site-packages/django/utils/asyncio.py”, line 26, in inner
return func(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.10/site-packages/django/db/backends/mysql/base.py”, line 234, in get_new_connection
return Database.connect(**conn_params)
File “/usr/local/CyberPanel/lib/python3.10/site-packages/MySQLdb/init.py”, line 130, in Connect
return Connection(*args, **kwargs)
File “/usr/local/CyberPanel/lib/python3.10/site-packages/MySQLdb/connections.py”, line 185, in init
super().init(*args, **kwargs2)
django.db.utils.OperationalError: (1045, “Access denied for user ‘cyberpanel’@‘45.83.205.105’ (using password: YES)”)
[03.31.2023_10-49-29] Running /usr/local/CyberPanel/bin/python manage.py makemigrations failed. Running again, try number 3

But this user uses a randomly generated password so we don’t know what privileges to give it the remote DB for that user!

1 Like

Hi, any news about the resolution of this problem ?

Thanks in advance for the support.

in fresh server mysql command not found.