I'm trying move an existing Wordpress site to run across two different servers, one with Apache and the main source code and the other that just has the database running on MYSQL.


define('DB_NAME', 'wp-user');
define('DB_USER', 'wp-user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'xxx.xxx.xxx.xxx:3306');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');

I've already opened ports 3306 on both servers and created a new mysql user that comes from the Apache Server address.

CREATE USER 'wp-user'@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wp-db . * TO 'wp-user'@'xxx.xxx.xxx.xxx';

both servers have the same version of MYSQL running.

I get the following error address:

Error establishing a database connection



# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
port = 3306
# skip-external-locking
# skip-networking
# bind-address

# Disabling symbolic-links is recommended to prevent assorted security risks

# Recommended in standard MySQL setup


2 Answers 2


Try to disable temporarily SELinux on the web server, with the command:

sudo setenforce 0
If the error disappears after disabling SELinux, re-enable it with:
sudo setenforce 1
and then allow httpd to connect to a MySql server through the network with:
sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_can_network_connect 1

  • It didn't work, i added sudo setsebool -P httpd_can_network_connect_db 1 to both already but just to be sure i disabled selinux.
    – blu
    Commented Nov 26, 2018 at 15:46
  • I have edited my answer, try to give also httpd_can_network_connect permission. Is it working with SELinux disabled ?
    – Det
    Commented Nov 26, 2018 at 15:51
  • No, it turns out the problem was with the firewall not SELinux.
    – blu
    Commented Nov 26, 2018 at 16:04
  • Agreed, but on a standard CentOS installation you have to configure the firewall to allow connections on TCP port 3306 AND configure SELinux to allow httpd to connect over the network. Leaving SELinux in permissive mode is not a good practice
    – Det
    Commented Nov 26, 2018 at 16:17
  • yes i turned SELLinux back on. thanks for your help
    – blu
    Commented Nov 26, 2018 at 16:21

running the following allowed external MYSQL connections:

sudo iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo firewall-cmd --reload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.