Page 1 of 1

I Want to Share With You How to Fix Database Error Roundcube

Posted: Mon Nov 24, 2014 3:24 am
by turkey3
So it's been three months and I finally managed to solve this error! You may have installed Vesta and noticed that going to http://mydomain/webmail leads to

Code: Select all

Database Error! Connection Failed
This is because the Vesta installation did not fully install Roundcube properly. For those of you who do not know, Roundcube is the mail server software. Apache on the other hand is the web server software. The Apache configuration file has /webmail as a symlink for all domains on the server. This means that for any domain on your server, adding /webmail will open up files in a diffeent directory specified in the Apache configuration file.

Roundcube uses a MySQL database to store users, contacts, emails, and more. Without the database, there is no possible way for Roundcube to function, resulting in the error shown above. Some Vesta installations may have left out the creation of the database used by Roundcube. This will show you how to fix it!

The first step is to open the terminal on your operating system. You will have to log into MySQL as root, which can be done via this command:

Code: Select all

mysql -u root -p
What this does is allows you to login as a superuser for MySQL and gain access to all priveleges and databases. If you have forgotten your root password, check out this on how to reset it. If on Ubuntu, I found this to be a much better guide.

After you are logged in successfully, on the left-side of the terminal will be mysql> which means you are within the MySQL shell and can now carry out commands. The first step is to create the database that was left out of the Vesta installation. This database needs the specifc name roundcube because the Roundcube software checks for a database with this exact name when it manages mail. A database with another name will not be recognized by Roundcube. Enter the following code after logged into MySQL as root:

Code: Select all

CREATE DATABASE roundcube;
Make note of the semicolon at the end, it is there to tell MySQL you are done typing the command and want it to be executed. It should tell you if the database is successfully created. If it states the database already exists, proceed to the next step as it should fix the problem for you anyway.

Now that the database is created, it needs the proper tables and columns. Rather than us doing this manually, there is a file that works perfectly for this! Go to this official webpage and download the "complete" stable package, the very first download indicated by the green button. This will take you to Sourceforge at which you can safely download the files. The files are all compressed, so once it is downloaded, simply uncompress the file either with a graphics user interface or through the terminal.

Afterwards, use ctrl-f or another search method on the newly extracted files and search for mysql.initial.sql and once you find the file, move it to a location where it is easy to find. It can be anywhere, including your very own home directory. A .sql file is simply a text file that contains a ton of MySQL commands all in one file that can be executed very quickly. This particular file creates the proper tables to be used for Roundcube.

Once the file is in a simple location, in the MySQL shell of the terminal, enter:

Code: Select all

USE roundcube;
Again, remember the semicolon. What this does is changes the database to roundcube, so all operations henceforth will be done on the roundcube database. It should print that the database was changed successfully. If not, check your spelling for any typos. Afterwards, simply perform the following code:

Code: Select all

source <pathtofile>
"source" is a static word that is used to carry out the contents of a .sql file. The path to the file should replace <pathtofile> and if everything works properly, you should see multiple instructions being printed to the screen. Everything should complete within a second, and then going to http://mysite/webmail will now show a login credentials page.

However, the process is not yet complete! Since mail accounts are made in the control panel, Vesta needs a MySQL account that will have full access to the new roundcube database so it can create new users and manage emails. Long story short, Vesta has a file at /etc/roundcube/db.inc.php that contains various configuration settings for Roundcube. Make sure you have write privileges. Search for "db_dsnw" and you should find a PHP object property being set to a value. On that same line, after the = sign, replace "password" in:

Code: Select all

mysql://roundcube:password...
With your own password. This will be the password of a MySQL database user that will have the abilities to perform all actions on the Roundcube database, including adding new users. Last step is, again in the terminal, to type the following command in the MySQL shell:

Code: Select all

GRANT ALL PRIVILEGES ON roundcube.* TO roundcube@localhost IDENTIFIED BY 'password';
Replace "password" with the exact password you used in the db.inc.php in the previous step. What this code does is grants all priveleges to a user by the name of roundcube with full access to the database roundcube. The MySQL user roundcube is created on the spot. To make this change go into effect, perform the following code in the MySQL shell:

Code: Select all

FLUSH PRIVILEGES;
Next, we need to restart MySQL. Type "quit" to exit the MySQL shell and go back to the normal terminal commands. Then enter the following:

Code: Select all

sudo /etc/init.d/mysql restart
Which will restart MySQL. Now the newly created database can be fully managed by the MySQL user roundcube and mail domains can be created dynamically from the control panel. Any questions please ask!

Re: I Want to Share With You How to Fix Database Error Round

Posted: Mon Nov 24, 2014 9:20 am
by sim
CREATE DATABASE roundecube;
Should be roundcube

Re: I Want to Share With You How to Fix Database Error Roundcube

Posted: Thu Sep 01, 2016 6:53 am
by skurudo
Main topic about Rouncude "DATABASE ERROR: CONNECTION FAILED!":
viewtopic.php?f=12&t=7065