Deploying Laravel to Elastic Beanstalk - DB Connection Refused - laravel

I've been developing Laravel app and deploying regularly to an Elastic Beanstalk instance without issue, but suddenly, and without warning, deployments have begun to fail.
Obviously I immediately wondered what I might have changed in the code to cause this, but I haven't made any changes to the core configuration. I rolled back to an earlier commit just to make sure it wasn't my code, and I got the same error.
It's failing after I run eb deploy and running the .ebextensions configs.
Here's the error message from the logs:
[2018-01-08T10:50:34.672Z] INFO [9457] : Running 4 of 5 actions: EbExtensionPostBuild...
[2018-01-08T10:50:35.523Z] ERROR [9457] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError) caused by:
In Connection.php line 664:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = custom and table_name
= migrations)
In Connector.php line 67:
SQLSTATE[HY000] [2002] Connection refused
(ElasticBeanstalk::ExternalInvocationError)
The DB connection credentials are absolutely correct (and haven't changed either).
The command that it's attempting when it fails is simply:
php artisan migrate --force
I've tried connecting over SSH to the server, and I can manually run the same command without issue.
I just can't understand why the deployment is suddenly having its connection refused. Could it be something to do with the AWS security configuration? Could it expire or something? :-/

It turns out the issue was caused by local settings becoming cached and then deployed to the server in: bootstrap/cache/config.php.
Clearing the cache with php artisan config:clear deleted the file and solved the problem.

Related

Receiving Invalid database URL while trying to start chainlink node

I am trying to start a chainlink node in rinkeby testnet.I have setup a postgres DB in AWS. The Database URL is already given. Below is the error while i am trying to start the node.
[ERROR] invalid database url %spostgresql://postgres:Bounty2000%#database-1.ciiecd8szsuh.us-west-1.rd
s.amazonaws.com:5432/db_sar_rinkeby orm/config.go:283
[ERROR] failed to initialize database, got error failed to connect to `host=/tmp user=root database=`
: dial error (dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory) orm/orm.go:82
[ERROR] failed to initialize database, got error failed to connect to `host=/tmp user=root database=`
: dial error (dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory) orm/orm.go:82
I tried changing few settings from AWS front but nothing helped.. If anyone have any clue pls help me up.
Based on the documentation it looks like there may be an "s" in front of your postgres URL, try removing that in your .env file. Also try replacing the database name with the IP address+Port. What should replace $DATABASE is "postgres". Finally try adding in ?sslmode=disable if you don't have ssl activated at the database (not recommended for a production node).
Example in .env:
DATABASE_URL=postgresql://me1234:password1234#10.10.100.100:3000/postgres?sslmode=disable

PDOException Error - Can't connect to database

I'm using PHP 7.1, MySQL 5.7, and Laravel 5.7.12. And on a Mac.
I'm new to Laravel. I'm building my application on a remote server (a Cloudways Server). I know most people build their project locally and then deploy their application onto a remote server, but I'm just building my application on a live remote server and I'm using SFTP.
I've configured my .env file to reflect my server's connection details.
When I try to run php artisan migrate I get this error:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = ********* and table_name = migrations)
at /Users/newadmin/Documents/Sites/Quipper/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
/Users/newadmin/Documents/Sites/Quipper/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=localhost;dbname=*********", "*********", "**********", [])
/Users/newadmin/Documents/Sites/Quipper/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Above I've placed ********** where my database name, username and password go, I guess just for security reasons.
I think it's worth noting on that second exception trace it says "mysql:host=localhost;", when in my .env file I have put in my DB_HOST address, which is a remote server address. So it shouldn't be saying localhost. That seems like it could be part of the problem?
Any help would be greatly appreciated!
I've already tried running in my terminal:
php artisan cache:clear
php artisan config:cache
And that didn't work.
From the log file, look at the path to the PHP script
/Users/newadmin/Documents/Sites/Quipper
This is in your local Mac or MacBook computer, which means that you need to SSH into your Cloudways server and then run the php artisan migrate command
By SSH I mean running something like
ssh cloudways_user#server_IP_ADDRESS
cd Quipper && php artisan migrate

Cant connect to google cloud SQL from Compute Engine Instance

I have a Laravel application running on Google Compute Engine instance. I have configured it to connect to a Cloud SQL database Instance, when I SSH to the VM and run php artisan migrate everything runs smoothly. But when I open the application in a browser I get this Error SQLSTATE[HY000] [2002] Permission denied I cant figure out what is going wrong here, I have tried cloud sql proxy but still the application cant establish a DB connection when accessed from a browser. Can anyone figure out the cause of this weird behavior.
I solved this by enabling httpd_can_network_connect_db flag in selinux by running this command.
sudo setsebool -P httpd_can_network_connect_db=1
I also faced another issue with SELinux with redis and solved it by running this command.
sudo semanage port -m -t http_port_t -p tcp 6379

connecting to database SQLSTATE[HY000] [1045] on new server

I have recently changed server and uploaded my database to the server, for the live website i made no changes to my env and everything works the same. But in my php storm development i have had to change the ip(db host) and despite the username and password being the same i am getting an error.
SQLSTATE[HY000] [1045] Access denied for user 'connect'#'xxxxxx' (using password: YES)
I have cleared config and cache and tried launching php artisan again but get the same issue. i have even brought in the env from the server(live website) and changed the DB Host to match the IP of the server but then the error occurs. Does anyone know how i fix this error, could it be an issue with the fact the database was imported from another server?

Unable to connect to Heroku Postgres from Play 2.3

I have a Play 2.3 app in Java. For this app, I am able to connect to local Postgres server.
But I am unable to connect to Heroku Postgres server.
I have following settings in my application.conf:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://ec2test.amazonaws.com:5432/rwerwerwer"
db.default.user=eerwerwerer
db.default.password="5345fdwfdsvfvsdfsdfds"
I am getting following error:
Caused by: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for ho
st "172.56.17.147", user "eerwerwerer", database "rwerwerwer", SSL off
From PgAdim III, I am able to successful connect to Heroku database.
While adding heroku config, I got:
**! No app specified.**
Follow these steps.
Things to remember:
Use Heroku commands from inside your main directory.
Use database connection as:
db.default.driver=org.postgresql.Driver
db.default.url=${?DATABASE_URL}
No need for username and password.
No need for Procfile.

Resources