4

I'm having a lot of trouble with the PDO driver on this new installation

This is the error I get when trying to do any db operation triggered by laravel.

ext Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Permission denied (SQL: select * from `users` where `email` = ethan@gmail.com limit 1) in /var/www/html/mypath/vendor/laravel/framework/src/Illuminate/Database/Connection.php:647

What's really strange here, is that PDO is enabled in php, and we're using the same credentials that php artisan migrate used to create the tables (so I know credentials, mysql socket are all working)

This is the PDO error from the stack

at PDO->__construct('mysql:unix_socket=/mnt/volume_sfo2_01/mysql_data/mysqld.sock;dbname=testdb1', 'dbuser1', 'mypassword', array(0, 2, 0, false, false))
in Connector.php line 68

Note that I did move the datadirectory of mysql and thus the change for the socket. This config works running the migrate, so what am I missing to get it working with the laravel PDO driver?

On ubuntu server 16 as well. Nginx + php7.1 apparmor has been disabled additional just for this testing. Any ideas would be greatly appreciated.

ethand320
  • 145
  • 2
  • 8

1 Answers1

19

I had similar issue on Laravel/Lumen 5.5 / CentOS7 / php71 / mariaDB

using the 'setenforce to test' strategy outlined in the solution here, Permissions Issue with Laravel on CentOS you might want to test for the influence of SElinux.

I was connecting via port 3306 and was able to resolve with insight from this problem report (https://bugzilla.redhat.com/show_bug.cgi?id=1245295) that lead me to

sudo setsebool httpd_can_network_connect_db 1

to make this change permenant you need to add -P switch

sudo setsebool -P httpd_can_network_connect_db 1

Mahmoud Fayez
  • 3,398
  • 2
  • 19
  • 36
Cary Reams
  • 195
  • 1
  • 7
  • 1
    Thanks! This is working on CentOS 7 with Laravel 5.6 for me. – Isuru Ranawaka Nov 04 '19 at 09:18
  • I was getting the same error codes when my PHP code was trying to access a MySQL database over the network when accessed from the browser (not using Laravel or any framework, just a vanilla PHP site). When running a PHP script from the command line, it worked fine though. Turns out, it was this SE Linux `httpd_can_network_connect_db` variable that was the culprit. Setting it to 1 fixed everything! Thanks :) – dcsmith926 May 11 '21 at 22:26
  • Thanks, you save me. – Noe Miranda Franco Jun 09 '21 at 01:24