Why Switching Your MySQL Host to 127.0.0.1 May Break Your Joomla Website

Many Joomla administrators think that 127.0.0.1 is equivalent to localhost when it comes to MySQL connections, and they think that they can change the value of $host in their configuration.php file from localhost to 127.0.0.1 and the website will still work as it should. In reality, if they’re using cPanel, then the website will go down, and, in almost all the remaining cases, the website will slow down. Let us explain…

When you create a user in cPanel, such as myuser, cPanel automatically assigns that user to 3 hosts:

  • localhost
  • Server HostName (such as “host.itoctopus.com”)
  • Server IP (such as “173.199.145.150”)

This means that the user will be able to connect to the database only when one of the above is set as the host in the configuration.php file. If you’re the skeptical type and want proof, then try the following:

  • ssh to the WHM server as root.
  • Type in mysql.

  • Type in the following query:

    SELECT User, Host FROM mysql.user;

Once you do the above, you will see a list of all the MySQL users, along with their “Host”, on your database server, and you will notice that each user is added 3 times, once for every host. You will also notice that (with one exception, where “root” is the user) 127.0.0.1 doesn’t exist anywhere in the resultset of the query, which means that you can’t use 127.0.0.1 as your host and expect it to work.

Of course, the above mainly applies to a cPanel/WHM environment. If you’re using a more manual environment, or if you’re using root to connect to the database (which is never a good idea), then you may be able to use 127.0.0.1 as the host. However, the problem with doing that (in the absolute majority of cases), is that any communication with the database server will be through a TCP/IP connection, instead of a local socket. This incurs unnecessary networking overhead which will slow down your Joomla website.

We hope that you found this short post useful. If you are having problems with your Joomla website connecting to your database server, then please contact us. We are very quick to help, our work is ultra clean, and our fees are always competitive!

No comments yet.

Leave a comment