Symfony2 database configuration during deployment - php

hi i'm new to symfony2 web development. I have develop a sample symfony2 application with a database on my localhost. It is working fine on my localhost.
I have uploaded my project to web server, All the files are working on the web server other than the files connecting with databases. When I requested for the files that are connected with database I got these errors.
Warning: PDO::__construct(): MySQL server has gone away in
/home/pipeline/public_html/BusinessPipeline/BusinessPipeline/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php
on line 40
Warning: PDO::__construct(): Error while reading greeting packet.
PID=18547 in
/home/pipeline/public_html/BusinessPipeline/BusinessPipeline/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php
on line 40
I have setup the parameters.yml file as follows.
# app/config/parameters.yml
parameters:
database_driver: pdo_mysql
database_host: localhost
database_name: test_project
database_user: my_username
database_password: my_password
I didn't change anything rather than change the parameters.yml.
what can I do for this issue, do I need to do any configuration prior to deployment?
Thanks in advance

Check MySQL Server doc for specific problem about your error message:
B.5.2.9 MySQL server has gone away
Check the wait_timeout problem

Related

Problems connecting to Mysql on a docker container via PDO, but command line works

A brief summary of my question:
What characteristic of my docker-compose is colliding with PDO that prevents Host -> mysql-docker via PDO, but allows Host -> mysql-docker from all other tools?
My App's config file:
database:
host: mysql
port: 3306
name: <name>
username: <username>
password: <pass>
outsideContainerConnections:
host: 127.0.0.1
port: 3307
Everything is running fine within the container, and I am able to access the database from the host using PHPStorm or Mysql on the command line.
If I run this command from the host, it connects
mysql --port=3307 -h 127.0.0.1 -u <username> -p
However, if I try to connect from php on the host, using PDO, it fails with
PDOException: SQLSTATE[HY000] [2002] Connection refused
PDO DSNs I've tried:
mysql:host=127.0.0.1:3307;port=;dbname=<name>;&charset=utf8;
or
mysql:host=127.0.0.1;port=3307;dbname=<name>;&charset=utf8;
or
mysql:host=127.0.0.1:3307;dbname=<name>;&charset=utf8;
I have read about using localhost vs 127.0.0.1 to force TCP, and I am doing that here.
Here also is the relevant section of my docker-composer. Again, using command line or other tools from the host work fine, it is only PDO that seems to have an issue. For what it's worth, PDO on another container in the docker-compose network is behaving.
mysql:
build: './mysql_docker'
command: --lower_case_table_names=0
ports:
- '3307:3306'
volumes:
- ./volumes/mysql:/var/lib/mysql
- ./volumes/my.cnf:/etc/my.cnf
networks:
- app-tier
Thank you for reading.
I've solved it– it's simple but hopefully a good lesson to pass on.
In one case the PHP file was being run by cron, and so it was being run locally, outside of the docker container. I had a small syntax or other error in my file so cron was having some trouble.
In order to debug this situation, I was opening the file in my web browser–and that's the kicker. The connection errors I saw in the web browser were not the same problems cron was having, because that page was being served by the docker container. Thus, the connection details had to be different. The same setup could not work both from the host and from the neighbor container.
What I learned is this; what seems like a really heady technical problem that requires lots of manual reading and research COULD be a simple bad assumption. Sometimes it's worth going back to the drawing board and sketching an outline of the situation from the ground up.
In a way that is what I did with asking this question, so thank you for the space to do so.
try "mysql --port=3307 -h 127.0.0.1 -u -p" from client if no

Doctrine won't connect to MAMP mysql database

EDIT: I have since resolved my issue thanks to this answer https://stackoverflow.com/a/50908912/12296041
I have started learning Symfony for a school project, and I was following a tutorial from Symfony's website, but for some reason, Doctrine doesn't manage to connect to MySQL database I have running on my computer. I'm on a Macbook, using MAMP to run a local MySQL server.
Whenever I try to execute any doctrine commands that interact with the database such as php bin/console doctrine:database:create it never works.
So far, I have checked that I could indeed connect to the database using PHPMyAdmin. I have also tried to change the DATABASE_URL in the .env file, but this hasn't solved my issue.
I have also tried creating a symbolic link with sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock but that didn't work either.
This is what my .env file looks like:
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# For a PostgreSQL database, use: "postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=11"
# IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=mysql://root:root#127.0.0.1:8888/db
###< doctrine/doctrine-bundle ###
And I get this error when trying to create a database with doctrine:
In AbstractMySQLDriver.php line 93:
An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] No such file or directory
Anything that can point me in the right direction is greatly appreciated, thanks!
I agree with Cid, port is 8889 by default for MySQL in MAMP.
You can also try to replace 127.0.0.1 by localhost.
Let me know if this works.

Setting HostName to 127.0.0.0

I am using Megento 2.1.8 and Php version php 7.0.20 on Mac with MAMP I am getting error when re-indexing:
SQLSTATE[HY000] [2002] No such file or directory. people resolved issue by setting the database hostname as 127.0.0.1 instead of localhost .
Question is: how can I set the database hostname as 127.0.0.1 instead of localhost?
Go to phpmyadmin->opendatabase->open coreconfigdata -> change securebaseurl and insecure base url->use instead of localhost to 127.0.0.1
Try updating the file /app/etc/env.php under your magento installation directory, you can change the database host there

Php - phinx migration

I am using phinx for migrations in my web app.
my phinx.yml:
paths:
migrations: %%PHINX_CONFIG_DIR%%/migrations
environments:
default_migration_table: app_migrations
default_database: app_database
development:
adapter: mysql
host: localhost:8888
name: app_database
user: ''
pass: ''
port:8889
I have mamp with ports apache:8888 and mysql:8889 running.
The database app_database does exist.
The table app_migrations does not exist(it will be created while migrating right?)
I already created some migrations and now i try to run them:
php vendor/bin/phinx migrate -e development
output in console:
Phinx by Rob Morgan - https://phinx.org. version 0.5.1
using config file ./phinx.yml
using config parser yaml
using migration path /path/to/directory/migrations
using environment development
using adapter mysql
using database app_database
Then it stops and nothing happens...
Anybody could help me with this issue?
Thanskj and Greetings!
Maybe there is some config-hickup. I know this phenomenon from conneting to a mysql-database that is not reachable via a specific host / port. This always leads to timeouts but only after eg. 60 seconds.
You wrote this in your config:
host: localhost:8888
[...]
port: 8889
First remove the port from the hostname:
host: localhost
port: 8889
and as second verify the mysql-server is really listening on localhost / port 8889.
You'll find more on in the "Configuration"-chapter of phinx-documentation: http://docs.phinx.org/en/latest/configuration.html
Regards
If you're using the default settings for MAMP, the username for the database would be root. Try changing the value of user in phinx.yml to root.

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

My code was working all fine yesterday and today it suddenly just don't want to connect to my database. I have changed no settings on it or on the code and I haven't updated any software either. All I do is this:
new PDO('mysql:host=localhost;port=3306;dbname=test', 'username', 'password');
And I get a nice exception message saying this:
Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in ...
The thing is: I'm clearly not trying to connect using a unix socket but using TCP/IP. What am I doing wrong? Is there something I'm missing here?
Thanks for any help.
You are using a Unix socket. When reading "localhost" MySQL client libraries don't interpret it as TCP host "localhost" and resolve that name but use the default Socket location. For using TCP on the local machine you have to use 127.0.0.1 as hostname.
To specify the past use unix_socketinstead of host in the DSN. The location of the socket used for localhost can be defined at compile time or in some versions of PHP using pdo_mysql.default_socket in the php.ini.
From the PHP documentation about connection to MySQL using PDO: PDO_MYSQL DNS
The note at the very end says:
Unix only:
When the host name is set to "localhost", then the connection to the
server is made thru a domain socket. If PDO_MYSQL is compiled against
libmysql then the location of the socket file is at libmysql's
compiled in location. If PDO_MYSQL is compiled against mysqlnd a
default socket can be set thru the pdo_mysql.default_socket setting.
So in order to fix this you would have to properly configure in php.ini the location of your mysql.sock
Find your mysql.sock file. Common locations:
/tmp/mysql.sock
/tmp/mysql/mysql.sock
/var/mysql/mysql.sock
or if you use MAMP or LAMP look for inside the tmp folder for mysql
Edit your php.ini file and properly set the value for pdo_mysql.default_socket
Restart your Apache server to pickup the changes in the php.ini file
On Ubuntu, you can use this setting in php.ini
pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock
There's an update to the docs for Drush which is documented here.
I just added this line:
'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
and all was well.

Categories