I'm trying to connect InvoiceNinja to my MariaDB database using SSL.
The client server (InvoiceNinja) can connect to the database server via command line without an issue:
mysql -u Username -h Hostname -p
When I use the InvoiceNinja GUI via /setup, I am able to test the database connection okay, but after submitting the page, I end up in a setup loop.
Enabling the debug to true, outputs this:
[2022-07-23 22:34:41] production.INFO: account table not found
[2022-07-23 22:35:25] production.INFO: The command "mysql --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --database="${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"" failed.
Exit Code: 1(General error)
Working directory: /var/www/ninja/public
Output:
================
Error Output:
================
ERROR 2026 (HY000): SSL connection error: Permission denied
I edited the config/database.php file to include the following under 'mysql':
'options' => [
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => true,
PDO::MYSQL_ATTR_SSL_KEY => '/var/www/ninja/db-certs/ninja.key',
PDO::MYSQL_ATTR_SSL_CERT => '/var/www/ninja/db-certs/ninja.pem',
PDO::MYSQL_ATTR_SSL_CA => '/var/www/ninja/db-certs/ca.pem',
],
I've also ran:
php artisan optimize
After removing the entire ninja directory and downloading a fresh file, everything worked. Its possible that previous attempts started to load data and could not be overwritten. I'm not 100% sure, but everything I had configured was correct.
Hope this helps someone.
Related
How would I connect to my VPS based MySQL database remotely (from a cloud based app) using the Ruby Net::SSH or Net::SSH::Gateway gems and key, not password, authentication?
And then connect to the database with Sequel or DataMapper. I'm assuming that after I manage to get the SSH connection working, I would just setup a Sequel/DM connection to 'sql_user#localhost:3306/database'.
I did locate a couple of similar question here, but they all use password authentication, not keys, and only demonstrate executing raw commands to query the database.
UPDATE: I just cannot seem to get this (Net::SSH with key manager) to work.
UPDATE2: Alright I have managed to get authorization when logging in from a computer that has authorized keys stored in the users local .ssh folder, with the following (port is my custom SQL port on the VPS):
sql_gate = Net::SSH::Gateway.new('192.xxx.xxx.xx','sqluser', port: 26000)
However, I will not be able to create a .ssh folder in the app's VM, so I need to somehow pass the path and filename (I will be creating a public key just for SQL access for specified user) as an option ... but haven't been able to figure out how.
UPDATE: Just need to figure out DataMapper access now. Current code being tested (remote_user_sql is my Ubuntu user, sql_user is the MySQL database user with localhost/127.0.0.1 privileges):
require 'net/ssh/gateway'
require 'data_mapper'
require 'dm-mysql-adapter'
class User
include DataMapp......
.
.
end
ssh_gate = Net::SSH::Gateway.new('192.n.n.n','remote_user_sql', {port: 25000, keys: ["sql_rsa"], keys_only: true})
port = ssh_gate.open('localhost',3306,3307)
child = fork do
DataMapper.setup(:default, {
adapter: 'mysql',
database: 'sql_test',
username: 'sql_user',
password: 'passwd',
host: 'localhost',
port: port})
DataMapper.auto_upgrade!
exit
end
puts "child: #{child}"
Process.wait
ssh_gate.close(port)
My solution, in two parts:
Well I have figured how to make the Net::SSH::Gateway gem using a specified keyfile, and then connect to the VPS through ssh via a port other than 22:
Part 1: Net::SSH::Gateway key authentication
First you must generate the keyfiles you want to use, copy the .pub to the remove server and append it to the ~/.ssh/authorized_keys file (cat sql_rsa.pub >> authorized_keys), and then make sure user_sql (the user I created on the VPS to be used only for this purpose) has been added to AllowUsers list in sshd_config. Make note of port used for ssh (25000 for this example) and use the following code to establish the connection:
ssh_gate = Net::SSH::Gateway.new('192.n.n.n','user_sql', {port: 25000, keys: ["sql_rsa"], keys_only: true})
That will read the keyfile sql_rsa in the same directory as script file, then create a new ssh gateway for 'user_sql'#'192.n.n.n' on port 25000.
I can successfully execute raw shell commands on the remove VPS with:
ssh_gate.exec("ls -la")
To close:
ssh_gate.shutdown!
Unfortunately I am still having problems using DataMapper (do-mysql-adapter) to use the gateway. I will update this answer if I figure that part out, but at least the first half of the problem has been solved.
These are the errors that DataMapper::Logger has reported:
When 127.0.0.1 was used:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (code: 2002, sql state: HY000, query: , uri: )
When localhost was used:
Access denied for user 'user_sql'#'localhost' (using password: YES) (code: 1045, sql state: 28000, query: , uri: )
When the VPS hostname was used:
Unknown MySQL server host 'hostname' (25) (code: 2005, sql state: HY000, query: , uri: )
UPDATE (No success yet): So far the only way I can access the remote MySQL database is by using Net::SSH::Gateway to establish a gateway, and then use the .sshmethod to open a new Net::SSH connection over that gateway, like so:
ssh_gate.ssh('192.n.n.n','user_sql',{port: 25000, keys: ["sql_rsa"], keys_only: true}) do |ssh|
ssh.exec("mysql -u sql_user -p'passwd' -h localhost -P 3306 -e 'SELECT DATABASE();'")
end
In other words, I can only execute SQL commands using the mysql command line. I cannot figure out how to get Sequel or DataMapper to use the gateway to connect.
Part 2: DataMapper/Sequel/mysql2 connection through Net::SSH::Gateway
Make sure your MySQL server is bound to 127.0.0.1 in /etc/mysql/my.cnf, setup your connection - DataMapper example:
DataMapper.setup(:default, {
adapter: 'mysql',
database: 'DATABASE',
username: 'username',
password: 'passwd',
host: '127.0.0.1',
port: 3307}) # local port being forwarded via Net::SSH:Gateway
Followed by any class table definitions and DataMapper.finalize if required. Note that DataMapper doesn't actually connect to the remote MySQL server until either an auto_upgrade!, auto_migrate!, or query is executed, so no need to create the forwarded port yet.
Then create a new Net::SSH::Gateway, and then whenever you need DataMapper/Sequel to access the remote database, just open a port for the process, like so:
port = ssh_gate.open('127.0.0.1',3306,3307)
child = fork do
DataMapper.auto_upgrade! # DM call that accesses MySQL server
exit
end
Process.wait
ssh_gate.close(port)
You may want to put the Net::SSH::Gateway/.open code in a begin..ensure..end block, ensure'ing the port closure and gateway shutdown.
I had to use a fork and Process.wait to establish the connection, without it the method just hangs.
I´m trying to install Silverstripe on a Server with the MySQL Connection Details like following:
Hostname localhost:/tmp/mysql5.sock
Socket /tmp/mysql5.sock
Entering one of these addresses in the Install Form for Database server brings up following error on submit for localhost:/tmp/mysql5.sock:
I couldn't find a database server on 'localhost:/tmp/mysql5.sock': Connection refused"
or for /tmp/mysql5.sock
I couldn't find a database server on '/tmp/mysql5.sock': php_network_getaddresses: getaddrinfo failed: Name or service not known
and just localhost shows this error:
I couldn't find a database server on 'localhost': Connecting to 3.22, 3.23 & 4.0 servers is not supported
Thanks,
Florian
Basically, there was something wrong with the server settings:
This is what I added to _config.php:
ini_set('mysqli.default_socket', '/tmp/mysql5.sock');
then the db connection looked like this:
$databaseConfig = array(
"type" => 'MySQLDatabase',
"server" => 'localhost',
"username" => 'myusername',
"password" => 'mypassword',
"database" => 'mydb',
"path" => '/tmp/mysql5.sock',
);
I have never tried to connect to a mysql server this way.
But maybe the installer fails to recognize a hostname like this, you could try to just write the _config.php file by hand and then run a /dev/build, maybe that works.
about:
I couldn't find a database server on 'localhost': Connecting to 3.22, 3.23 & 4.0 servers is not supported
SilverStripe requires a mysql database version 5, could it be that your mysql server is not up2date?
In setting up SilverStripe and MariaDB on a Mac (Mountain Lion), all that was necessary was to put this into the _ss_environment.php file:
define('SS_DATABASE_SERVER', 'localhost:/opt/local/var/run/mariadb/mysqld.sock');
It was not necessary to change the value of 'mysqli.default_socket'.
I'm trying to get a crontab working for Cakephp (running on my shared Dreamhost server for now).
I have a shell set up as per the book, which works fine via either a cron run or manually executing (both via a shell file, e.g:
cron.sh
#########
cd /pathToApp/app/Console
/usr/local/bin/php cake.php updater list_reports
where updater is my shell and list_reports a method thereof.
The problem occurs when I try to access the database in the shell ("Using models in your shell", same link).
Error Message:
Error: Database connection "SQLSTATE[HY000] [2002] Can't connect to
local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"
is missing, or could not be created.
My DB Set-up (site works fine for http, do I need to add unix_socket or something?
array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'mysql.mydomain.net',
'port' => '3306',
'login' => '*******',
'password' => '*******',
'database' => '*******',
'prefix' => '',
);
Thing I've tried:
Creating a symlink to /var/run/mysqld/mysqld.sock - permission denied
Can I even do this with shared hosting?
Tried various changes to the db settings above, no luck.
I note similar problems have been solved by people replacing localhost with 127.0.0.1, but I'm using a shared host, not local.
It's official! I'm a db!
I can confirm this problem was not caused by either Cakephp or Mysql, but rather for something I'd done myself and forgot about....
I had a little switch in database.php to automatically detect whether I was in the dev, test, staging environment etc. I had the default set to local, and since the bash script didn't pick up $_SERVER['SERVER_NAME'] which I was using for the switch, it defaulted to my local db.
Thanks to ifunk for spotting the clue which enabled me to unravel this and get back on track!
:)
Trying to install my first drupal module. Following the book did not work because of an "FTP" error so I installed drush. Download seemed to work now the enable command gives me this error. I'm a noob with ubuntu and every part of drupal. Help. Thanks.
NNH#comp:/var/www/drupal$ sudo drush en module_filter
Command pm-enable needs a higher bootstrap level to run - you will [error]
need invoke drush from a more functional Drupal environment to run
this command.
The drush command 'en module_filter' could not be executed. [error]
Drush was not able to start (bootstrap) the Drupal database. [error]
Hint: This error often occurs when Drush is trying to bootstrap a
site that has not been installed or does not have a configured
database.and tried it.
Drush was attempting to connect to :
Drupal version : 7.14
Site URI : http: //default
Database driver : mysql
Database hostname : localhost
Database username : drupal7
Database name : drupal7
Default theme : garland
Administration theme: garland
PHP configuration :
Drush version : 5.3
Drush configuration:
Drupal root : /var/www/drupal
Site path : sites/default
Modules path : sites/all/modules
Themes path : sites/all/themes
File directory path: sites/default/files
%paths : Array
You can select another site with a working database setup by
specifying the URI to use with the --uri parameter on the command
line or $options['uri'] in your drushrc.php file.
Possibly related:
NNH#comp:~$ sudo dpkg-reconfigure -plow phpmyadmin
[sudo] password for NNH:
/usr/sbin/dpkg-reconfigure: phpmyadmin is broken or not fully installed
Drush is basically a command-line interface to interact, manage and configure Drupal and its modules. So if you like to use Drush for any operations pertaining database, you have to go through loop address ie., localhost. But it seems like Drush understands 127.0.0.1 as loop address but not localhost.
Simply by defining these in settings.php you are allowing the Drush to proceed with any database related operations.
Instead of just this
'host' => 'localhost',
use this,
'host' => php_sapi_name() == 'cli' ? '127.0.0.1' : 'localhost',
You typically recieve the error
Command pm-enable needs a higher bootstrap level to run - you will
[error] need invoke drush from a more functional Drupal environment to
run this command.
when you aren't in the root of the site when running the command.
If the error persist try connecting to MySQL straight from the prompt. Try connecting using the values from the Drush output, ie:
mysql -hlocalhost -udrupal7 -p drupal7
If it is working and the site is working then you most likely can rule out database connection problem. Assuming you are developing locally on your own box, you can try changing localhost to 127.0.0.1 in settings.php. This seem to have helped some people.
The site URI setting seems a bit odd.
This is my first time installing a framework, and I am pretty clueless.
I am on OSX 10.7 and I have the cakephp framework loaded into /Library/WebServer/Documents/cakephp and I have been able to load the test page and get rid of some of the errors and warnings. Right now I am trying to resolve this
Warning (2): PDO::__construct() [pdo.--construct]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) [CORE/Cake/Model/Datasource/Database/Mysql.php, line 160]
Cake is NOT able to connect to the database.
Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.
I don't really know what to do here. I have installed MySQL. Does the MySQL PDO come installed on OSX by default? or do I need to install that? How can I check if that is installed if that seems to be the problem.
UPDATE:
The PDO Mysql driver is enabled.
Also the phpinfo() for pro_mysql looks like this:
Directive Local Value Master Value
pdo_mysql.default_socket /var/mysql/mysql.sock /var/mysql/mysql.sock
However the mysql directory doesn't appear in my filesystem. should I create it? or do I nee to change this path somewhere?
UPDATE:
I think the problem is that I haven't actually set up a database. kindof dumb of me not to set up the database.
I guess I will try to figure that out now.
UPDATE:
The thing that finally solved this was that cake was looking for the Unix socket to the database in /var/mysql/mysql.sock but mysql was using the socket in /tmp/mysql.sock
I fixed this by creating a symbolic link from the /var/mysql/mysql.sock to /tmp/mysql.sock.
It looks more like MySQL itself is not installed, but the PDO libraries are compiled with your webserver. I am not sure how to check this in OSX, but you can try checkign this link out: http://www.sequelpro.com/docs/Install_MySQL_on_Mac_OS_X
EDIT
Log into MySQL (mysql -u root -p) and create the databas:
create database cakephp
Then create a new username/password and grant them access to this database. Let's say you want to create the username cakephp and the password cakepass:
GRANT ALL ON cakephp.* TO cakephp#localhost IDENTIFIED BY 'cakepass';
FLUSH PRIVILEGES;
And now your database.php config file should look like this:
<?php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakephp',
'password' => 'cakepass',
'database' => 'cakephp',
'prefix' => ''
);
}
No, MySQL does not come with OSX, you'll have to install it.
The easiest solution is to use XAMPP instead of compiling/installing MySQL yourself. It will also come with a separate Apache and PHP, if you don't want to mess with the native OSX versions.