12monkeys
By:
12monkeys

phpMyAdmin One Click Installation

June 10, 2017 86 views
PHP MySQL

I just launched a phpMyAdmin droplet as a 1 click app. But I cannot connect to it from PHP on my local machine.

I've got it set up like so -

// database connection
$db_username = 'user';
$db_password = 'xxx';
$db_database = 'db_name';
$db_host = "123.456.789.100";

// connect to DB
try {
    $dbh = new PDO("mysql:host=$db_host;dbname=$db_database;charset=utf8", $db_username, $db_password);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage(); die();
}

It works for my other databases, but not on digitalocean :/

1 Answer

Hi @12monkeys

Almost every one-click-app comes with firewall enabled, so you need to allow access to your MySQL from the outside if you want to use it remotely.

You can run this command to show the status of the firewall:

sudo ufw status

And run this command to allow access from anywhere to MySQL:

sudo ufw allow 3306

Please setup advanced, long users and password - or only allow connections from specific IP addresses. You can read more about the UFW firewall in this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-16-04

UFW, or Uncomplicated Firewall, is an interface to iptables that is geared towards simplifying the process of configuring a firewall. While iptables is a solid and flexible tool, it can be difficult for beginners to learn how to use it to properly configure a firewall. If you're looking to get started securing your network, and you're not sure which tool to use, UFW may be the right choice for you. This tutorial will show you how to set up a firewall with UFW on Ubuntu 16.04.
Have another answer? Share your knowledge.