Doctrine cannot connect to database in Symfony2 using Mamp - php

I'm trying to create database through doctrine.
php app/console doctrine:database:create
When I run the command above, I receive the following errors:
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] Connection refused
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
What I have tried
This symbolic link creation did not work for me.
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock
I've tried with both
database_host: localhost and database_host: 127.0.0.1 nothing changed.
I know that my MySQL port is 8889 as I can see on MAMP.
I could not check the option Allow network access to MySQL under MySQL tab on MAMP since I do not have MAMP Pro
Here are my configuration files
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#FatihTestBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
cache: false
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
parameters.yml:
# This file is auto-generated during the composer install
parameters:
database_host: localhost
database_port: 8889
database_name: todo
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: fgnfgmngfm

php app/console cache:clear
The problem was because of cache, I received error messages not matter what I did. The command above that clears the cache and
changing the database port to 3306 in both MAMP and paramteters.yml has solved the problem.

Check your DNS settings. If you are not using a VPN, turn it off.
You can test the connection with "Sequel PRO"
Hostname : localhost - 127.0.0.1 - IP Adress
Password : 1234 - root
If they do not solve the problem check the user permissions.
mysql database -> user table

Related

Symfony3 - Assets not working properly in Production

My SF3 application is working just fine in dev built-in PHP server. However some assets give me an error when getting to a production Apache server : the images are showing a 404 error, and a Bundle triggers a 505 code. Here's 2 screens of the Chrome console where you can see the errors :
Dev:
Prod:
I've been trying many things (checking the Apache conf files, emptying the cache, the install:assets command even thoug I'm just using the classic Twig syntax and no Assetic, etc) and browsed tons of topics over the internet in vain.
Here's my config.yml file just in case :
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#ABundle/Resources/config/services.yml" }
- { resource: "#AnotherBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
# save_path: /var/lib/php/sessions
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
paths:
"%kernel.root_dir%/../app/Resources/views/modules": modules
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I'm really stuck on this one, so thank you in advance guys.
have you tried: php bin/console assetic:dump --env=prod --no-debug ?
also, your assets should be in src/YourBundle/Resources/public directory. Then when you install them with php bin/console assets:install --symlink they should be copied or symlinked to web/bundles/your directory
So the problem was that my assets were in the web folder instead of the Resources. Then the assetic:dump command worked perfectly.
Thanks a lot

fsockopen() error 500 when I try to access my Symfony app after deployment to Ubuntu VPS

EDIT2: APC is installed and enabled. what would be the solution?
I'm trying to deploy a symfony app to a VPS.
I deployed the code from git ok, I installed vendors and check /web/config.php to fix all the major and recommended issues on Symfony requirements. It's all green.
However, when I try to access the [VPS_IP]/my_project/web/app.php I get a page isn't working. [my_ip] is currently unable to handle the request.
I also tried to configure virtual host and try to access my Symfony app on the [my_ip] only as URL address and I get the same result.
I've enabled apache 2 mod rewrite, I've added and enabled all the necessary php extensions, I've set date.timezone in php.ini, I've also looked in the dev.log files and tehre I have this error which may be the cause:
[2016-11-22 14:45:49] php.DEBUG: fsockopen(): unable to connect to 127.0.0.1:800 0 (Connection refused) {"type":2,"file":"/var/www/html/giftbundle/vendor/symfony /symfony/src/Symfony/Bundle/FrameworkBundle/Command/ServerCommand.php","line":59 ,"level":28928} []
Could anyone provide some help?
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#MyVendorBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'bootstrap_3_layout.html.twig'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# app/config/config.yml
#knp_menu:
# use "twig: false" to disable the Twig extension and the TwigRenderer
# twig:
# template: knp_menu.html.twig
# if true, enables the helper for PHP templates
# templating: false
# the renderer to use, list is also available by default
# default_renderer: twig
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
gregwar_captcha: ~
liip_imagine:
filter_sets:
cover_filter:
filters:
thumbnail:
size: [600, 400]
mode: inset
prod_thumbnail:
filters:
thumbnail:
size: [50, 50]
mode: inset
#web_profiler:
# toolbar: true
# position: bottom
# intercept_redirects: false
# excluded_ajax_paths: ^/bundles|^/_wdt
parameters.yml
# This file is auto-generated during the composer install
parameters:
database_host: [another remote DB IP]
database_port: 3306
database_name: [remote DB name]
database_user: [Remote DB user]
database_password: [remote DB PSW]
mailer_transport: sendmail
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: rodacsoft
facebook_app_id: [fb_app_ID]
facebook_app_secret: [fb_secret]
VPS /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/giftbundle/web
<Directory /var/www/html/giftbundle/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/symfony_error.log
CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>
EDIT: in the Symfony_error.log I have this. No clue how to fix it or if it's related.
[Tue Nov 22 14:46:06.216187 2016] [:error] [pid 21788] [client 159.153.60.77:18035] PHP Fatal error: Uncaught Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException: The service "validator.builder" has a dependency on a non-existent service "validator.mapping.cache.apc". in /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:58\nStack trace:\n#0 /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php(51): Symfony\\Component\\DependencyInjection\\Compiler\\CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(Array)\n#1 /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php(51): Symfony\\Component\\DependencyInjection\\Compiler\\CheckExceptionOnInvalidReferenceBehaviorPass->processReferences(Array)\n#2 /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnIn in /var/www/html/giftbundle/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php on line 58
Check if cache folder is writable by apache (www-data) user. You cannot access [VPS_IP]/my_project/web/app.php because you already defined web/ folder as root folder in apache config. You should define ServerName and ServerAlias in apache config with your domain name or try direct access to [VPS_IP]/app.php.
Also enter your IP to app_dev and access [VPS_IP]/app_dev.php for more clear errors.

Symfony3 Generate Entites from DB

New to Symfony... Trying to create Entities from an existing DB. I am attempting to following the instructions at http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
Long story short it seems that I simply need 3 commands:
$ php bin/console doctrine:mapping:import --force AppBundle xml
$ php bin/console doctrine:mapping:convert annotation ./src
$ php bin/console doctrine:generate:entities AppBundle
Note: I Modified the name of the bundle from AcmeBlogBundle to AppBundle because I am just using the default bundle. I also am using Symfony 3, everything I look up online seems to reference symfony2
Anyway, first command seems to run fine. I get orm.xml files generated in my ./src/AppBundle/Resources/config/doctrine/ path
Commands 2 and 3 seem to be where my troubles begin.
Command 2 results in
No Metadata Classes to process
Command 3 results in (obviously command 2 didnt work correctly but tried anyway)
[RuntimeException] Bundle "AppBundle" does not contain any mapped entities.
I'm at a loss here.
Contents of config.yml are:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
Put parameters here that don't need to change on each machine where the app is deployed
http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I did end up getting past this by adding i think the "--from database" flag in one of the commands above. I think the second command. I'm pretty sure youre correct that my config is not expecting the xml files so thats why it cant find them.
you can run the following command straightaway after configuring your parameters.yml.
php bin/console doctrine:mapping:import --force AppBundle annotation
then you can run this command to generate entities
php bin/console doctrine:generate:entities AppBundle
It's also important to try your database connection before running any of those commands. Try to fetch values with
php bin/console doctrine:query:sql "SELECT * FROM your_table_name"

Symfony\Component\Config\Exception\FileLoaderLoadException] error

Hi I stumble upon this error everytime I want to run my Symfony application from console. Therefore I am unable to use this symphony app at all. Please help me with your knowledge.
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Unable to parse at line 9 (near "mailer_transport="gmail"") in
/opt/lampp/htdocs/symblog.dev/app/config/parameters.yml (which is
being imported from
"/opt/lampp/htdocs/symblog.dev/app/config/config.yml").
[Symfony\Component\Yaml\Exception\ParseException]
Unable to parse at line 9 (near "mailer_transport="gmail"").
Here is my /app/config/parameters.yml file (I have my true password in original file obviously)
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: symblog_db
database_user: root
database_password: null
mailer_transport="gmail"
mailer_encryption="ssl"
mailer_auth_mode="login"
mailer_host="smtp.gmail.com"
mailer_user="mactestsymblog#gmail.com"
mailer_password="xxxxxxxxx"
secret: JaTylkoTrenuje
And my app/config/config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: #BloggerBlogBundle/Resources/config/config.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
As noted by redbirdo, you have = instead of : in your parameters.yml, which should be like this:
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: symblog_db
database_user: root
database_password: null
mailer_transport: "gmail"
mailer_encryption: "ssl"
mailer_auth_mode: "login"
mailer_host: "smtp.gmail.com"
mailer_user: "mactestsymblog#gmail.com"
mailer_password: "xxxxxxxxx"
secret: JaTylkoTrenuje

SQLSTATE[HY000] [2002] Connection refused - MAMP & Symfony 2

I've a problem with symfony.
When I try to run this command :
php app/console doctrine:schema:update --force
And I've error:
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
Here is my config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
unix_socket: /tmp/mysql.sock
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
And my parameters.yml
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: '8889'
database_name: sil19
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: e7f97888e382ddd2e235dc7da6fc39346b37096c
database_path: null
I don't know where the problem is from. So if someone have any idea. Thanks in advance
I'had to check "Allow network access to Mysql" to make it work on MAMP.
I'have got the same error when trying to connect SYMFONY 4 to MAMP Mysql:
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
For my case, it was a wrong Mysql port, just changed 3306 to 8889 to fix it
DATABASE_URL=mysql://root:root#127.0.0.1:8889/db_name
in my .env file
Run at the full path, like this:
/Applications/MAMP/bin/php/php5.4.4/bin/php bin/console
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the
https://blog.liplex.de/symfony-console-connection-refused-with-mamp/

Categories