SQLSTATE[HY000] [2002] Connection refused only in browser - laravel

I am on OS X Yosemite, running the latest homestead with Laravel 5.3.
I am able to run and reset migration in terminal from OS X. I can see the tables when I connect to the database with Sequel Pro using standard connection. I even see the tables when I SSH into the virtual box and run mysql -uhomestead -psecret.
The problem is, when I try to register a new user from the browser, I get the PDOException in Connector.php line 119: SQLSTATE[HY000] [2002] Connection refused error. It works when I run php artisan serve and fill in the form at http://localhost:8000/register.
I tried changing DB_HOST to 192.168.10.10 but that causes migrations to fail.
I might have created some chaos while trying to install mysql. I installed it using homebrew. Then i ran mysql.server start and at another point I ran brew services start mysql because I was not sure if it was working.
Homestead.yml file:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/code/laravel
to: /home/vagrant/laravel
type: "nfs"
sites:
- map: votingapp.dev
to: /home/vagrant/laravel/votingapp/public
databases:
- homestead
.env file:
APP_ENV=local
APP_KEY=base64:xxxxxxxx
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=votingapp_development
DB_USERNAME=homestead
DB_PASSWORD=secret
web.php file:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index');

It turns out I had the wrong port number. In the .env file it should be 3306 while in Sequel Pro it should be 33060.
According to the Connecting to databases of the Laravel manual:
You should only use these non-standard ports when connecting to the
databases from your host machine. You will use the default 3306 and
5432 ports in your Laravel database configuration file since Laravel
is running within the virtual machine.

If you use Mamp in 127.0.0.1 add :8889 or the port your config mamp.enter image description here
127.0.0.1:8889 or localhost:8889

Related

Ping to Laravel Homestead is Fine but Web Connection Refused

I just set up a homestead on my Windows 10 machine. Everything looks fine but page is not loading. I am getting connection refused on my browser.
I have asked this on Laracasts with details
https://laracasts.com/discuss/channels/servers/ping-to-homestead-is-fine-but-connection-refused#reply=495171
I think it is a minor issue but don't know where and what to look for.
My Homestead.yaml file:
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: d:/DATA/SourceCodes/laravel
to: /home/vagrant/code
sites:
- map: myapp.test
to: /home/vagrant/code/myapp/public
databases:
- homestead
at many times I found that modern browsers refuses to connect to urls that is ending with some unknown extensions for security reasons, so maybe its the url.
add "myapp.test" to Homestead.yaml file > sites: -map: myapp.test.
make sure you did edit hosts added line192.168.10.10 myapp.test
another possibilities:
if you are using antivirus or any internet security program on your
host system: disable it for a while and test.
if you use proxy for your internet connection, add myapp.test as an exception or disable the proxy for a while
Seems to be a problem with nginx. Try to login to homestead with ssh and check if nginx is running. I had the same problem after upgrading Homestead when my nginx config file was throwing an error (check your config with nginx -t)

Laravel Homestead could not connect to server 127.0.0.1

I have installed laravel homestead and vagrant. After vagrant up my local site started work.
My migrations worked well and i could connect to DB with PhpStorm ( http://joxi.ru/a2X45M1S1x3Vw2 )
my .env file contains the same code as written in doc
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=54320
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
But when I try to register new user I got an error
SQLSTATE[08006] [7] could not connect to server: Connection refused Is
the server running on host "127.0.0.1" and accepting TCP/IP
connections on port 54320?
( http://joxi.ru/nAynW7asYOD39r )
How it possible when migrations run well but connection refused?
Your screenshot says that Laravel is having trouble connecting to 192.168.10.10, which isn't the same as 127.0.0.1. Check that the correct DB_HOST is set in your .env file.
In case the config from the .env file isn't being used, also check the config/database.php file and verify the settings there too.
You have to change .env -> DB_PORT
for pgsql use DB_PORT=5432
I was having this same issue, and what worked for me was to change my DB_HOST=127.0.0.1 to ip: "192.168.56.56"(the same id that is on my Homestead.yaml file).

Laravel Homestead not working database connect

I have installed laravel homestead and run it.
But I can't run migration locally and in vagrant.
If I try to run the migration inside vagrant
cd ~/code/project/
php artisan migrate
I got an error
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 54320?"
If I try to run the migration locally I got a another error
PDOException::("could not find driver")
my .env file contains the same code as written in doc
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=54320
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Maybe something I do not understand but do I need posgresql locally and inside my vagrant? Where I have to work with database locally or with vagrant?

Laravel not connecting to homestead database

I was developing a laravel application locally on Mac connecting to a mysql database. i recently found out about homestead and pulled my app over to Vagrant Homestead. however now im not able to connect to the mysql server on the homestead/box.
Error i recieve:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
I did update my app's .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=eHDatabase
DB_USERNAME=homestead
DB_PASSWORD=secret
I cleared my app's cache
php artisan cache:clear
I updated my /etc/hosts file
27.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 laravel.app
and i also removed the old mysql server running on port 3306 on 127.0.0.1.
but still recieve the connection error.
Any help would be great.
Both .env and /config/database.php are looking fine, so try to run this:
php artisan config:cache

Laravel Homestead (Windows)

Today I have been trying to install the Laravel library together with Laravel Homestead.. But I can't seem to get it working.
The first thing, Laravel documentation tells you to do: composer global require "laravel/homestead=~2.0", but it didn't work.
So I searched the internet some and found: composer global require "laravel/homestead=~3.0", which actually worked.
But now when I try to run the homestead command in my command line, it gives me this: http://prntscr.com/9perhj, that's the only thing it's giving me.
I have added the directory to my path variable.
I hope someone can help me.
Thanks in advance!
Homestead itself command will return this expected screen. You would need to pass the command you want to run.
At first, run homestead init so that it will create the Homestead.yaml configuration file
This is an old question but I thought I'd put up my answer since it took me multiple tries to get it right and I documented the process while I was doing it so I wouldn't have such a hard time in the future.
Note: You should NOT have NginX, PHP, MySQL, etc. installed on your machine. The Vagrant Homestead virtual box provides all of this functionality. I had some issues where I had NginX and MySQL on my machine and it was connecting to my local machine's MySQL when it should be connecting to the virtual box's MySQL.
Without further ado, this is how I set it up for my Windows 7 machine:
Prerequisites:
VirtualBox:
https://www.virtualbox.org/wiki/Downloads
Vagrant:
https://www.vagrantup.com/downloads.html
Git Bash: A terminal that feels like a Linux terminal. You can do everything you do on an Ubuntu server in Windows.
https://git-scm.com/downloads
Putty: Telnet client that I used for connecting to my VirtualBox Homestead server
http://www.putty.org/
create project folder
open terminal in project folder (something like E:\Projects\Vagrant)
type 'vagrant box add laravel/homestead'
type 'git clone https://github.com/laravel/homestead.git Homestead'
This installs Homestead in the designated project folder.
type 'cd Homestead'
type 'bash init.sh' OR 'init.bat'
This creates a folder in:
C:\Users\USERNAME\.homestead
which has the file:
Homestead.yaml
If you open the Homestead.yaml file it should look something like this:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
databases:
- homestead
The '~/' folder is the equivalent of:
C:\Users\USERNAME\
Change:
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
To:
folders:
- map: E:/Projects/Vagrant/Homestead
to: /home/vagrant/Homestead
sites:
- map: WEBSITE.dev
to: /home/vagrant/Homestead/Laravel/public
goto C:\Windows\System32\drivers\etc
open the file 'hosts' in a text editor
add '192.168.10.10 WEBSITE.dev' (the IP address should match the IP address in the Homestead.yaml file)
open a terminal in E:/Projects/Vagrant/Homestead folder
type 'ssh-keygen -t rsa -C "USERNAME#gmail.com"'
This creates the folder C:\Users\USERNAME.ssh and sets up your SSH Key
type 'vagrant init laravel/homestead'
type 'vagrant up'
You should see Homestead running in VirtualBox
You can use 'vagrant destroy' to kill it when done
Use putty.exe to log in to Homestead
IP Address: 127.0.0.1
Port: 2222
login as: vagrant
password: vagrant
Everything is now ready

Resources