How can i set up my drupal database correctely?

1k views Asked by At

I guys I'm getting an error while I'm trying to set up my drupal database. the drupal give me this error when i insert the database info, but I'm sure the database info is correct.

Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Form\FormValidator->doValidateForm() (line 261 of core/lib/Drupal/Core/Form/FormValidator.php). Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'install_settings_form') Drupal\Core\Form\FormValidator->validateForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->processForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->buildForm('install_settings_form', Object) install_get_form('Drupal\Core\Installer\Form\SiteSettingsForm', Array) install_run_task(Array, Array) install_run_tasks(Array) install_drupal(Object) Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Form\FormValidator->doValidateForm() (line 261 of core/lib/Drupal/Core/Form/FormValidator.php). Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'install_settings_form') Drupal\Core\Form\FormValidator->validateForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->processForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->buildForm('install_settings_form', Object) install_get_form('Drupal\Core\Installer\Form\SiteSettingsForm', Array) install_run_task(Array, Array) install_run_tasks(Array) install_drupal(Object) Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Form\FormValidator->doValidateForm() (line 261 of core/lib/Drupal/Core/Form/FormValidator.php). Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'install_settings_form') Drupal\Core\Form\FormValidator->validateForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->processForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->buildForm('install_settings_form', Object) install_get_form('Drupal\Core\Installer\Form\SiteSettingsForm', Array) install_run_task(Array, Array) install_run_tasks(Array) install_drupal(Object) Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Form\FormValidator->doValidateForm() (line 261 of core/lib/Drupal/Core/Form/FormValidator.php). Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'install_settings_form') Drupal\Core\Form\FormValidator->validateForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->processForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->buildForm('install_settings_form', Object) install_get_form('Drupal\Core\Installer\Form\SiteSettingsForm', Array) install_run_task(Array, Array) install_run_tasks(Array) install_drupal(Object) Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Form\FormValidator->doValidateForm() (line 261 of core/lib/Drupal/Core/Form/FormValidator.php). Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'install_settings_form') Drupal\Core\Form\FormValidator->validateForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->processForm('install_settings_form', Array, Object) Drupal\Core\Form\FormBuilder->buildForm('install_settings_form', Object) install_get_form('Drupal\Core\Installer\Form\SiteSettingsForm', Array) install_run_task(Array, Array) install_run_tasks(Array) install_drupal(Object) Resolve all issues below to continue the installation. For help configuring your database server, see the installation handbook, or contact your hosting provider. Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] Permission denied. Is the database server running? Does the database exist or does the database user have sufficient privileges to create the database? Have you entered the correct database name? Have you entered the correct username and password? Have you entered the correct database hostname?

I'm trying to set up my database on drupal

1

There are 1 answers

1
AndreC23 On

How to set-up a Drupal database:

Using the installation wizard

Once Drupal has been installed on your machine (via composer, for example) you will arrive at the Database set-up page where you will enter the host, DB name, user and password. Drupal will automatically create the DB connection string in the settings.php file in the web/sites/default folder.

Installing a project "manually"

once you have downloaded the project with composer, you have to edit the settings.php file in the folder web/sites/default. The changes to be made are to the entries:

  1. $settings['hash_salt'] by setting random a salt string
  2. $settings['config_sync_directory'] passing the path to the custom folder that will contain the configs to be managed with cex/cim (or other config sync procedures).

You then need to set up the database connection string (always in the settings.php file):

$databases['default']['default'] = array (
  'database' => 'database_name',
  'username' => 'database_username',
  'password' => 'database_password',
  'prefix' => '',
  'host' => 'database_host',
  'port' => 'database_port',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

I recommend installing Drush (https://www.drush.org/latest) and once the database is set up, run a ./vendor/bin/drush status from the project root to check the status of the database connection.

If you already have a database to import, once it has been set up as above, again using Drush, you can use the command ./vendor/bin/drush sql-cli < your_dababase.sql (again from the project root) to import your database into the project.

Reading your error it seems that you have not provided the correct host in the configurations (or you have the wrong username or password) or mysql/mariadb is not running correctly on the host you have set up.