Laravel Mysql PDO Exception at migrate

php
laravel
mysql

#1

Hi,

I am new to c9. I installed Laravel on a c9 workspace using https://docs.c9.io/docs/laravel (multiple times). None of the steps errored.

Whenever I run:

php artisan migrate

I get these errors:

[PDOException]                                                                                  
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
                                                                                              
                                                                                           
[ErrorException]                                                                             
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known  

Can someone please explain to me what is this issue in c9 context, and what can be possible solutions?

UPDATE1: I’m adding my environment, just in case that might be of help https://ide.c9.io/shootingla/slate

UPDATE2:


#2

Hey @ArturGrigio,

Pardon this isn’t a direct answer to your question but you may see these posts for guidance/inspiration:

:book: :snail:

and if not you may ask one of them for the link to their workspace if it’s open to poke around see what they may be doing differently.

Hey @Silvanite & @clone45, how’d you get your Laravel workspaces running, do you see anything that could help out @ArturGrigio? :slight_smile: :innocent:


#3

@mikeumus Thank you for the suggestions, but neither one provided a solution to the issue :frowning:

Just to clarify myself, I don’t have a problem running Laravel without db connections, my issue is strictly db related (unfortunately, that’s the one field I know the least about).


#4

the documentation at https://docs.c9.io/docs/laravel suggests using the c9 db, for some reason it does not work. So I created my own db, this is how I did it:

  • Enter MySQL: mysql --user=root mysql

  • Add a new MySQL Database: CREATE DATABASE newdb;

  • Add the ubuntu user as a user for MySQL: CREATE USER 'ubuntu'@'localhost' IDENTIFIED BY 'some_pass';

  • Grant the ubuntu user privilages: GRANT ALL PRIVILEGES ON *.* TO 'ubuntu'@'localhost'

  • Finish granting privilages: WITH GRANT OPTION;
    http://dev.mysql.com/doc/refman/5.7/en/adding-users.html

  • MySQL documentation suggests doing this ass well: CREATE USER 'ubuntu'@'%' IDENTIFIED BY 'some_pass';

  • Grant the ubuntu user privilages: GRANT ALL PRIVILEGES ON *.* TO 'ubuntu'@'%'

  • Finish granting privilages: WITH GRANT OPTION;

  • Exit MySQL: exit

  • Restart MySQL: sudo services mysql restart

  • vim into your .env file and make these changes:
    DB_HOST=localhost DB_DATABASE=newdb DB_USERNAME=ubuntu DB_PASSWORD=some_pass

  • Now Run: php artisan migrate

Hope this helps whoever encounters database connection problem when installing Laravel


#5

Thanks Artur. This worked for me!

For whatever reason, some of these privileges statements didn’t work though whatever reason. Fortunately, Cloud9 has Phpmyadmin running on their instances so I manually adjusted the user permissions via Phpmyadmin. All is well. Thanks again.


#6

Thanks @ArturGrigio, I hustled with the error for weeks. This helped.


#7

same problem… cant find a solution


#8

THANK YOU!! This worked fine :slight_smile: