i can’t log in to mysql via pdo when i try to execute connection to db via apache but on cli it works just fine
in symfony 4.1 controller
i have inserted this string
new PDO('mysql:host=db;dbname=test_db', 'xyz', 'uzzzxxxx');
and it give Exception but on Symfony4.1 command
the same line works and i can query db.
What can cause this? Controller and command are in one bundle
3
Answers
In my case at fault was SELinux by disabling it, now it works in case someone want to check there is tutorial https://linuxize.com/post/how-to-disable-selinux-on-centos-7/
You have to give Apache enable writing to log files and file uploads as well? Let’s play nice with SELinux. And set the proper ownership and permissions
sudo chown apache:apache -R /data/www/html/sites/mysite
cd /data/www/html/sites/mysite
File permissions, recursive
find . -type f -exec chmod 0644 {} ;
Dir permissions, recursive
find . -type d -exec chmod 0755 {} ;
SELinux serve files off Apache, resursive
sudo chcon -t httpd_sys_content_t /data/www/html/sites/mysite -R
Allow write only to specific dirs
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/logs -R
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/uploads -R
That’s it! I enjoyed and you share!
I believe for Apache you are looking for localhost as your host.
While I’m unfamiliar with Symfony, it may be that either it uses different credentials or it may be that when it detects an error, it sets it to localhost, whereas Apache does not.