By vin2164382
I want to ask that is there any way I can connect 1 VPS containing my website to another VPS running the database or not? Anyone who has a specific tutorial to design it on MariaDB please help me, I appreciate it.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @vin2164382,
Yes, it’s possible to connect this. It’s actually a really common way of structuring your servers. You have one server for your Web Requests and another for your Database.
The first and most important thing you need to do is allow access for VPS 1 on VPS 2(where your database is) on the port your database is listening on. Usually, MySQL/MariaDB use the port 3306.
To allow incoming MySQL connections from a specific IP address or subnet, specify the source. For example, if you want to allow the entire 15.15.15.0/24 subnet, run these commands:
sudo iptables -A INPUT -p tcp -s 15.15.15.0/24 --dport 3306 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 3306 -m conntrack --ctstate ESTABLISHED -j ACCEPT
The second command, which allows the outgoing traffic of established MySQL connections, is only necessary if the OUTPUT policy is not set to ACCEPT.
You’ll need to change the 15.15.15.0/24 with your actual IP address and run the above commands on the Database server.
Next, when you are with this, you should be able to connect with your credentials in your website to the database.
Regards, KFSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.