This is not about 'localhost'. Both the command line version of 'mysql' as well as a script I wrote in Perl (using perl-DBD-MySQL) can login, get to this database and work with it. Only PHP gives the permission denied error, and that error is not reported in any of the various log files. I even went as far as creating a simple test user in the database to avoid any issues with special characters in the password:
create user 'web'#'%' identified by 'Iamnotarobot';
and again the command line can login with this credential but PHP says permission denied.
I don't know what is throwing the error so I can't address it. I'm literally lost.
Relevant info:
RHEL 8 = 4.18.0
php 7.2.11
nginx 1.14.1
And here's the actual code that's failing:
<?php
$host="core";
$user="web";
$pass="Iamnotarobot";
$db="mydb";
$conn = new mysqli($host,$user,$pass,$db);
if( $conn->connect_errno ) {
exit($conn->connect_errno);
}
?>
It turned out to be an selinux issue. Here's how I fixed it:
setsebool -P httpd_can_network_connect_db 1
Now with setenforce back to '1', the page can connect to the database.
Check with php-mysql package installation.
If perl can connect remotely and php could not...the issue is with php-mysql installation only.
Related
I'm trying to get Emoncms working on a shared hosting MediaTemple web server with verified prerequisites like mod_rewrite and LAMP server. I've created the database with user and password, configured the settings.php to the best of my ability.
/ - this is root
/emoncmsdata - Its 777 for data folders /phpfina & /phpfiwa & /phptimeseries
/httpdocs - this is my public folder
/httpdocs/emoncms - this is where the settings.php is and where modules are
But when I access santiapps.com/emoncms/ I get:
Can’t connect to database, please verify credentials/configuration in settings.php
Error message: Access denied for user ‘marskoko’#‘localhost’ (using password: NO).
I've put the database, user and password in the script. I've checked it and reset the password through their plesk.
I know the password for that user is correct because I can log in with the password just fine via terminal using mysql -u user -p pass and I get the MariaDB server and I can then enter USE Emoncms and the prompt reads that I'm connected to Emoncms.
The emoncms.log file created by the application is empty. I found a bunch of these in the web server error.log:
[Fri Sep 28 20:53:23.620729 2018] [proxy_fcgi:error] [pid 8219:tid 140039956670208] [client 83.139.179.122:35214] AH01071: Got error ‘Primary script unknown\n’
I've checked most of the posts in SO about this user password:NO issue and they all pertain to root, which I am not. I'm using another user called marskoko.
Access denied for user 'root'#'localhost' (using password: NO)?Unable to authenticate php/Mysql?
I can't stop or start the server, I've tried service mysql stop and I get:
Redirecting to /bin/systemctl stop mysql.service
Failed to stop mysql.service: Unit mysql.service not loaded.
4.a) I have recently been suggested to try:
service mysqld restart
But I get a similar error:
Redirecting to /bin/systemctl restart mysqld.service
Failed to restart mysqld.service: Unit not found.
But I know its running, otherwise I wouldn't be able to view my other databases.
I've created this php file:
<?php
$db = mysqli_connect("localhost","marskoko","myPasshasAdollarSign") or die("Failed to open connection to MySQL server.");
mysqli_select_db($db, "emoncms") or die("Unable to select database");
\>
and ran it and I get this:
Failed to open connection to MySQL server.
5.a) When I use mysqli_connect_error() I get:
Access denied for user 'emonuser'#'localhost' (using password: NO)
NOTE: The user is different because I wanted to make sure there wasn't some issue with the db or user, so I deleted the db and re-created it and changed the username. The db is still there and I can still access it via MariaDB using mysql command and the same password.
I tried this suggestion:
ps aux | grep mysql
and I get this:
mysql 7766 0.0 0.0 113200 1588 ? Ss Sep28 0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 8286 0.7 5.4 1906888 457400 ? Sl Sep28 5:12 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/lib/mysql/activacorp.net.err --pid-file=activacorp.net.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 15702 0.0 0.0 112600 1068 pts/0 S+ 09:17 0:00 grep --color=auto mysql
I just tried logging into the db with the user/pass and I tried getting the table of users but got this:
MariaDB [emoncms]> select * from user;
ERROR 1146 (42S02): Table 'emoncms.user' doesn't exist
Then again I just checked all my databases and neither have the users table in it. They have other tables which Ive added and work with, but not the user table. Maybe phpmyadmin hides that, I dunno.
I dunno what else to try.
i think you can resolve this by the steps following
start/stop mysql by using service mysqld start/stop/restart instead of service mysql start/stop/restart
make sure you got the right password for mysql user - root, if no, please reset password by following step 3, else, skip step 3
edit mysql config file, usually /etc/my.cny, add skip-grant-tables under [mysqld], then restart mysql, now you can go into mysql without password, then reset password by using
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
flush privileges;
that is all, please check it
Ok I figured it out. Digging around the php I tried logging the $password variable in the index.php of emoncms and it logged blank whilst the username, database or other variables logged correctly. I ended up replacing the $password for the actual password in the mysqli line and it works now. So then I just replaced the $password "" for '' and it works now.
I have this simple php script:
<?php
$c = new mysqli("localhost", 'root', '');
echo($c->connect_error);
?>
My mysql credentials are correct but when I run the php script, it prints this error: Access denied for user 'root'#'localhost'.
I started mysql and apache services using service mysql start and service apache2 start. When I type mysql -u root -h localhost on terminal, all goes well but not my script. I tried using laravel but still getting the same error. What am I doing wrong? Please help.
Regards
I got a solution by running update user set plugin='mysql_native_password' where user='root';
The plugin was unix_socket before I did an update.
Using the following bits:
<?php
require('vendor/autoload.php');
$client = new Everyman\Neo4j\Client('localhost', 7474);
print_r($client->getServerInfo());
?>
If I run this as php test.php I get the expected output.
If I run this via http://server/test.php I get connection errors.
[24-Jun-2014 05:49:52] PHP Fatal error: Uncaught exception 'Everyman\Neo4j\Exception'
with message 'Can't open connection to http://localhost:7474/db/data/' in
/var/www/html/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Transport/Curl.php:91
Clearly I've monkeyed up something with either my PHP config or the installation of this library. Suggestions on where to look?
Installed per these instructions.
Running on CentOS 6.4 (x64), PHP 5.3.3
NOTE: I've made successful connections from other machines back to this server so I know the neo4j server is working. It just doesn't seem to want to let me connect locally when called via browser.
I had same issue, it was caused by SeLinux
Try disabling it by:
echo 0 >/selinux/enforce
then recheck connection.
If solved configure SeLinux permissions.
In my case httpd_can_network_connect should be on
setsebool -P httpd_can_network_connect on
echo 1 >/selinux/enforce
Helpful manual:
http://wiki.centos.org/TipsAndTricks/SelinuxBooleans
I'm trying to connect to an AWS MySQL server from my VPS, but no matter what I try, I just get access denied, my user has privileges to connect from any host.
If I try to connect via PHP:
$db = new mysqli('mysite.cufncdsjslka.us-east-1.rds.amazonaws.com', 'my_user', 'my_pass', 'my_db');
Gives me: Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'my_user'#'XXXX.myhost.com' (using password: YES) in /home/me/shopify/libraries/db.lib.php on line 4
If I try to connect via the MySQL CLI:
mysql -h mysite.cufncdsjslka.us-east-1.rds.amazonaws.com -umy_user -p
Gives me:
ERROR 1045 (28000): Access denied for user 'my_user'#'xxxx.myhost.com' (using password: YES)
This command works flawlessly on my PC, but not on my VPS.
I'm assuming it's some sort of security setting preventing MySQL from using external servers?
My VPS is running Debian squeeze with the LAMP components all from the standard Debian packages except for PHP which I manually updated to 5.4.
I'm posting this as a new question since most similar questions I've found on SO were a permissions issue (I've given my MySQL user priveliges to connect from any host) or a SELinux issue (which AFAIK doesn't apply to Debian)
OK.
I have seen this problem number of times for many different reasons. Since I cannot see your server or your logs so I am guessing from the information that there could be bind address issue.
In my.cnf check
bind-address=YOUR-SERVER-IP
change it to the the ipaddress of your mysql server for example 81.92.33.45
restart mysql after this. And if you are still unable to connect then let me know with the error info from log and I will look again.
Secondly make sure iptables are not causing problems.
iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
my cassandra is working well in CLI. and thrift also installed well. i already started apache server and cassandara..but when trying to execute php file that is not executed on browser.it shows the error as:
TException: Error: TSocket: Could not connect to localhost:9160 (Permission denied [13])
and the 12th and 13th line is:
$socket = new TSocket('localhost', 9160);
$transport = new TBufferedTransport($socket, 1024, 1024);
i gave 127.0.0.1 instead of localhost.even it is not working.
can any one please help me?
hi every one i solve the problem....
selinux is cause for that problem.....
TException: Error: TSocket: Could not connect to localhost:9160 (Permission denied [13])
To resolve it, you need to change an SELinux boolean value (which will automatically persist across reboots). You may also want to restart httpd to reset the proxy worker, although this isn't strictly required.
setsebool -P httpd_can_network_connect 1
http://wiki.apache.org/httpd/13PermissionDenied