0

I have a Linux server (Centos 7) running WordPress and another Linux server (Ubuntu) running MySQL. Communication between WordPress and the Database was working. However, after a web server reboot, I see the following message in the browser:

This site can't be reached

It was determined that Apache was not running via: ps -ef | grep http

I manually started Apache via: service httpd start

**** I do want Apache to start automatically after a server reboot ****

Now Apache returned the following message in the browser: Error establishing a database connection

After attempting to test the connecting via: mysql

Linux returned the error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

The directory, '/var/lib/mysql/', is empty. I read on the Internet, that when the MySQL service runs, it creates the socket. When exited, the socket file is removed. Not sure this is true or not.

So it appears to be a MySQL socket issue.

Looking forward to everybody's help on this...

  • If the mysql server is on a different host, then you cannot connect through a socket. Your web application may have lost its database configuration. Enabling Apache as a service is chkconfig --add httpd I think on Centos 7. Connect to a different host: mysql -h hostname -u user -p – user188737 May 10 '18 at 17:30
  • How to check if the web server lost its database configuration? – Sammy May 10 '18 at 17:32
  • Depends on the application. Often it is something like config/config.php or config/database.php etc. – user188737 May 10 '18 at 17:34
  • I have Wordpress and PHP installed. I am able to access the databse on the DB server from the Web server successfully via: mysql -u dbuser -h xxx.xxx.xxx.xxx -p – Sammy May 10 '18 at 17:41
  • Should be wp-config.php in the root of the webdirectory, right at the front. DB_USER, DB_PASSWORD, DB_HOST – user188737 May 10 '18 at 17:58
0

If you have Centos/Red Hat/Fedora/Suse, and you have things that seem to work as root or other logged in user but not from an application like a webserver, then check if your instance has selinux on with sestatus.

sestatus

SELinux status: enabled
SELinuxfs mount: /selinux
Current Mode: enforcing

If it is in mode enforcing then you can check audit logs to see if your problem is there. For example to see errors from something running in the httpd program:

ausearch -c "httpd" -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -i

And/or use:

sealert -a /var/log/audit/audit.log > /path/to/mylogfile.txt

For some common problems there exist booleans to tweak the working of the default policies. For a complete listing use getsebool -a

For httpd servers you have an option for accessing specifically some common database ports over network, httpd_can_network_connect_db and more generic full network access, httpd_can_network_connect. This applies if you use php as a module in httpd and it has to access a database over network connection.

If you wan't to change them you use setsebool -P <boolean_name_> {0|1|on|off}. Without the -P the setting will revert on reboot.

An excellent starting point if you do want to read up on selinux: https://wiki.centos.org/HowTos/SELinux

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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