My colleague changed a cPanel password for a Drupal site. The front-end is now displaying the following error.
Error
The website encountered an unexpected error. Please try again later.
Error message PDOException: SQLSTATE[HY000] [1045] Access denied for user 'xx'#'localhost' (using password: YES) in lock_may_be_available() (line 167 of /home/xx/public_html/includes/lock.inc).
How do I fix this error?
If only a password was changed, and you get that error, it means the password to access the database that Drupal knows needs to be changed too. By default, that is stored in the sites/default/settings.php file. Look for code similar to the following, in that file.
$databases['default']['default'] = array(
'database' => 'databasename',
'username' => 'sqlusername',
'password' => 'sqlpassword',
'host' => 'localhost',
'port' => '3306',
'driver' => 'mysql',
'prefix' => '',
'collation' => 'utf8mb4_general_ci',
);
The most important part are the first three lines, in particular what follows password =>, which should be the actual password. (databasename, sqlusername, and sqlpassword are placeholders for the real values.)
Since Drupal can use different settings.php files, check there aren't other files with that filename in the sites directory. For example, if Drupal is installed on https://www.drupal.org:8080/mysite/test/, the settings.php file is searched in the following directories.
sites/8080.www.drupal.org.mysite.test
sites/www.drupal.org.mysite.test
sites/drupal.org.mysite.test
sites/org.mysite.test
sites/8080.www.drupal.org.mysite
sites/www.drupal.org.mysite
sites/drupal.org.mysite
sites/org.mysite
sites/8080.www.drupal.org
sites/www.drupal.org
sites/drupal.org
sites/org
sites/default
Then, the content of the sites/sites.php file can change which settings.php file is used. For example, with the following sites.php file, the sites/example.com/settings.php file is used for the domains example.org, example.it, and example.com.
$sites['example.org'] = 'example.com';
$sites['example.it'] = 'example.com';
$sites['example.com'] = 'example.com';
Related
When uninstall module then why delete all table from database without module_uninstall() function in .install file.
Also, why create table without module_install() function
.install file code is only:
function commerce_quickpay_schema() {
$schema['webc_crypto_meta'] = [
'description' => 'Custom Cryptography Meta',
'fields' => [...],
'primary key' => ['wcm_id'],
];
$schema['webc_crypto_payment'] = [
'description' => 'Custom Cryptography Payment',
'fields' => [...],
'primary key' => ['wcp_id'],
];
return $schema;
}
Also, please, CREATE TABLE IF NOT EXISTS condition in .install file.
This is how it behaves, the tables defined in hook_schema will be created or removed from the database when the module is installed or uninstalled, the hook_install() or hook_uninstall() hooks should be used when you want to do something extra.
It is simply assumed that the database schema should be removed when a module is uninstalled and come back when installed, if you think about it, it makes perfect sense.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21database.api.php/function/hook_schema/8.7.x
"The tables declared by this hook will be automatically created when
the module is installed, and removed when the module is uninstalled.
This happens before hook_install() is invoked, and after
hook_uninstall() is invoked, respectively."
I have puppet code for nginx.conf .
The file is created by source => puppet://path to file which contain the required file contents.
I don't want to disturb this file because it is for default setting.
I have to append this nginx.conf file which can be deployed on
specific node where it is required.
So I have written the separate module which is responsible for new changes.
But this module is dependent on previous module which contain the nginx.conf file.
if ! defined(File['/etc/nginx/nginx.conf']) {
file { '/etc/nginx/nginx.conf' :
ensure => present,
owner => root,
group => root,
mode => '0644',
source => 'puppet:///modules/path/to/file/nginx_default.conf',
require => Package[ 'nginx' ],
notify => Service[ 'nginx'],
}
}
How could I append the nginx.conf file without disturbing above code?
I would recommend using Nginx modules from Puppet Forge the main benefit of the modules is that you don't have to reinvent the wheel, you can reuse the modules or adapt them to your needs.
This will still allow you to have a default nginx.conf (as a template) and by using classes you would be able to repurpose the nginx.conf template to your liking.
i.e:
host_1.pp:
class { 'nginx':
# Fix for "upstream sent too big header ..." errors
fastcgi_buffers => '8 8k',
fastcgi_buffer_size => '8k',
ssl_ciphers => 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256',
upstream => {
fpmbackend => 'server unix:/var/run/php-fpm-www.sock',
},
}
host_2.pp:
class { 'nginx':
# Fix for "upstream sent too big header ..." errors
fastcgi_buffers => '8 8k',
fastcgi_buffer_size => '36k',
upstream => {
fpmbackend => 'server unix:/var/run/php-fpm-host2.sock',
},
}
However if you still want to use your modules you can setup the nginx.conf as a template and have it populated with variables of you choosing based on the environment/host of your choosing.
This will make the least changes to your code.
Although IMO in the long run using correct community modules will pay off better for you and our team.
I did use the exec to append the file, as there were many restrictions to try other ways like adding any new module.
I have created one file containing appending lines and then removed it.
include existing::module
if ! defined (File["/new/path/for/temp/file/nginx_append.conf"])
file{"/new/path/for/temp/file/nginx_append.conf":
ensure => present,
mode => 755,
owner => 'root',
group => 'root',
source => 'puppet:///modules/module-name/nginx_append.conf',
}
}
exec {"nginx.conf":
cwd => '/new/path/for/tenter code hereemp/file',
command => "/bin/cat /new/path/for/temp/file/nginx_append.conf >> /etc/nginx/nginx.conf && rm /new/path/for/temp/file/nginx_append.conf",
require => [ Service["nginx"]],
}
Thanks MichalT for your support...
By default the error mail only takes these server variables from log.php:
protected static $log_globals = array(
'_SERVER' => array(
'HTTP_ACCEPT',
'HTTP_ACCEPT_CHARSET',
'HTTP_ACCEPT_ENCODING',
'HTTP_ACCEPT_LANGUAGE',
'HTTP_REFERRER',
'HTTP_USER_AGENT',
'HTTPS',
'REMOTE_ADDR',
),
);
How do I add 'HTTP_X_FORWARDED_FOR' to my error e-mails without modifying the core files?
This is actually possible via the new configuration system in Silverstripe. Have a YAML config file with the following:
SS_Log:
log_globals:
'_SERVER':
- 'HTTP_X_FORWARDED_FOR'
This adds HTTP_X_FORWARDED_FOR to the _SERVER array on the log_globals static variable.
Trying to use sqlite in development environment. It seems to detect the environment correctly but when I try to migrate to development.sqlite I get exception thrown "database does not exist"
artisan command
php artisan migrate --env=development
bootstrap/start.php
$env = $app->detectEnvironment(array(
'development' => array('localhost'),
));
app/config/development/database.php
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/development.sqlite',
'prefix' => '',
)
)
);
As far as I know laravel is supposed to create the file if it does not exist but since it didn't I tried manually creating the file and still get the exception thrown.
UPDATE: Maybe something not right with the env because the same thing happens if I try ':memory' for the database.
UPDATE 2: I tried running the sample unit test but add to TestCase.php
/**
* Default preparation for each test
*
*/
public function setUp()
{
parent::setUp(); // Don't forget this!
$this->prepareForTests();
}
/**
* Creates the application.
*
* #return Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}
/**
* Migrates the database and set the mailer to 'pretend'.
* This will cause the tests to run quickly.
*
*/
private function prepareForTests()
{
Artisan::call('migrate');
Mail::pretend(true);
}
And this too gives the same exception though the testing env is already shipped with laravel. So I'll see if I can find any new issues on that.
Wow, typos and wrong paths.
Copying the sqlite array from config/database.php into config/development/database.php I forgot to change the path to the development.sqlite file from
__DIR__.'/../database/development.sqlite'
to
__DIR__.'/../../database/development.sqlite'
And for the in memory test it should have been
':memory:'
instead of
':memory'
I noticed that my database.php file had the following
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
I changed it to read the following, and it worked just fine.
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
One of the problem which I faced was I use "touch storage/database.sqlite" in terminal, so database is created in Storage folder instead of database folder.
in my config/database.php path is database_path('database.sqlite')
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
than I use command "php artisan migrate" which gave me error "Database (/Applications/MAMP/htdocs/FOLDER_NAME/database/database.sqlite) does
not exist."
so it's obvious database file is not in database folder as It was generated in Storage folder, so copy "database.sqlite" from storage folder or run command "touch database/database.sqlite"
Hope that helps.!!
Well, my answer is kinda outdated, but anyway. I faced the same problem, but with Laravel 5, I am using Windows 7 x64. First I manually created SQLite database called 'db' and placed it into storage directory, then fixed my .env file like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=oBxQMkpqbENPb07bLccw6Xv7opAiG3Jp
DB_HOST=localhost
DB_DATABASE='db'
DB_USERNAME=''
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null`
I thought it would fix my problems, but the command line keeps telling me that database doesn't exist. And then I just checked the path to db in my database.php file and this is why I put database file into storage directory. But nothing changed. And finally I checked db's extension and it was .db, not .sqlite as default extension you see in your sqlite block in database.php. So this is how I reconfigured sqlite piece:
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/db.db',
'prefix' => '',
],
And of course don't forget to set sqlite as default database in your database.php file. Good luck!
For me it was that path to database had to be '/var/www/html' + location to the database in your project. In my case database was stored in database/db.sqlite so DB_DATABASE='/var/www/html/database/db.sqlite'
I had the same error while running a GitHub action test workflow.
For me the solution was to define the relative path to the database archive into the workflow file:
on:
...
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
jobs:
laravel-tests:
...
I think that the previous answers reduce the importance of the config and most likely the developers wanted to get the database file like this:
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => database_path(env('DB_DATABASE', 'database').'.sqlite'), // <- like this
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
Tested on Laravel 9.x
I'm working on a new website. A friend of mine configured Drupal 7 on our hosting service and we started to work. Unfortunately he forgot to add, during the setting phase, a prefix to Drupal standard tables.
Is it possible to change this configuration after having installed Drupal (in order to dont loose the work we have already done after the installation)?
I could do it via SQL code, but I guess that the platform will crash in this way because the code is generated according to the initial settings, right?
(PS: I dont have so much experience with Drupal).
Thanks!
I have similar issue, I found it is very easy to do this in phpmyadmin.
I assume your table prefix is "drupal_", and the target prefix is "new_"
step 1: login to phpmyadmin, chose your database;
step 2: under table list bottom , click "check all" checkbox;
step 3: select action "Replace table prefix";
step 4: Type "drupal_" into "From" and "new_" to "To", click "Go"
You can see the prefix was change to new_tablename
enjoy : )
oh, don't forget to change your settings.php:
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'databasename',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'prefix' => 'new_', // <-- add your prefix here
);
If you change the table names via SQL commands (add the prefix), you can set the prefix in your site's settings.php file. Assuming you have just one site, your settings.php file would be in your sites/default/ directory.
Look for your database configurations that would look something like the following and add your desired prefix:
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'databasename',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'prefix' => '', // <-- add your prefix here
);