Lucifer489's avatar

Problem connecting laravel with mysql database in xampp on AWS EC2 Ubuntu 20.4

Hi, I am new to laravel and still learning. I am working on ubuntu on aws. I tried to connect my application to the mysql database which I installed with xampp. I am using laravel 8.76.2

I got this error when DB_HOST=localhost in my .env file: Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from Contact)

and when I put DB_HOST=127.0.0.1 I got this error: Illuminate\Database\QueryException SQLSTATE[HY000] [2002] Connection refused (SQL: select * from Contact)

I am running laravel appplication on nginx server on my aws public IP! can anyone help me in this regards?

0 likes
11 replies
Sinnbeck's avatar

So the website is in the cloud and the mysql server is on your local computer?

1 like
Lucifer489's avatar

@Sinnbeck no sir, both are on cloud. I installed xampp on aws and made it accessible through the public ip of my instance.

Sinnbeck's avatar

you might want to ask support to have your nickname whitelisted. It isn't possible to tag you as your name is considered spam

Sinnbeck's avatar

I don't know. But if I try and tag you I get a spam message. Try tagging yourself

Tray2's avatar

It's extremly dangerous running anything but dev on xampp, I would say that it is for dev as well, but that is just your local computer that hopefully is protected by a properly set up firewall.

I recommend that you use a deploy tool like Ploi.

If you still want to do it manually you can use this guide

https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/

And to secure MySql se step two of this guide

https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04

1 like
Lucifer489's avatar

@Tray2 thanks, I uninstalled xampp and installed mysql server using sudo apt-get install mysql-server Solved my problem.❤️

Sinnbeck's avatar

You figured that out yourself or by following the links from @tray2 ?

Lucifer489's avatar

@Sinnbeck no, actually your comment helped me. Thanks❣️ I solved my problem before @tray2 comment, using your suggestion. Thanks to @tray2 as well❣️

Please or to participate in this conversation.